From f499454957a8adf2f36646e5f37d3bbda0421c36 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Thu, 23 Mar 2023 01:42:01 +0100 Subject: [PATCH] Fixed identation problems Added comments all over the codebase to explain things a bit better Improved CApplicationContext to be a bit more self-explanatory Abstracted CRenderContext access away into a helper that every render class should use Signed-off-by: Alexis Maiquez --- CMakeLists.txt | 10 +- main.cpp | 2 +- .../Application/CApplicationContext.cpp | 265 +++---- .../Application/CApplicationContext.h | 150 +++- .../Application/CWallpaperApplication.cpp | 664 +++++++++--------- .../Application/CWallpaperApplication.h | 93 ++- .../Assets/CAssetLoadException.cpp | 1 - .../Assets/CAssetLoadException.h | 4 +- .../Assets/CCombinedContainer.cpp | 8 +- .../Assets/CCombinedContainer.h | 25 +- src/WallpaperEngine/Assets/CContainer.cpp | 60 +- src/WallpaperEngine/Assets/CContainer.h | 48 +- src/WallpaperEngine/Assets/CDirectory.cpp | 6 +- src/WallpaperEngine/Assets/CDirectory.h | 12 +- src/WallpaperEngine/Assets/CFileEntry.h | 9 +- src/WallpaperEngine/Assets/CPackage.cpp | 2 +- src/WallpaperEngine/Assets/CPackage.h | 8 +- .../Assets/CPackageLoadException.cpp | 6 +- .../Assets/CPackageLoadException.h | 4 +- src/WallpaperEngine/Assets/CTexture.cpp | 136 ++-- src/WallpaperEngine/Assets/CTexture.h | 106 ++- .../Assets/CVirtualContainer.cpp | 2 +- .../Assets/CVirtualContainer.h | 8 +- src/WallpaperEngine/Assets/ITexture.h | 66 +- src/WallpaperEngine/Audio/CAudioContext.h | 24 +- src/WallpaperEngine/Audio/CAudioStream.cpp | 12 +- src/WallpaperEngine/Audio/CAudioStream.h | 136 +++- .../Audio/Drivers/CAudioDriver.h | 26 +- .../Audio/Drivers/CSDLAudioDriver.cpp | 3 +- .../Audio/Drivers/CSDLAudioDriver.h | 31 +- src/WallpaperEngine/Core/CProject.cpp | 4 +- src/WallpaperEngine/Core/CProject.h | 2 +- src/WallpaperEngine/Core/CScene.cpp | 80 +-- src/WallpaperEngine/Core/CScene.h | 40 +- src/WallpaperEngine/Core/CVideo.cpp | 4 +- src/WallpaperEngine/Core/CVideo.h | 8 +- src/WallpaperEngine/Core/CWallpaper.cpp | 2 +- src/WallpaperEngine/Core/Objects/CEffect.cpp | 14 +- src/WallpaperEngine/Core/Objects/CEffect.h | 48 +- src/WallpaperEngine/Core/Objects/CImage.cpp | 2 +- src/WallpaperEngine/Core/Objects/CImage.h | 84 ++- .../Core/Objects/CParticle.cpp | 22 +- src/WallpaperEngine/Core/Objects/CParticle.h | 53 +- src/WallpaperEngine/Core/Objects/CSound.cpp | 16 +- src/WallpaperEngine/Core/Objects/CSound.h | 25 +- .../Core/Objects/Effects/CBind.h | 23 +- .../Core/Objects/Effects/CFBO.h | 27 +- .../Effects/Constants/CShaderConstant.h | 9 +- .../Constants/CShaderConstantFloat.cpp | 1 - .../Effects/Constants/CShaderConstantFloat.h | 10 + .../Constants/CShaderConstantInteger.cpp | 1 - .../Constants/CShaderConstantInteger.h | 10 + .../Constants/CShaderConstantVector2.h | 10 + .../Constants/CShaderConstantVector3.h | 10 + .../Constants/CShaderConstantVector4.h | 12 +- .../Core/Objects/Images/CMaterial.h | 50 +- .../Core/Objects/Images/Materials/CPass.cpp | 2 +- .../Core/Objects/Images/Materials/CPass.h | 81 ++- .../Core/Objects/Particles/CControlPoint.cpp | 2 +- .../Core/Objects/Particles/CControlPoint.h | 29 +- .../Core/Objects/Particles/CEmitter.cpp | 30 +- .../Core/Objects/Particles/CEmitter.h | 56 +- .../Core/Objects/Particles/CInitializer.h | 18 +- .../Particles/Initializers/CAlphaRandom.h | 42 +- .../Initializers/CAngularVelocityRandom.h | 42 +- .../Particles/Initializers/CColorRandom.h | 17 +- .../Initializers/CLifeTimeRandom.cpp | 6 +- .../Particles/Initializers/CLifeTimeRandom.h | 16 +- .../Initializers/CRotationRandom.cpp | 14 +- .../Particles/Initializers/CRotationRandom.h | 60 +- .../Particles/Initializers/CSizeRandom.cpp | 6 +- .../Particles/Initializers/CSizeRandom.h | 17 +- .../Initializers/CTurbulentVelocityRandom.cpp | 14 +- .../Initializers/CTurbulentVelocityRandom.h | 26 +- .../Initializers/CVelocityRandom.cpp | 12 +- .../Particles/Initializers/CVelocityRandom.h | 17 +- src/WallpaperEngine/Core/Projects/CProperty.h | 35 +- .../Core/Projects/CPropertyBoolean.h | 13 +- .../Core/Projects/CPropertyColor.h | 10 +- .../Core/Projects/CPropertyCombo.h | 25 +- .../Core/Projects/CPropertySlider.h | 29 +- .../Core/Projects/CPropertyText.h | 5 +- .../Core/Scenes/CProjection.cpp | 6 +- .../Core/UserSettings/CUserSettingFloat.cpp | 4 +- src/WallpaperEngine/Render/CRenderContext.cpp | 161 +++-- src/WallpaperEngine/Render/CRenderContext.h | 95 +-- src/WallpaperEngine/Render/CScene.cpp | 6 +- src/WallpaperEngine/Render/CTextureCache.cpp | 36 +- src/WallpaperEngine/Render/CTextureCache.h | 14 +- src/WallpaperEngine/Render/CVideo.cpp | 20 +- src/WallpaperEngine/Render/CWallpaper.cpp | 33 +- src/WallpaperEngine/Render/CWallpaper.h | 76 +- .../Render/Drivers/COpenGLDriver.cpp | 16 +- .../Render/Drivers/COpenGLDriver.h | 12 +- .../Render/Drivers/CVideoDriver.h | 35 +- .../Drivers/Output/CGLFWWindowOutput.cpp | 78 ++ .../Render/Drivers/Output/CGLFWWindowOutput.h | 25 + .../Render/Drivers/Output/COutput.cpp | 8 +- .../Render/Drivers/Output/COutput.h | 50 +- .../Render/Drivers/Output/CWindowOutput.cpp | 77 -- .../Render/Drivers/Output/CWindowOutput.h | 25 - .../Render/Drivers/Output/CX11Output.cpp | 228 +++--- .../Render/Drivers/Output/CX11Output.h | 46 +- .../Render/Helpers/CContextAware.cpp | 19 + .../Render/Helpers/CContextAware.h | 31 + .../Render/Objects/CEffect.cpp | 1 + src/WallpaperEngine/Render/Objects/CImage.cpp | 58 +- src/WallpaperEngine/Render/Objects/CSound.cpp | 4 +- .../Render/Objects/Effects/CPass.cpp | 22 +- .../Render/Shaders/Compiler.cpp | 320 ++++----- src/WallpaperEngine/Render/Shaders/Compiler.h | 68 +- 111 files changed, 2897 insertions(+), 1795 deletions(-) create mode 100644 src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.cpp create mode 100644 src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.h delete mode 100644 src/WallpaperEngine/Render/Drivers/Output/CWindowOutput.cpp delete mode 100644 src/WallpaperEngine/Render/Drivers/Output/CWindowOutput.h create mode 100644 src/WallpaperEngine/Render/Helpers/CContextAware.cpp create mode 100644 src/WallpaperEngine/Render/Helpers/CContextAware.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f5f429..af76f30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,12 +105,15 @@ add_executable( src/WallpaperEngine/Render/Shaders/Compiler.h src/WallpaperEngine/Render/Shaders/Compiler.cpp + src/WallpaperEngine/Render/Helpers/CContextAware.cpp + src/WallpaperEngine/Render/Helpers/CContextAware.h + src/WallpaperEngine/Render/Drivers/Output/COutput.cpp src/WallpaperEngine/Render/Drivers/Output/COutput.h src/WallpaperEngine/Render/Drivers/Output/CX11Output.cpp src/WallpaperEngine/Render/Drivers/Output/CX11Output.h - src/WallpaperEngine/Render/Drivers/Output/CWindowOutput.cpp - src/WallpaperEngine/Render/Drivers/Output/CWindowOutput.h + src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.cpp + src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.h src/WallpaperEngine/Render/Drivers/COpenGLDriver.h src/WallpaperEngine/Render/Drivers/COpenGLDriver.cpp src/WallpaperEngine/Render/Drivers/CVideoDriver.h @@ -120,6 +123,9 @@ add_executable( src/WallpaperEngine/Render/CTextureCache.h src/WallpaperEngine/Render/CTextureCache.cpp + src/WallpaperEngine/Render/Helpers/CContextAware.cpp + src/WallpaperEngine/Render/Helpers/CContextAware.h + src/WallpaperEngine/Render/CWallpaper.h src/WallpaperEngine/Render/CWallpaper.cpp src/WallpaperEngine/Render/CScene.h diff --git a/main.cpp b/main.cpp index e612b5a..d00e695 100644 --- a/main.cpp +++ b/main.cpp @@ -29,7 +29,7 @@ int main (int argc, char* argv[]) WallpaperEngine::Application::CWallpaperApplication app (appContext); // halt if the list-properties option was specified - if (appContext.onlyListProperties) + if (appContext.general.onlyListProperties) return 0; appPointer = &app; diff --git a/src/WallpaperEngine/Application/CApplicationContext.cpp b/src/WallpaperEngine/Application/CApplicationContext.cpp index cc65bb1..253dc4b 100644 --- a/src/WallpaperEngine/Application/CApplicationContext.cpp +++ b/src/WallpaperEngine/Application/CApplicationContext.cpp @@ -4,7 +4,6 @@ #include "WallpaperEngine/Logging/CLog.h" #include -#include #include #define WORKSHOP_APP_ID 431960 @@ -12,24 +11,24 @@ using namespace WallpaperEngine::Application; -struct option long_options [] = { - {"screen-root", required_argument, nullptr, 'r'}, - {"bg", required_argument, nullptr, 'b'}, - {"window", required_argument, nullptr, 'w'}, - {"pkg", required_argument, nullptr, 'p'}, - {"dir", required_argument, nullptr, 'd'}, - {"silent", no_argument, nullptr, 's'}, - {"volume", required_argument, nullptr, 'v'}, - {"help", no_argument, nullptr, 'h'}, - {"fps", required_argument, nullptr, 'f'}, - {"assets-dir", required_argument, nullptr, 'a'}, - {"screenshot", required_argument, nullptr, 'c'}, - {"list-properties", no_argument, nullptr, 'l'}, - {"set-property", required_argument, nullptr, 'o'}, - {nullptr, 0, nullptr, 0} +struct option long_options[] = { + { "screen-root", required_argument, nullptr, 'r' }, + { "bg", required_argument, nullptr, 'b' }, + { "window", required_argument, nullptr, 'w' }, + { "pkg", required_argument, nullptr, 'p' }, + { "dir", required_argument, nullptr, 'd' }, + { "silent", no_argument, nullptr, 's' }, + { "volume", required_argument, nullptr, 'v' }, + { "help", no_argument, nullptr, 'h' }, + { "fps", required_argument, nullptr, 'f' }, + { "assets-dir", required_argument, nullptr, 'a' }, + { "screenshot", required_argument, nullptr, 'c' }, + { "list-properties", no_argument, nullptr, 'l' }, + { "set-property", required_argument, nullptr, 'o' }, + { nullptr, 0, nullptr, 0 } }; -std::string stringPathFixes(const std::string& s) +std::string stringPathFixes (const std::string& s) { if (s.empty ()) return s; @@ -37,136 +36,155 @@ std::string stringPathFixes(const std::string& s) std::string str (s); // remove single-quotes from the arguments - if (str [0] == '\'' && str [str.size() - 1] == '\'') + if (str[0] == '\'' && str[str.size () - 1] == '\'') str - .erase (str.size() - 1, 1) + .erase (str.size () - 1, 1) .erase (0, 1); return std::move (str); } -CApplicationContext::CApplicationContext (int argc, char* argv[]) : - takeScreenshot (false), - maximumFPS (30), - audioVolume (128), - audioEnabled (true), - onlyListProperties (false) +CApplicationContext::CApplicationContext (int argc, char* argv[]) { + // setup structs with sane default values for now + this->general = + { + .onlyListProperties = false, + .assets = "", + .defaultBackground = "", + .screenBackgrounds = {}, + .properties = {}, + }; + this->render = + { + .mode = NORMAL_WINDOW, + .maximumFPS = 30, + .window = { .geometry = {}}, + }; + this->audio = + { + .enabled = true, + .volume = 127, + }; + this->screenshot = + { + .take = false, + .path = "", + .format = FIF_UNKNOWN, + }; + int c; - std::string lastScreen; + std::string lastScreen; while ((c = getopt_long (argc, argv, "b:r:p:d:shf:a:w:", long_options, nullptr)) != -1) { switch (c) { - case 'b': - if (lastScreen.empty ()) - sLog.exception ("--bg has to go after a --screen-root argument"); + case 'b': + if (lastScreen.empty ()) + sLog.exception ("--bg has to go after a --screen-root argument"); - // no need to check for previous screen being in the list, as it's the only way for this variable - // to have any value - this->screenSettings.insert_or_assign (lastScreen, this->validatePath (optarg)); - break; + // no need to check for previous screen being in the list, as it's the only way for this variable + // to have any value + this->general.screenBackgrounds[lastScreen] = translateBackground (optarg); + break; - case 'o': - { - std::string value = optarg; - std::string::size_type equals = value.find ('='); + case 'o': + { + std::string value = optarg; + std::string::size_type equals = value.find ('='); - // properties without value are treated as booleans for now - if (equals == std::string::npos) - this->properties.insert_or_assign (value, "1"); - else - this->properties.insert_or_assign ( - value.substr (0, equals), - value.substr (equals + 1) - ); - } - break; + // properties without value are treated as booleans for now + if (equals == std::string::npos) + this->general.properties[value] = "1"; + else + this->general.properties[value.substr (0, equals)] = value.substr (equals + 1); + } + break; - case 'l': - this->onlyListProperties = true; - break; + case 'l': + this->general.onlyListProperties = true; + break; - case 'r': - if (this->screenSettings.find (optarg) != this->screenSettings.end ()) - sLog.exception ("Cannot specify the same screen more than once: ", optarg); - if (this->windowMode == EXPLICIT_WINDOW) - sLog.exception ("Cannot run in both background and window mode"); + case 'r': + if (this->general.screenBackgrounds.find (optarg) != this->general.screenBackgrounds.end ()) + sLog.exception ("Cannot specify the same screen more than once: ", optarg); + if (this->render.mode == EXPLICIT_WINDOW) + sLog.exception ("Cannot run in both background and window mode"); - this->windowMode = X11_BACKGROUND; - lastScreen = optarg; - this->screenSettings.insert_or_assign (lastScreen, ""); - break; + this->render.mode = X11_BACKGROUND; + lastScreen = optarg; + this->general.screenBackgrounds[lastScreen] = ""; + break; - case 'w': - if (this->windowMode == X11_BACKGROUND) - sLog.exception ("Cannot run in both background and window mode"); + case 'w': + if (this->render.mode == X11_BACKGROUND) + sLog.exception ("Cannot run in both background and window mode"); - if (optarg != nullptr) - { - this->windowMode = EXPLICIT_WINDOW; - // read window geometry - char* pos = optarg; + if (optarg != nullptr) + { + this->render.mode = EXPLICIT_WINDOW; + // read window geometry + char* pos = optarg; - if (pos != nullptr) - this->windowGeometry.x = atoi (pos); - if ((pos = strchr (pos, '.')) != nullptr) - this->windowGeometry.y = atoi (pos + 1); - if ((pos = strchr (pos + 1, '.')) != nullptr) - this->windowGeometry.z = atoi (pos + 1); - if ((pos = strchr (pos + 1, '.')) != nullptr) - this->windowGeometry.w = atoi (pos + 1); - } - break; + if (pos != nullptr) + this->render.window.geometry.x = atoi (pos); + if ((pos = strchr (pos, '.')) != nullptr) + this->render.window.geometry.y = atoi (pos + 1); + if ((pos = strchr (pos + 1, '.')) != nullptr) + this->render.window.geometry.z = atoi (pos + 1); + if ((pos = strchr (pos + 1, '.')) != nullptr) + this->render.window.geometry.w = atoi (pos + 1); + } + break; - case 'p': - case 'd': - sLog.error ("--dir/--pkg is deprecated and not used anymore"); - this->background = this->validatePath (stringPathFixes (optarg)); - break; + case 'p': + case 'd': + sLog.error ("--dir/--pkg is deprecated and not used anymore"); + this->general.defaultBackground = translateBackground (stringPathFixes (optarg)); + break; - case 's': - this->audioEnabled = false; - break; + case 's': + this->audio.enabled = false; + break; - case 'h': - this->printHelp (argv [0]); - break; + case 'h': + printHelp (argv[0]); + break; - case 'f': - maximumFPS = atoi (optarg); - break; + case 'f': + this->render.maximumFPS = atoi (optarg); + break; - case 'a': - this->assets = stringPathFixes (optarg); - break; + case 'a': + this->general.assets = stringPathFixes (optarg); + break; - case 'v': - this->audioVolume = std::max (atoi (optarg), 128); - break; + case 'v': + this->audio.volume = std::max (atoi (optarg), 128); + break; - case 'c': - this->takeScreenshot = true; - this->screenshot = stringPathFixes (optarg); - break; + case 'c': + this->screenshot.take = true; + this->screenshot.path = stringPathFixes (optarg); + break; - default: - sLog.out ("Default on path parsing: ", optarg); - break; + default: + sLog.out ("Default on path parsing: ", optarg); + break; } } - if (this->background.empty ()) + if (this->general.defaultBackground.empty ()) { - if (optind < argc && strlen (argv [optind]) > 0) + if (optind < argc && strlen (argv[optind]) > 0) { - this->background = this->validatePath (argv [optind]); + this->general.defaultBackground = translateBackground (argv[optind]); } else { - printHelp (argv [0]); + printHelp (argv[0]); } } @@ -175,50 +193,49 @@ CApplicationContext::CApplicationContext (int argc, char* argv[]) : this->validateScreenshot (); } -std::string CApplicationContext::validatePath (const std::string& path) +std::filesystem::path CApplicationContext::translateBackground (const std::string& bgIdOrPath) { - if (path.find ('/') == std::string::npos) - return Steam::FileSystem::workshopDirectory (WORKSHOP_APP_ID, path); + if (bgIdOrPath.find ('/') == std::string::npos) + return Steam::FileSystem::workshopDirectory (WORKSHOP_APP_ID, bgIdOrPath); - return path; + return bgIdOrPath; } void CApplicationContext::validateAssets () { - if (!this->assets.empty ()) + if (!this->general.assets.empty ()) { - sLog.out ("Using wallpaper engine's assets at ", this->assets, " based on --assets-dir parameter"); + sLog.out ("Using wallpaper engine's assets at ", this->general.assets, " based on --assets-dir parameter"); return; } try { - this->assets = Steam::FileSystem::appDirectory (APP_DIRECTORY, "assets"); + this->general.assets = Steam::FileSystem::appDirectory (APP_DIRECTORY, "assets"); } catch (std::runtime_error&) { // set current path as assets' folder - std::filesystem::path directory = std::filesystem::canonical ("/proc/self/exe") - .parent_path () / "assets"; + std::filesystem::path directory = std::filesystem::canonical ("/proc/self/exe").parent_path () / "assets"; } } void CApplicationContext::validateScreenshot () { - if (!this->takeScreenshot) + if (!this->screenshot.take) return; - if (!this->screenshot.has_extension ()) + if (!this->screenshot.path.has_extension ()) sLog.exception ("Cannot determine screenshot format"); - std::string extension = this->screenshot.extension (); + std::string extension = this->screenshot.path.extension (); if (extension == ".bmp") - this->screenshotFormat = FIF_BMP; + this->screenshot.format = FIF_BMP; else if (extension == ".png") - this->screenshotFormat = FIF_PNG; + this->screenshot.format = FIF_PNG; else if (extension == ".jpg" || extension == ".jpeg") - this->screenshotFormat = FIF_JPEG; + this->screenshot.format = FIF_JPEG; else sLog.exception ("Cannot determine screenshot format, unknown extension ", extension); } @@ -235,7 +252,7 @@ void CApplicationContext::printHelp (const char* route) sLog.out ("\t--silent\t\t\t\t\tMutes all the sound the wallpaper might produce"); sLog.out ("\t--volume \t\t\tSets the volume for all the sounds in the background"); sLog.out ("\t--screen-root \tDisplay as screen's background"); - sLog.out ("\t--window \tRuns in window mode, geometry has to be XxYxWxH and sets the position and size of the window"); + sLog.out ("\t--window \tRuns in window mode, geometry has to be XxYxWxH and sets the position and size of the window"); sLog.out ("\t--fps \t\t\tLimits the FPS to the given number, useful to keep battery consumption low"); sLog.out ("\t--assets-dir \t\t\tFolder where the assets are stored"); sLog.out ("\t--screenshot\t\t\t\tTakes a screenshot of the background"); diff --git a/src/WallpaperEngine/Application/CApplicationContext.h b/src/WallpaperEngine/Application/CApplicationContext.h index 9dc6a0b..4b0c89e 100644 --- a/src/WallpaperEngine/Application/CApplicationContext.h +++ b/src/WallpaperEngine/Application/CApplicationContext.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -8,38 +7,141 @@ #include +#include + namespace WallpaperEngine::Application { - class CApplicationContext - { - public: - CApplicationContext (int argc, char* argv[]); + /** + * Application information as parsed off the command line arguments + */ + class CApplicationContext + { + public: + CApplicationContext (int argc, char* argv[]); enum WINDOW_MODE { + /** + * Default window mode + */ NORMAL_WINDOW = 0, + /** + * Draw to X11 background + */ X11_BACKGROUND = 1, + /** + * Explicit window mode with specified geometry + */ EXPLICIT_WINDOW = 2, }; - glm::ivec4 windowGeometry; - std::map screenSettings; - std::map properties; - std::string background; - std::filesystem::path assets; - std::filesystem::path screenshot; - bool takeScreenshot; - int maximumFPS; - int audioVolume; - bool audioEnabled; - bool onlyListProperties; - FREE_IMAGE_FORMAT screenshotFormat; - WINDOW_MODE windowMode; + /** + * General settings + */ + struct + { + /** + * If the user requested a list of properties for the given background + */ + bool onlyListProperties; - private: - std::string validatePath (const std::string& path); - void validateAssets (); - void validateScreenshot (); - static void printHelp (const char* route); - }; + /** + * The path to the assets folder + */ + std::filesystem::path assets; + /** + * Background to load (provided as the final argument) as fallback for multi-screen setups + */ + std::filesystem::path defaultBackground; + + /** + * The backgrounds specified for different screens + */ + std::map screenBackgrounds; + /** + * Properties to change values for + */ + std::map properties; + } general; + + /** + * Render settings + */ + struct + { + /** + * The mode to run the background in + */ + WINDOW_MODE mode; + /** + * Maximum FPS + */ + int maximumFPS; + + struct + { + /** + * The window size used in explicit window + */ + glm::ivec4 geometry; + } window; + } render; + + /** + * Audio settings + */ + struct + { + /** + * If the audio system is enabled + */ + bool enabled; + /** + * Sound volume (0-128) + */ + int volume; + } audio; + + /** + * Screenshot settings + */ + struct + { + /** + * If an screenshot should be taken + */ + bool take; + /** + * The path to where the screenshot must be saved + */ + std::filesystem::path path; + /** + * The image format + */ + FREE_IMAGE_FORMAT format; + } screenshot; + private: + /** + * Validates the assets folder and ensures a valid one is present + */ + void validateAssets (); + + /** + * Validates the screenshot settings + */ + void validateScreenshot (); + + /** + * Validates a background parameter and returns the real bgIdOrPath to it + * + * @param bgIdOrPath + * @return + */ + static std::filesystem::path translateBackground (const std::string& bgIdOrPath); + + /** + * Prints the normal help message + */ + static void printHelp (const char* route); + }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Application/CWallpaperApplication.cpp b/src/WallpaperEngine/Application/CWallpaperApplication.cpp index 954ef02..948d520 100644 --- a/src/WallpaperEngine/Application/CWallpaperApplication.cpp +++ b/src/WallpaperEngine/Application/CWallpaperApplication.cpp @@ -1,366 +1,366 @@ #include "CWallpaperApplication.h" + +#include "Steam/FileSystem/FileSystem.h" #include "WallpaperEngine/Assets/CDirectory.h" #include "WallpaperEngine/Assets/CVirtualContainer.h" #include "WallpaperEngine/Audio/Drivers/CSDLAudioDriver.h" #include "WallpaperEngine/Core/CVideo.h" #include "WallpaperEngine/Logging/CLog.h" #include "WallpaperEngine/Render/CRenderContext.h" +#include "WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.h" #include "WallpaperEngine/Render/Drivers/Output/CX11Output.h" -#include "WallpaperEngine/Render/Drivers/Output/CWindowOutput.h" -#include "Steam/FileSystem/FileSystem.h" #include - float g_Time; float g_TimeLast; bool g_KeepRunning = true; bool g_AudioEnabled = true; int g_AudioVolume = 128; -using namespace WallpaperEngine::Application; -using namespace WallpaperEngine::Core; - -CWallpaperApplication::CWallpaperApplication (CApplicationContext& context) : - m_context (context), - m_defaultProject (nullptr) +namespace WallpaperEngine::Application { - // copy state to global variables for now - g_AudioVolume = context.audioVolume; - g_AudioEnabled = context.audioEnabled; - this->loadProjects (); - this->setupProperties (); -} - -void CWallpaperApplication::setupContainer (CCombinedContainer& container, const std::string& bg) const -{ - std::filesystem::path basepath = bg; - - container.add (new CDirectory (basepath)); - container.addPkg (basepath / "scene.pkg"); - container.addPkg (basepath / "gifscene.pkg"); - container.add (new CDirectory (this->m_context.assets)); - - // add two possible patches directories to the container - // hopefully one sticks - bool relative = true; - bool absolute = true; - - try - { - container.add (new CDirectory ("../share/")); - } - catch (std::runtime_error& ex) - { - relative = false; - } - - try - { - container.add (new CDirectory (DATADIR)); - } - catch (std::runtime_error& ex) - { - absolute = false; - } - - if (!relative && !absolute) - sLog.error ("WARNING: Shader patches directory cannot be found, this might make some backgrounds not work properly"); - - // TODO: move this somewhere else? - CVirtualContainer* virtualContainer = new CVirtualContainer (); - - // - // Had to get a little creative with the effects to achieve the same bloom effect without any custom code - // these virtual files are loaded by an image in the scene that takes current _rt_FullFrameBuffer and - // applies the bloom effect to render it out to the screen - // - - // add the effect file for screen bloom - virtualContainer->add ( - "effects/wpenginelinux/bloomeffect.json", - "{" - "\t\"name\":\"camerabloom_wpengine_linux\"," - "\t\"group\":\"wpengine_linux_camera\"," - "\t\"dependencies\":[]," - "\t\"passes\":" - "\t[" - "\t\t{" - "\t\t\t\"material\": \"materials/util/downsample_quarter_bloom.json\"," - "\t\t\t\"target\": \"_rt_4FrameBuffer\"," - "\t\t\t\"bind\":" - "\t\t\t[" - "\t\t\t\t{" - "\t\t\t\t\t\"name\": \"_rt_FullFrameBuffer\"," - "\t\t\t\t\t\"index\": 0" - "\t\t\t\t}" - "\t\t\t]" - "\t\t}," - "\t\t{" - "\t\t\t\"material\": \"materials/util/downsample_eighth_blur_v.json\"," - "\t\t\t\"target\": \"_rt_8FrameBuffer\"," - "\t\t\t\"bind\":" - "\t\t\t[" - "\t\t\t\t{" - "\t\t\t\t\t\"name\": \"_rt_4FrameBuffer\"," - "\t\t\t\t\t\"index\": 0" - "\t\t\t\t}" - "\t\t\t]" - "\t\t}," - "\t\t{" - "\t\t\t\"material\": \"materials/util/blur_h_bloom.json\"," - "\t\t\t\"target\": \"_rt_Bloom\"," - "\t\t\t\"bind\":" - "\t\t\t[" - "\t\t\t\t{" - "\t\t\t\t\t\"name\": \"_rt_8FrameBuffer\"," - "\t\t\t\t\t\"index\": 0" - "\t\t\t\t}" - "\t\t\t]" - "\t\t}," - "\t\t{" - "\t\t\t\"material\": \"materials/util/combine.json\"," - "\t\t\t\"target\": \"_rt_FullFrameBuffer\"," - "\t\t\t\"bind\":" - "\t\t\t[" - "\t\t\t\t{" - "\t\t\t\t\t\"name\": \"_rt_imageLayerComposite_-1_a\"," - "\t\t\t\t\t\"index\": 0" - "\t\t\t\t}," - "\t\t\t\t{" - "\t\t\t\t\t\"name\": \"_rt_Bloom\"," - "\t\t\t\t\t\"index\": 1" - "\t\t\t\t}" - "\t\t\t]" - "\t\t}" - "\t]" - "}" - ); - - // add some model for the image element even if it's going to waste rendering cycles - virtualContainer->add ( - "models/wpenginelinux.json", - "{" - "\t\"material\":\"materials/wpenginelinux.json\"" - "}" - ); - - // models require materials, so add that too - virtualContainer->add ( - "materials/wpenginelinux.json", - "{" - "\t\"passes\":" - "\t\t[" - "\t\t\t{" - "\t\t\t\t\"blending\": \"normal\"," - "\t\t\t\t\"cullmode\": \"nocull\"," - "\t\t\t\t\"depthtest\": \"disabled\"," - "\t\t\t\t\"depthwrite\": \"disabled\"," - "\t\t\t\t\"shader\": \"genericimage2\"," - "\t\t\t\t\"textures\": [\"_rt_FullFrameBuffer\"]" - "\t\t\t}" - "\t\t]" - "}" - ); - - container.add (virtualContainer); -} - -void CWallpaperApplication::loadProjects () -{ - for (const auto& it : this->m_context.screenSettings) - { - // ignore the screen settings if there was no background specified - // the default will be used - if (it.second.empty()) - continue; - - this->m_projects.insert_or_assign ( - it.first, - this->loadProject (it.second) - ); - } - - // load the default project if required - if (!this->m_context.background.empty ()) - this->m_defaultProject = this->loadProject (this->m_context.background); -} - -CProject* CWallpaperApplication::loadProject (const std::string& bg) -{ - CCombinedContainer* container = new CCombinedContainer (); - - this->setupContainer (*container, bg); - - // TODO: Change this to pointer instead of reference - return CProject::fromFile ("project.json", container); -} - -void CWallpaperApplication::setupPropertiesForProject (CProject* project) -{ - // show properties if required - for (auto cur : project->getProperties ()) - { - // update the value of the property - auto override = this->m_context.properties.find (cur->getName ()); - - if (override != this->m_context.properties.end ()) - { - sLog.out ("Applying override value for ", cur->getName ()); - - cur->update (override->second); - } - - if (this->m_context.onlyListProperties) - sLog.out (cur->dump ()); - } -} - -void CWallpaperApplication::setupProperties () -{ - for (const auto& it : this->m_projects) - this->setupPropertiesForProject (it.second); - - if (this->m_defaultProject != nullptr) - this->setupPropertiesForProject (this->m_defaultProject); -} - -void CWallpaperApplication::takeScreenshot (const Render::CRenderContext& context, const std::filesystem::path& filename, FREE_IMAGE_FORMAT format) -{ - // this should be getting called at the end of the frame, so the right thing should be bound already - - int width = context.getOutput ()->getFullWidth (); - int height = context.getOutput ()->getFullHeight (); - - // make room for storing the pixel data - uint8_t* buffer = new uint8_t [width * height * sizeof (uint8_t) * 3]; - uint8_t* pixel = buffer; - - // read the image into the buffer - glReadPixels (0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer); - - // build the output file with FreeImage - FIBITMAP* bitmap = FreeImage_Allocate (width, height, 24); - RGBQUAD color; - - // now get access to the pixels - for (int y = height; y > 0; y --) + CWallpaperApplication::CWallpaperApplication (CApplicationContext& context) : + m_context (context), + m_defaultBackground (nullptr) { - for (int x = 0; x < width; x ++) - { - color.rgbRed = *pixel ++; - color.rgbGreen = *pixel ++; - color.rgbBlue = *pixel ++; + // copy state to global variables for now + g_AudioVolume = context.audio.volume; + g_AudioEnabled = context.audio.enabled; + this->loadBackgrounds (); + this->setupProperties (); + } - // set the pixel in the destination - FreeImage_SetPixelColor (bitmap, x, y, &color); + void CWallpaperApplication::setupContainer (CCombinedContainer& container, const std::string& bg) const + { + std::filesystem::path basepath = bg; + + container.add (new CDirectory (basepath)); + container.addPkg (basepath / "scene.pkg"); + container.addPkg (basepath / "gifscene.pkg"); + container.add (new CDirectory (this->m_context.general.assets)); + + // add two possible patches directories to the container + // hopefully one sticks + bool relative = true; + bool absolute = true; + + try + { + container.add (new CDirectory ("../share/")); + } + catch (std::runtime_error& ex) + { + relative = false; + } + + try + { + container.add (new CDirectory (DATADIR)); + } + catch (std::runtime_error& ex) + { + absolute = false; + } + + if (!relative && !absolute) + sLog.error ( + "WARNING: Shader patches directory cannot be found, this might make some backgrounds not work " + "properly" + ); + + // TODO: move this somewhere else? + CVirtualContainer* virtualContainer = new CVirtualContainer (); + + // + // Had to get a little creative with the effects to achieve the same bloom effect without any custom code + // these virtual files are loaded by an image in the scene that takes current _rt_FullFrameBuffer and + // applies the bloom effect to render it out to the screen + // + + // add the effect file for screen bloom + + // add some model for the image element even if it's going to waste rendering cycles + virtualContainer->add ( + "effects/wpenginelinux/bloomeffect.json", + "{" + "\t\"name\":\"camerabloom_wpengine_linux\"," + "\t\"group\":\"wpengine_linux_camera\"," + "\t\"dependencies\":[]," + "\t\"passes\":" + "\t[" + "\t\t{" + "\t\t\t\"material\": \"materials/util/downsample_quarter_bloom.json\"," + "\t\t\t\"target\": \"_rt_4FrameBuffer\"," + "\t\t\t\"bind\":" + "\t\t\t[" + "\t\t\t\t{" + "\t\t\t\t\t\"name\": \"_rt_FullFrameBuffer\"," + "\t\t\t\t\t\"index\": 0" + "\t\t\t\t}" + "\t\t\t]" + "\t\t}," + "\t\t{" + "\t\t\t\"material\": \"materials/util/downsample_eighth_blur_v.json\"," + "\t\t\t\"target\": \"_rt_8FrameBuffer\"," + "\t\t\t\"bind\":" + "\t\t\t[" + "\t\t\t\t{" + "\t\t\t\t\t\"name\": \"_rt_4FrameBuffer\"," + "\t\t\t\t\t\"index\": 0" + "\t\t\t\t}" + "\t\t\t]" + "\t\t}," + "\t\t{" + "\t\t\t\"material\": \"materials/util/blur_h_bloom.json\"," + "\t\t\t\"target\": \"_rt_Bloom\"," + "\t\t\t\"bind\":" + "\t\t\t[" + "\t\t\t\t{" + "\t\t\t\t\t\"name\": \"_rt_8FrameBuffer\"," + "\t\t\t\t\t\"index\": 0" + "\t\t\t\t}" + "\t\t\t]" + "\t\t}," + "\t\t{" + "\t\t\t\"material\": \"materials/util/combine.json\"," + "\t\t\t\"target\": \"_rt_FullFrameBuffer\"," + "\t\t\t\"bind\":" + "\t\t\t[" + "\t\t\t\t{" + "\t\t\t\t\t\"name\": \"_rt_imageLayerComposite_-1_a\"," + "\t\t\t\t\t\"index\": 0" + "\t\t\t\t}," + "\t\t\t\t{" + "\t\t\t\t\t\"name\": \"_rt_Bloom\"," + "\t\t\t\t\t\"index\": 1" + "\t\t\t\t}" + "\t\t\t]" + "\t\t}" + "\t]" + "}" + ); + + virtualContainer->add ( + "models/wpenginelinux.json", + "{" + "\t\"material\":\"materials/wpenginelinux.json\"" + "}" + ); + + // models require materials, so add that too + virtualContainer->add ( + "materials/wpenginelinux.json", + "{" + "\t\"passes\":" + "\t\t[" + "\t\t\t{" + "\t\t\t\t\"blending\": \"normal\"," + "\t\t\t\t\"cullmode\": \"nocull\"," + "\t\t\t\t\"depthtest\": \"disabled\"," + "\t\t\t\t\"depthwrite\": \"disabled\"," + "\t\t\t\t\"shader\": \"genericimage2\"," + "\t\t\t\t\"textures\": [\"_rt_FullFrameBuffer\"]" + "\t\t\t}" + "\t\t]" + "}" + ); + + container.add (virtualContainer); + } + + void CWallpaperApplication::loadBackgrounds () + { + for (const auto& it : this->m_context.general.screenBackgrounds) + { + // ignore the screen settings if there was no background specified + // the default will be used + if (it.second.empty ()) + continue; + + this->m_backgrounds[it.first] = this->loadBackground (it.second); + } + + // load the default project if required + if (!this->m_context.general.defaultBackground.empty ()) + this->m_defaultBackground = this->loadBackground (this->m_context.general.defaultBackground); + } + + Core::CProject* CWallpaperApplication::loadBackground (const std::string& bg) + { + CCombinedContainer* container = new CCombinedContainer (); + + this->setupContainer (*container, bg); + + return Core::CProject::fromFile ("project.json", container); + } + + void CWallpaperApplication::setupPropertiesForProject (Core::CProject* project) + { + // show properties if required + for (auto cur : project->getProperties ()) + { + // update the value of the property + auto override = this->m_context.general.properties.find (cur->getName ()); + + if (override != this->m_context.general.properties.end ()) + { + sLog.out ("Applying override value for ", cur->getName ()); + + cur->update (override->second); + } + + if (this->m_context.general.onlyListProperties) + sLog.out (cur->dump ()); } } - // finally save the file - FreeImage_Save (format, bitmap, filename.c_str (), 0); - - // free all the used memory - delete[] buffer; - - FreeImage_Unload (bitmap); - - // unbind the textures - glBindTexture (GL_TEXTURE_2D, GL_NONE); -} - -void CWallpaperApplication::show () -{ - // initialize sdl audio driver - WallpaperEngine::Audio::Drivers::CSDLAudioDriver audioDriver; - // initialize audio context - WallpaperEngine::Audio::CAudioContext audioContext (audioDriver); - // initialize OpenGL driver - WallpaperEngine::Render::Drivers::COpenGLDriver videoDriver ("wallpaperengine"); - // initialize the input subsystem - WallpaperEngine::Input::CInputContext inputContext (videoDriver); - // output requested - WallpaperEngine::Render::Drivers::Output::COutput* output; - - // initialize the requested output - switch (this->m_context.windowMode) - { - case CApplicationContext::EXPLICIT_WINDOW: - case CApplicationContext::NORMAL_WINDOW: - output = new WallpaperEngine::Render::Drivers::Output::CWindowOutput (this->m_context, videoDriver); - break; - - case CApplicationContext::X11_BACKGROUND: - output = new WallpaperEngine::Render::Drivers::Output::CX11Output (this->m_context, videoDriver); - break; - } - - // initialize render context - WallpaperEngine::Render::CRenderContext context (output, videoDriver, inputContext, *this); - - // set all the specific wallpapers required - for (const auto& it : this->m_projects) - { - context.setWallpaper ( - it.first, - WallpaperEngine::Render::CWallpaper::fromWallpaper (it.second->getWallpaper (), context, audioContext) - ); - } - - // set the default rendering wallpaper if available - if (this->m_defaultProject != nullptr) - context.setDefaultWallpaper ( - WallpaperEngine::Render::CWallpaper::fromWallpaper (this->m_defaultProject->getWallpaper (), context, audioContext) - ); - - float startTime, endTime, minimumTime = 1.0f / this->m_context.maximumFPS; - - while (!videoDriver.closeRequested () && g_KeepRunning) + void CWallpaperApplication::setupProperties () { - // update input information - inputContext.update (); - // keep track of the previous frame's time - g_TimeLast = g_Time; - // calculate the current time value - g_Time = videoDriver.getRenderTime (); - // get the start time of the frame - startTime = g_Time; - // render the scene - context.render (); - // get the end time of the frame - endTime = videoDriver.getRenderTime (); + for (const auto& it : this->m_backgrounds) + this->setupPropertiesForProject (it.second); - // ensure the frame time is correct to not overrun FPS - if ((endTime - startTime) < minimumTime) - usleep ((minimumTime - (endTime - startTime)) * CLOCKS_PER_SEC); + if (this->m_defaultBackground != nullptr) + this->setupPropertiesForProject (this->m_defaultBackground); + } - if (this->m_context.takeScreenshot && videoDriver.getFrameCounter () == 5) + void CWallpaperApplication::takeScreenshot ( + const Render::CRenderContext& context, const std::filesystem::path& filename, FREE_IMAGE_FORMAT format + ) + { + // this should be getting called at the end of the frame, so the right thing should be bound already + + int width = context.getOutput ()->getFullWidth (); + int height = context.getOutput ()->getFullHeight (); + + // make room for storing the pixel data + uint8_t* buffer = new uint8_t[width * height * sizeof (uint8_t) * 3]; + uint8_t* pixel = buffer; + + // read the image into the buffer + glReadPixels (0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer); + + // build the output file with FreeImage + FIBITMAP* bitmap = FreeImage_Allocate (width, height, 24); + RGBQUAD color; + + // now get access to the pixels + for (int y = height; y > 0; y--) { - this->takeScreenshot (context, this->m_context.screenshot, this->m_context.screenshotFormat); + for (int x = 0; x < width; x++) + { + color.rgbRed = *pixel++; + color.rgbGreen = *pixel++; + color.rgbBlue = *pixel++; + + // set the pixel in the destination + FreeImage_SetPixelColor (bitmap, x, y, &color); + } + } + + // finally save the file + FreeImage_Save (format, bitmap, filename.c_str (), 0); + + // free all the used memory + delete[] buffer; + + FreeImage_Unload (bitmap); + + // unbind the textures + glBindTexture (GL_TEXTURE_2D, GL_NONE); + } + + void CWallpaperApplication::show () + { + // initialize sdl audio driver + WallpaperEngine::Audio::Drivers::CSDLAudioDriver audioDriver; + // initialize audio context + WallpaperEngine::Audio::CAudioContext audioContext (audioDriver); + // initialize OpenGL driver + WallpaperEngine::Render::Drivers::COpenGLDriver videoDriver ("wallpaperengine"); + // initialize the input subsystem + WallpaperEngine::Input::CInputContext inputContext (videoDriver); + // output requested + WallpaperEngine::Render::Drivers::Output::COutput* output; + + // initialize the requested output + switch (this->m_context.render.mode) + { + case CApplicationContext::EXPLICIT_WINDOW: + case CApplicationContext::NORMAL_WINDOW: + output = new WallpaperEngine::Render::Drivers::Output::CGLFWWindowOutput (this->m_context, videoDriver); + break; + + case CApplicationContext::X11_BACKGROUND: + output = new WallpaperEngine::Render::Drivers::Output::CX11Output (this->m_context, videoDriver); + break; + } + + // initialize render context + WallpaperEngine::Render::CRenderContext context (output, videoDriver, inputContext, *this); + + // set all the specific wallpapers required + for (const auto& it : this->m_backgrounds) + context.setWallpaper ( + it.first, + WallpaperEngine::Render::CWallpaper::fromWallpaper (it.second->getWallpaper (), context, audioContext) + ); + + // set the default rendering wallpaper if available + if (this->m_defaultBackground != nullptr) + context.setDefaultWallpaper (WallpaperEngine::Render::CWallpaper::fromWallpaper ( + this->m_defaultBackground->getWallpaper (), context, audioContext + )); + + float startTime, endTime, minimumTime = 1.0f / this->m_context.render.maximumFPS; + + while (!videoDriver.closeRequested () && g_KeepRunning) + { + // update input information + inputContext.update (); + // keep track of the previous frame's time + g_TimeLast = g_Time; + // calculate the current time value + g_Time = videoDriver.getRenderTime (); + // get the start time of the frame + startTime = g_Time; + // render the scene + context.render (); + // get the end time of the frame + endTime = videoDriver.getRenderTime (); + + // ensure the frame time is correct to not overrun FPS + if ((endTime - startTime) < minimumTime) + usleep ((minimumTime - (endTime - startTime)) * CLOCKS_PER_SEC); + + if (!this->m_context.screenshot.take || videoDriver.getFrameCounter () != 5) + continue; + + this->takeScreenshot (context, this->m_context.screenshot.path, this->m_context.screenshot.format); // disable screenshot just in case the counter overflows - this->m_context.takeScreenshot = false; + this->m_context.screenshot.take = false; } + + // ensure this is updated as sometimes it might not come from a signal + g_KeepRunning = false; + + sLog.out ("Stop requested"); + + SDL_Quit (); } - // ensure this is updated as sometimes it might not come from a signal - g_KeepRunning = false; + void CWallpaperApplication::signal (int signal) + { + g_KeepRunning = false; + } - sLog.out ("Stop requested"); + const std::map& CWallpaperApplication::getBackgrounds () const + { + return this->m_backgrounds; + } - SDL_Quit (); -} - -void CWallpaperApplication::signal (int signal) -{ - g_KeepRunning = false; -} - -const std::map & CWallpaperApplication::getProjects () const -{ - return this->m_projects; -} - -CProject* CWallpaperApplication::getDefaultProject () const -{ - return this->m_defaultProject; + Core::CProject* CWallpaperApplication::getDefaultBackground () const + { + return this->m_defaultBackground; + } } \ No newline at end of file diff --git a/src/WallpaperEngine/Application/CWallpaperApplication.h b/src/WallpaperEngine/Application/CWallpaperApplication.h index 99ac8a2..4dc35a5 100644 --- a/src/WallpaperEngine/Application/CWallpaperApplication.h +++ b/src/WallpaperEngine/Application/CWallpaperApplication.h @@ -1,42 +1,95 @@ #pragma once -#include "CApplicationContext.h" -#include "WallpaperEngine/Render/Drivers/COpenGLDriver.h" +#include "WallpaperEngine/Application/CApplicationContext.h" + #include "WallpaperEngine/Assets/CCombinedContainer.h" + #include "WallpaperEngine/Core/CProject.h" + #include "WallpaperEngine/Render/CWallpaper.h" #include "WallpaperEngine/Render/CRenderContext.h" - -namespace WallpaperEngine::Render -{ - class CWallpaper; - class CRenderContext; -} +#include "WallpaperEngine/Render/Drivers/COpenGLDriver.h" namespace WallpaperEngine::Application { - using namespace WallpaperEngine::Assets; - + /** + * Small wrapper class over the actual wallpaper's main application skeleton + * + * @author Alexis Maiquez + */ class CWallpaperApplication { public: - CWallpaperApplication (CApplicationContext& context); + explicit CWallpaperApplication (CApplicationContext& context); + /** + * Shows the application until it's closed + */ void show (); + /** + * Handles a OS signal sent to this PID + * + * @param signal + */ void signal (int signal); - const std::map & getProjects () const; - Core::CProject* getDefaultProject () const; + /** + * @return Maps screens to loaded backgrounds + */ + [[nodiscard]] const std::map & getBackgrounds () const; + /** + * @return The default background to use if no specific project is loaded + */ + [[nodiscard]] Core::CProject* getDefaultBackground () const; - private: + private: + /** + * Sets up a combined container for the given background, adding default files and directories to the list + * + * @param container + * @param bg + */ void setupContainer (CCombinedContainer& container, const std::string& bg) const; - void loadProjects (); - Core::CProject* loadProject (const std::string& bg); + /** + * Loads projects based off the settings + */ + void loadBackgrounds (); + /** + * Loads the given project + * + * @param bg + * @return + */ + Core::CProject* loadBackground (const std::string& bg); + /** + * Prepares all background's values and updates their properties if required + */ void setupProperties (); - void setupPropertiesForProject (Core::CProject* project); - void takeScreenshot (const Render::CRenderContext& context, const std::filesystem::path& filename, FREE_IMAGE_FORMAT format); + /** + * Updates the properties for the given background based on the current context + * + * @param project + */ + void setupPropertiesForProject (Core::CProject* project); + /** + * Takes an screenshot of the background and saves it to the specified path + * + * @param context + * @param filename + * @param format + */ + static void takeScreenshot (const Render::CRenderContext& context, const std::filesystem::path& filename, FREE_IMAGE_FORMAT format); - Core::CProject* m_defaultProject; + /** + * The default background to display if no specific background was loaded + */ + Core::CProject* m_defaultBackground; + /** + * The application context that contains the current app settings + */ CApplicationContext& m_context; - std::map m_projects; + /** + * Maps screens to backgrounds + */ + std::map m_backgrounds; }; } diff --git a/src/WallpaperEngine/Assets/CAssetLoadException.cpp b/src/WallpaperEngine/Assets/CAssetLoadException.cpp index f6e70f0..1f7cbc4 100644 --- a/src/WallpaperEngine/Assets/CAssetLoadException.cpp +++ b/src/WallpaperEngine/Assets/CAssetLoadException.cpp @@ -5,7 +5,6 @@ using namespace WallpaperEngine::Assets; CAssetLoadException::CAssetLoadException(const std::string& filename, const std::string& extrainfo) : m_message("Cannot find file " + filename + ": " + extrainfo) { - } const char *CAssetLoadException::what() const noexcept diff --git a/src/WallpaperEngine/Assets/CAssetLoadException.h b/src/WallpaperEngine/Assets/CAssetLoadException.h index 9aec138..43a9c81 100644 --- a/src/WallpaperEngine/Assets/CAssetLoadException.h +++ b/src/WallpaperEngine/Assets/CAssetLoadException.h @@ -8,8 +8,8 @@ namespace WallpaperEngine::Assets class CAssetLoadException : public std::exception { public: - CAssetLoadException(const std::string& filename, const std::string& extrainfo = ""); - const char* what() const noexcept override; + explicit CAssetLoadException (const std::string& filename, const std::string& extrainfo = ""); + [[nodiscard]] const char* what () const noexcept override; private: std::string m_message; diff --git a/src/WallpaperEngine/Assets/CCombinedContainer.cpp b/src/WallpaperEngine/Assets/CCombinedContainer.cpp index 4a48591..2063627 100644 --- a/src/WallpaperEngine/Assets/CCombinedContainer.cpp +++ b/src/WallpaperEngine/Assets/CCombinedContainer.cpp @@ -7,8 +7,8 @@ using namespace WallpaperEngine::Assets; CCombinedContainer::CCombinedContainer () : - CContainer (), - m_containers () + CContainer (), + m_containers () { } @@ -38,7 +38,7 @@ void CCombinedContainer::addPkg (const std::filesystem::path& path) } -std::filesystem::path CCombinedContainer::resolveRealFile (std::string filename) const +std::filesystem::path CCombinedContainer::resolveRealFile (const std::string& filename) const { for (auto cur : this->m_containers) { @@ -58,7 +58,7 @@ std::filesystem::path CCombinedContainer::resolveRealFile (std::string filename) throw CAssetLoadException (filename, "Cannot resolve file in any of the containers"); } -const void* CCombinedContainer::readFile (std::string filename, uint32_t* length) const +const void* CCombinedContainer::readFile (const std::string& filename, uint32_t* length) const { for (auto cur : this->m_containers) { diff --git a/src/WallpaperEngine/Assets/CCombinedContainer.h b/src/WallpaperEngine/Assets/CCombinedContainer.h index 663eef1..e5e00b8 100644 --- a/src/WallpaperEngine/Assets/CCombinedContainer.h +++ b/src/WallpaperEngine/Assets/CCombinedContainer.h @@ -1,17 +1,20 @@ #pragma once -#include -#include -#include - #include "CContainer.h" +#include +#include +#include + namespace WallpaperEngine::Assets { + /** + * A meta-container that allows backgrounds to have files spread across different containers + */ class CCombinedContainer : public CContainer { public: - CCombinedContainer (); + CCombinedContainer (); /** * Adds a container to the list @@ -19,12 +22,20 @@ namespace WallpaperEngine::Assets * @param container */ void add (CContainer* container); + /** + * Adds the given package to the list + * + * @param path + */ void addPkg (const std::filesystem::path& path); - std::filesystem::path resolveRealFile (std::string filename) const override; - const void* readFile (std::string filename, uint32_t* length = nullptr) const override; + /** @inheritdoc */ + [[nodiscard]] std::filesystem::path resolveRealFile (const std::string& filename) const override; + /** @inheritdoc */ + [[nodiscard]] const void* readFile (const std::string& filename, uint32_t* length) const override; private: + /** The list of containers to search files off from */ std::vector m_containers; }; }; \ No newline at end of file diff --git a/src/WallpaperEngine/Assets/CContainer.cpp b/src/WallpaperEngine/Assets/CContainer.cpp index 4eb5fa3..0c632c0 100644 --- a/src/WallpaperEngine/Assets/CContainer.cpp +++ b/src/WallpaperEngine/Assets/CContainer.cpp @@ -9,58 +9,58 @@ using namespace WallpaperEngine::Assets; -std::filesystem::path CContainer::resolveRealFile (std::string filename) const +std::filesystem::path CContainer::resolveRealFile (const std::string& filename) const { - throw CAssetLoadException (filename, "Cannot resolve physical file in this container"); + throw CAssetLoadException (filename, "Cannot resolve physical file in this container"); } -const ITexture* CContainer::readTexture (std::string filename) const +const ITexture* CContainer::readTexture (const std::string& filename) const { // get the texture's filename (usually .tex) - filename = "materials/" + filename + ".tex"; + std::string texture = "materials/" + filename + ".tex"; - const void* textureContents = this->readFile (filename, nullptr); + const void* textureContents = this->readFile (texture, nullptr); ITexture* result = new CTexture (textureContents); #if !NDEBUG - glObjectLabel (GL_TEXTURE, result->getTextureID (), -1, filename.c_str ()); + glObjectLabel (GL_TEXTURE, result->getTextureID (), -1, texture.c_str ()); #endif /* NDEBUG */ return result; } std::string CContainer::readShader (const std::string& filename) const { - std::filesystem::path shader = filename; - auto it = shader.begin (); + std::filesystem::path shader = filename; + auto it = shader.begin (); - // detect workshop shaders and check if there's a - if (*it++ == "workshop") - { - std::filesystem::path workshopId = *it++; + // detect workshop shaders and check if there's a + if (*it++ == "workshop") + { + std::filesystem::path workshopId = *it++; - if (++it != shader.end ()) - { - std::filesystem::path shaderfile = *it; + if (++it != shader.end ()) + { + std::filesystem::path shaderfile = *it; - try - { - shader = std::filesystem::path ("zcompat") / "scene" / "shaders" / workshopId / shaderfile; - // replace the old path with the new one - std::string contents = this->readFileAsString (shader); + try + { + shader = std::filesystem::path ("zcompat") / "scene" / "shaders" / workshopId / shaderfile; + // replace the old path with the new one + std::string contents = this->readFileAsString (shader); - sLog.out ("Replaced ", filename, " with compat ", shader); + sLog.out ("Replaced ", filename, " with compat ", shader); - return contents; - } - catch (CAssetLoadException&) - { + return contents; + } + catch (CAssetLoadException&) + { - } - } - } + } + } + } - return this->readFileAsString ("shaders/" + filename); + return this->readFileAsString ("shaders/" + filename); } std::string CContainer::readVertexShader (const std::string& filename) const @@ -78,7 +78,7 @@ std::string CContainer::readIncludeShader (const std::string& filename) const return this->readFileAsString ("shaders/" + filename); } -std::string CContainer::readFileAsString (std::string filename) const +std::string CContainer::readFileAsString (const std::string& filename) const { uint32_t length = 0; diff --git a/src/WallpaperEngine/Assets/CContainer.h b/src/WallpaperEngine/Assets/CContainer.h index 4426a56..dde5f7b 100644 --- a/src/WallpaperEngine/Assets/CContainer.h +++ b/src/WallpaperEngine/Assets/CContainer.h @@ -1,21 +1,25 @@ #pragma once +#include "WallpaperEngine/Assets/ITexture.h" + #include #include -#include "WallpaperEngine/Assets/ITexture.h" namespace WallpaperEngine::Assets { + /** + * File container, provides access to files for backgrounds + */ class CContainer { public: - /** - * Resolves the full path to the specified file in the filesystem - * - * @param filename - * @return - */ - virtual std::filesystem::path resolveRealFile (std::string filename) const; + /** + * Resolves the full path to the specified file in the filesystem + * + * @param filename + * @return + */ + [[nodiscard]] virtual std::filesystem::path resolveRealFile (const std::string& filename) const; /** * Reads the given file from the container and returns it's data @@ -26,7 +30,7 @@ namespace WallpaperEngine::Assets * * @return */ - virtual const void* readFile (std::string filename, uint32_t* length = nullptr) const = 0; + [[nodiscard]] virtual const void* readFile (const std::string& filename, uint32_t* length) const = 0; /** * Wrapper for readFile, appends the texture extension at the end of the filename @@ -35,16 +39,16 @@ namespace WallpaperEngine::Assets * * @return */ - const ITexture* readTexture (std::string filename) const; + [[nodiscard]] const ITexture* readTexture (const std::string& filename) const; - /** - * Wrapper for readFile, checks for compat versions of the given shader file - * - * @param filename - * - * @return The shader code as an string to be used - */ - std::string readShader (const std::string& filename) const; + /** + * Wrapper for readFile, checks for compat versions of the given shader file + * + * @param filename + * + * @return The shader code as an string to be used + */ + [[nodiscard]] std::string readShader (const std::string& filename) const; /** * Wrapper for readFile, appends the .vert extension at the end and opens the given shader file @@ -53,7 +57,7 @@ namespace WallpaperEngine::Assets * * @return The shader code as an string to be used */ - std::string readVertexShader (const std::string& filename) const; + [[nodiscard]] std::string readVertexShader (const std::string& filename) const; /** * Wrapper for readFile, appends the .frag extension at the end and opens the given shader file @@ -62,7 +66,7 @@ namespace WallpaperEngine::Assets * * @return The shader code as an string to be used */ - std::string readFragmentShader (const std::string& filename) const; + [[nodiscard]] std::string readFragmentShader (const std::string& filename) const; /** * Wrapper for readFile, appends the .h extension at the end and opens the given shader file @@ -71,7 +75,7 @@ namespace WallpaperEngine::Assets * * @return The shader code as an string to be used */ - std::string readIncludeShader (const std::string& filename) const; + [[nodiscard]] std::string readIncludeShader (const std::string& filename) const; /** * Reads a file as string @@ -80,6 +84,6 @@ namespace WallpaperEngine::Assets * * @return The file's contents as string */ - std::string readFileAsString (std::string filename) const; + [[nodiscard]] std::string readFileAsString (const std::string& filename) const; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Assets/CDirectory.cpp b/src/WallpaperEngine/Assets/CDirectory.cpp index 46634ca..d66cb25 100644 --- a/src/WallpaperEngine/Assets/CDirectory.cpp +++ b/src/WallpaperEngine/Assets/CDirectory.cpp @@ -24,12 +24,12 @@ CDirectory::CDirectory (std::filesystem::path basepath) : CDirectory::~CDirectory () = default; -std::filesystem::path CDirectory::resolveRealFile (std::string filename) const +std::filesystem::path CDirectory::resolveRealFile (const std::string& filename) const { - return std::filesystem::path (this->m_basepath) / filename; + return std::filesystem::path (this->m_basepath) / filename; } -const void* CDirectory::readFile (std::string filename, uint32_t* length) const +const void* CDirectory::readFile (const std::string& filename, uint32_t* length) const { std::filesystem::path final = std::filesystem::path (this->m_basepath) / filename; diff --git a/src/WallpaperEngine/Assets/CDirectory.h b/src/WallpaperEngine/Assets/CDirectory.h index 09cdf3f..514218c 100644 --- a/src/WallpaperEngine/Assets/CDirectory.h +++ b/src/WallpaperEngine/Assets/CDirectory.h @@ -10,16 +10,24 @@ namespace WallpaperEngine::Assets { + /** + * Directory container implementation, provides access to background files under a specific directory + */ class CDirectory : public CContainer { public: explicit CDirectory (std::filesystem::path basepath); ~CDirectory (); - std::filesystem::path resolveRealFile (std::string filename) const override; - const void* readFile (std::string filename, uint32_t* length) const override; + /** @inheritdoc */ + [[nodiscard]] std::filesystem::path resolveRealFile (const std::string& filename) const override; + /** @inheritdoc */ + [[nodiscard]] const void* readFile (const std::string& filename, uint32_t* length) const override; + private: + /** The basepath for the directory */ std::filesystem::path m_basepath; + /** File cache to simplify access to data */ std::map m_cache; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Assets/CFileEntry.h b/src/WallpaperEngine/Assets/CFileEntry.h index 963bd18..bf2ab9e 100644 --- a/src/WallpaperEngine/Assets/CFileEntry.h +++ b/src/WallpaperEngine/Assets/CFileEntry.h @@ -1,11 +1,10 @@ -// -// Created by almamu on 8/8/21. -// - #pragma once namespace WallpaperEngine::Assets { + /** + * File cache entry to prevent hit the disk when loading the same file multiple times + */ class CFileEntry { public: @@ -13,7 +12,9 @@ namespace WallpaperEngine::Assets address (address), length (length) { } + /** File contents */ const void* address; + /** File length */ uint32_t length; }; } diff --git a/src/WallpaperEngine/Assets/CPackage.cpp b/src/WallpaperEngine/Assets/CPackage.cpp index 8d23957..d9438c5 100644 --- a/src/WallpaperEngine/Assets/CPackage.cpp +++ b/src/WallpaperEngine/Assets/CPackage.cpp @@ -32,7 +32,7 @@ CPackage::~CPackage() = default; -const void* CPackage::readFile (std::string filename, uint32_t* length) const +const void* CPackage::readFile (const std::string& filename, uint32_t* length) const { auto it = this->m_contents.find (filename); diff --git a/src/WallpaperEngine/Assets/CPackage.h b/src/WallpaperEngine/Assets/CPackage.h index a7696cb..a8be5c2 100644 --- a/src/WallpaperEngine/Assets/CPackage.h +++ b/src/WallpaperEngine/Assets/CPackage.h @@ -13,13 +13,17 @@ namespace WallpaperEngine::Assets { + /** + * Package container implementation, provides access to background files that are stored + * inside the WallpaperEngine's pkg format + */ class CPackage : public CContainer { public: explicit CPackage (std::filesystem::path path); ~CPackage (); - const void* readFile (std::string filename, uint32_t* length) const override; + [[nodiscard]] const void* readFile (const std::string& filename, uint32_t* length) const override; protected: /** @@ -59,7 +63,9 @@ namespace WallpaperEngine::Assets uint32_t readInteger (FILE* fp); private: + /** The path to the package file */ std::filesystem::path m_path; + /** Contents of the package file */ std::map m_contents; }; } diff --git a/src/WallpaperEngine/Assets/CPackageLoadException.cpp b/src/WallpaperEngine/Assets/CPackageLoadException.cpp index bc2c59f..7ed7eb8 100644 --- a/src/WallpaperEngine/Assets/CPackageLoadException.cpp +++ b/src/WallpaperEngine/Assets/CPackageLoadException.cpp @@ -2,12 +2,12 @@ using namespace WallpaperEngine::Assets; -CPackageLoadException::CPackageLoadException(const std::string& filename, const std::string& extrainfo) - : m_message("Cannot load package " + filename + ": " + extrainfo) +CPackageLoadException::CPackageLoadException (const std::string& filename, const std::string& extrainfo) : + m_message ("Cannot load package " + filename + ": " + extrainfo) { } -const char *CPackageLoadException::what() const noexcept +const char *CPackageLoadException::what () const noexcept { return this->m_message.c_str (); } diff --git a/src/WallpaperEngine/Assets/CPackageLoadException.h b/src/WallpaperEngine/Assets/CPackageLoadException.h index 37db8c0..e94c6e5 100644 --- a/src/WallpaperEngine/Assets/CPackageLoadException.h +++ b/src/WallpaperEngine/Assets/CPackageLoadException.h @@ -8,8 +8,8 @@ namespace WallpaperEngine::Assets class CPackageLoadException : public std::exception { public: - explicit CPackageLoadException(const std::string& message, const std::string& extrainfo = ""); - const char* what() const noexcept override; + explicit CPackageLoadException (const std::string& message, const std::string& extrainfo = ""); + [[nodiscard]] const char* what () const noexcept override; private: std::string m_message; diff --git a/src/WallpaperEngine/Assets/CTexture.cpp b/src/WallpaperEngine/Assets/CTexture.cpp index 9af11ef..05db4d4 100644 --- a/src/WallpaperEngine/Assets/CTexture.cpp +++ b/src/WallpaperEngine/Assets/CTexture.cpp @@ -8,7 +8,7 @@ using namespace WallpaperEngine::Assets; CTexture::CTexture (const void* fileData) : - m_resolution () + m_resolution () { // ensure the header is parsed this->m_header = parseHeader (static_cast (fileData)); @@ -62,27 +62,27 @@ CTexture::CTexture (const void* fileData) : // detect the image format and hand it to openGL to be used switch (this->m_header->format) { - case TextureFormat::DXT5: - internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - break; - case TextureFormat::DXT3: - internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - break; - case TextureFormat::DXT1: - internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; - break; - case TextureFormat::ARGB8888: - internalFormat = GL_RGBA8; - break; - case TextureFormat::R8: - internalFormat = GL_R8; - break; - case TextureFormat::RG88: - internalFormat = GL_RG8; - break; - default: - delete this->m_header; - sLog.exception ("Cannot determine texture format"); + case TextureFormat::DXT5: + internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + break; + case TextureFormat::DXT3: + internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + break; + case TextureFormat::DXT1: + internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + break; + case TextureFormat::ARGB8888: + internalFormat = GL_RGBA8; + break; + case TextureFormat::R8: + internalFormat = GL_R8; + break; + case TextureFormat::RG88: + internalFormat = GL_RG8; + break; + default: + delete this->m_header; + sLog.exception ("Cannot determine texture format"); } } @@ -161,39 +161,39 @@ CTexture::CTexture (const void* fileData) : } else { - if (this->m_header->format == TextureFormat::R8) - { - // red textures are 1-byte-per-pixel, so it's alignment has to be set manually - glPixelStorei (GL_UNPACK_ALIGNMENT, 1); - textureFormat = GL_RED; - } - else if (this->m_header->format == TextureFormat::RG88) + if (this->m_header->format == TextureFormat::R8) + { + // red textures are 1-byte-per-pixel, so it's alignment has to be set manually + glPixelStorei (GL_UNPACK_ALIGNMENT, 1); + textureFormat = GL_RED; + } + else if (this->m_header->format == TextureFormat::RG88) textureFormat = GL_RG; } switch (internalFormat) { - case GL_RGBA8: - case GL_RG8: - case GL_R8: - glTexImage2D ( - GL_TEXTURE_2D, level, internalFormat, - width, height, 0, - textureFormat, GL_UNSIGNED_BYTE, - dataptr - ); - break; - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - glCompressedTexImage2D ( - GL_TEXTURE_2D, level, internalFormat, - width, height, 0, - bufferSize, dataptr - ); - break; - default: - sLog.exception ("Cannot load texture, unknown format", this->m_header->format); + case GL_RGBA8: + case GL_RG8: + case GL_R8: + glTexImage2D ( + GL_TEXTURE_2D, level, internalFormat, + width, height, 0, + textureFormat, GL_UNSIGNED_BYTE, + dataptr + ); + break; + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + glCompressedTexImage2D ( + GL_TEXTURE_2D, level, internalFormat, + width, height, 0, + bufferSize, dataptr + ); + break; + default: + sLog.exception ("Cannot load texture, unknown format", this->m_header->format); } // freeimage buffer won't be used anymore, so free memory @@ -309,14 +309,14 @@ void CTexture::TextureMipmap::decompressData () } CTexture::TextureFrame::TextureFrame () : - frameNumber (0), - frametime (0.0f), - x (0), - y (0), - width1 (0), - width2 (0), - height1 (0), - height2 (0) + frameNumber (0), + frametime (0.0f), + x (0), + y (0), + width1 (0), + width2 (0), + height1 (0), + height2 (0) { } @@ -324,16 +324,16 @@ CTexture::TextureFrame::~TextureFrame () = default; CTexture::TextureHeader::TextureHeader () : - flags (NoFlags), - width (0), - height (0), - textureWidth (0), - textureHeight (0), - gifWidth (0), - gifHeight (0), - format (TextureFormat::UNKNOWN), - imageCount (0), - mipmapCount (0) + flags (NoFlags), + width (0), + height (0), + textureWidth (0), + textureHeight (0), + gifWidth (0), + gifHeight (0), + format (TextureFormat::UNKNOWN), + imageCount (0), + mipmapCount (0) { } diff --git a/src/WallpaperEngine/Assets/CTexture.h b/src/WallpaperEngine/Assets/CTexture.h index 22dca56..7c37df6 100644 --- a/src/WallpaperEngine/Assets/CTexture.h +++ b/src/WallpaperEngine/Assets/CTexture.h @@ -1,40 +1,26 @@ #pragma once -#include -#include -#include - -#include -#include +#include "ITexture.h" #include +#include +#include #include -#include "ITexture.h" +#include +#include +#include namespace WallpaperEngine::Assets { + /** + * A normal texture file in WallpaperEngine's format + */ class CTexture : public ITexture { - struct TextureHeader; - - public: - explicit CTexture (const void* fileData); - ~CTexture (); - - const GLuint getTextureID (uint32_t imageIndex = 0) const override; - const uint32_t getTextureWidth (uint32_t imageIndex = 0) const override; - const uint32_t getTextureHeight (uint32_t imageIndex = 0) const override; - const uint32_t getRealWidth () const override; - const uint32_t getRealHeight () const override; - const TextureFormat getFormat () const override; - const TextureFlags getFlags () const override; - const glm::vec4* getResolution () const override; - const std::vector& getFrames () const override; - const bool isAnimated () const override; - private: - const TextureHeader* getHeader () const; - + /** + * Different texture container versions supported + */ enum ContainerVersion : int { UNKNOWN = -1, @@ -43,6 +29,9 @@ namespace WallpaperEngine::Assets TEXB0001 = 1 }; + /** + * Different texture animation versions supported + */ enum AnimatedVersion : int { TEXSUNKN = -1, @@ -50,6 +39,9 @@ namespace WallpaperEngine::Assets TEXS0003 = 1, }; + /** + * Texture mipmap data + */ class TextureMipmap { public: @@ -76,13 +68,16 @@ namespace WallpaperEngine::Assets void decompressData (); }; + /** + * Texture header data + */ class TextureHeader { public: TextureHeader (); ~TextureHeader (); - bool isAnimated () const; + [[nodiscard]] bool isAnimated () const; /** The version of the texture container */ ContainerVersion containerVersion = ContainerVersion::UNKNOWN; @@ -111,17 +106,70 @@ namespace WallpaperEngine::Assets /** Number of mipmap levels on the texture */ uint32_t mipmapCount; /** List of mipmaps */ - std::map > images; + std::map> images; /** List of animation frames */ - std::vector frames; + std::vector frames; }; + + public: + explicit CTexture (const void* fileData); + ~CTexture (); + + /** @inheritdoc */ + [[nodiscard]] const GLuint getTextureID (uint32_t imageIndex = 0) const override; + /** @inheritdoc */ + [[nodiscard]] const uint32_t getTextureWidth (uint32_t imageIndex = 0) const override; + /** @inheritdoc */ + [[nodiscard]] const uint32_t getTextureHeight (uint32_t imageIndex = 0) const override; + /** @inheritdoc */ + [[nodiscard]] const uint32_t getRealWidth () const override; + /** @inheritdoc */ + [[nodiscard]] const uint32_t getRealHeight () const override; + /** @inheritdoc */ + [[nodiscard]] const TextureFormat getFormat () const override; + /** @inheritdoc */ + [[nodiscard]] const TextureFlags getFlags () const override; + /** @inheritdoc */ + [[nodiscard]] const glm::vec4* getResolution () const override; + /** @inheritdoc */ + [[nodiscard]] const std::vector& getFrames () const override; + /** @inheritdoc */ + [[nodiscard]] const bool isAnimated () const override; + private: + /** + * @return The texture header + */ + [[nodiscard]] const TextureHeader* getHeader () const; + + /** + * Tries to parse a header off the given data pointer + * + * @param fileData The point at which to start reading data off from + * @return + */ static TextureHeader* parseHeader (const char* fileData); + /** + * Tries to parse an animation frame off the given data pointer + * + * @param originalFileData The point at which to start reading data off from + * @return + */ static TextureFrame* parseAnimation (const char** originalFileData); + /** + * Tries to parse mipmap information off the given data pointer + * + * @param header The file header + * @param fileData The point at which to start reading data off from + * @return + */ static TextureMipmap* parseMipmap (TextureHeader* header, const char** fileData); + /** The texture header */ TextureHeader* m_header; + /** OpenGL's texture ID */ GLuint* m_textureID; + /** Resolution vector of the texture */ glm::vec4 m_resolution; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Assets/CVirtualContainer.cpp b/src/WallpaperEngine/Assets/CVirtualContainer.cpp index 7849314..2a8d69d 100644 --- a/src/WallpaperEngine/Assets/CVirtualContainer.cpp +++ b/src/WallpaperEngine/Assets/CVirtualContainer.cpp @@ -23,7 +23,7 @@ void CVirtualContainer::add (const std::string& filename, const std::string& con this->add (filename, copy, contents.length () + 1); } -const void* CVirtualContainer::readFile (std::string filename, uint32_t* length) const +const void* CVirtualContainer::readFile (const std::string& filename, uint32_t* length) const { auto cur = this->m_virtualFiles.find (filename); diff --git a/src/WallpaperEngine/Assets/CVirtualContainer.h b/src/WallpaperEngine/Assets/CVirtualContainer.h index bc99392..9327d65 100644 --- a/src/WallpaperEngine/Assets/CVirtualContainer.h +++ b/src/WallpaperEngine/Assets/CVirtualContainer.h @@ -8,6 +8,9 @@ namespace WallpaperEngine::Assets { + /** + * Virtual container implementation, provides virtual files for the backgrounds to use + */ class CVirtualContainer : public CContainer { public: @@ -30,10 +33,11 @@ namespace WallpaperEngine::Assets * @param contents */ void add (const std::string& filename, const std::string& contents); - - const void* readFile (std::string filename, uint32_t* length) const override; + /** @inheritdoc */ + const void* readFile (const std::string& filename, uint32_t* length) const override; private: + /** The recorded files in this virtual container */ std::map m_virtualFiles; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Assets/ITexture.h b/src/WallpaperEngine/Assets/ITexture.h index 30d8c67..338a592 100644 --- a/src/WallpaperEngine/Assets/ITexture.h +++ b/src/WallpaperEngine/Assets/ITexture.h @@ -6,9 +6,16 @@ namespace WallpaperEngine::Assets { + /** + * Base interface that describes the minimum information required for a texture + * to be displayed by the engine + */ class ITexture { public: + /** + * Texture frame information for animated textures + */ class TextureFrame { public: @@ -32,11 +39,11 @@ namespace WallpaperEngine::Assets }; /** - * Configures the data format for the texture + * Data formats for textures in memory */ enum TextureFormat : uint32_t { - UNKNOWN = 0xFFFFFFFF, + UNKNOWN = 0xFFFFFFFF, ARGB8888 = 0, RGB888 = 1, RGB565 = 2, @@ -54,7 +61,7 @@ namespace WallpaperEngine::Assets }; /** - * Configures how the texture will be handled by the background + * Different settings of the textures */ enum TextureFlags : uint32_t { @@ -64,15 +71,48 @@ namespace WallpaperEngine::Assets IsGif = 4, }; - virtual const GLuint getTextureID (uint32_t imageIndex = 0) const = 0; - virtual const uint32_t getTextureWidth (uint32_t imageIndex = 0) const = 0; - virtual const uint32_t getTextureHeight (uint32_t imageIndex = 0) const = 0; - virtual const uint32_t getRealWidth () const = 0; - virtual const uint32_t getRealHeight () const = 0; - virtual const TextureFormat getFormat () const = 0; - virtual const TextureFlags getFlags () const = 0; - virtual const std::vector& getFrames () const = 0; - virtual const glm::vec4* getResolution () const = 0; - virtual const bool isAnimated () const = 0; + /** + * @param imageIndex For animated textures, the frame to get the ID of + * @return The OpenGL texture to use when rendering + */ + [[nodiscard]] virtual const GLuint getTextureID (uint32_t imageIndex = 0) const = 0; + /** + * @param imageIndex For animated textures, the frame to get the ID of + * @return The texture's width + */ + [[nodiscard]] virtual const uint32_t getTextureWidth (uint32_t imageIndex = 0) const = 0; + /** + * @param imageIndex For animated textures, the frame to get the ID of + * @return The texture's height + */ + [[nodiscard]] virtual const uint32_t getTextureHeight (uint32_t imageIndex = 0) const = 0; + /** + * @return The textures real width + */ + [[nodiscard]] virtual const uint32_t getRealWidth () const = 0; + /** + * @return The textures real height + */ + [[nodiscard]] virtual const uint32_t getRealHeight () const = 0; + /** + * @return The texture's memory format + */ + [[nodiscard]] virtual const TextureFormat getFormat () const = 0; + /** + * @return The texture's settings + */ + [[nodiscard]] virtual const TextureFlags getFlags () const = 0; + /** + * @return The list of frames this texture has + */ + [[nodiscard]] virtual const std::vector& getFrames () const = 0; + /** + * @return The texture's resolution vector + */ + [[nodiscard]] virtual const glm::vec4* getResolution () const = 0; + /** + * @return If the texture is animated or not + */ + [[nodiscard]] virtual const bool isAnimated () const = 0; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Audio/CAudioContext.h b/src/WallpaperEngine/Audio/CAudioContext.h index 2b6e3f1..d7d4b8a 100644 --- a/src/WallpaperEngine/Audio/CAudioContext.h +++ b/src/WallpaperEngine/Audio/CAudioContext.h @@ -17,12 +17,30 @@ namespace WallpaperEngine::Audio public: explicit CAudioContext (Drivers::CAudioDriver& driver); + /** + * Registers the given stream in the driver for playing + * + * @param stream + */ void addStream (CAudioStream* stream); - AVSampleFormat getFormat () const; - int getSampleRate () const; - int getChannels () const; + /** + * TODO: MAYBE THIS SHOULD BE OUR OWN DEFINITIONS INSTEAD OF LIBRARY SPECIFIC ONES? + * + * @return The audio format the driver supports + */ + [[nodiscard]] AVSampleFormat getFormat () const; + /** + * @return The sample rate the driver supports + */ + [[nodiscard]] int getSampleRate () const; + /** + * @return The channels the driver supports + */ + [[nodiscard]] int getChannels () const; + private: + /** The audio driver in use */ Drivers::CAudioDriver& m_driver; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Audio/CAudioStream.cpp b/src/WallpaperEngine/Audio/CAudioStream.cpp index 2915757..17831ba 100644 --- a/src/WallpaperEngine/Audio/CAudioStream.cpp +++ b/src/WallpaperEngine/Audio/CAudioStream.cpp @@ -28,8 +28,8 @@ int audio_read_thread (void* arg) // give the cpu some time to play the queued frames if there's enough info there if ( stream->getQueueSize () >= MAX_QUEUE_SIZE || - (stream->getQueuePacketCount () > MIN_FRAMES && - (av_q2d (stream->getTimeBase ()) * stream->getQueueDuration () > 1.0)) + (stream->getQueuePacketCount () > MIN_FRAMES && + (av_q2d (stream->getTimeBase ()) * stream->getQueueDuration () > 1.0)) ) { SDL_LockMutex (waitMutex); @@ -328,7 +328,7 @@ void CAudioStream::dequeuePacket (AVPacket* output) #if FF_API_FIFO_OLD_API int ret = av_fifo_read (this->m_queue->packetList, &entry, 1); #else - int ret = -1; + int ret = -1; if (av_fifo_size (this->m_queue->packetList) >= sizeof (entry)) ret = av_fifo_generic_read (this->m_queue->packetList, &entry, sizeof (entry), nullptr); @@ -450,7 +450,7 @@ void CAudioStream::stop () int CAudioStream::resampleAudio (AVFrame * decoded_audio_frame, uint8_t * out_buf) { - int out_linesize = 0; + int out_linesize = 0; int ret; int out_nb_channels; int in_nb_samples; @@ -515,7 +515,7 @@ int CAudioStream::resampleAudio (AVFrame * decoded_audio_frame, uint8_t * out_bu // retrieve output samples number taking into account the progressive delay out_nb_samples = av_rescale_rnd( swr_get_delay(this->m_swrctx, this->getContext ()->sample_rate) + in_nb_samples, - this->m_audioContext.getSampleRate (), + this->m_audioContext.getSampleRate (), this->getContext ()->sample_rate, AV_ROUND_UP ); @@ -634,7 +634,7 @@ int CAudioStream::decodeFrame (uint8_t* audioBuffer, int bufferSize) if (ret < 0 && ret != AVERROR (EAGAIN)) return -1; - len1 = pkt->size; + len1 = pkt->size; if (len1 < 0) { diff --git a/src/WallpaperEngine/Audio/CAudioStream.h b/src/WallpaperEngine/Audio/CAudioStream.h index 1c0537f..4144103 100644 --- a/src/WallpaperEngine/Audio/CAudioStream.h +++ b/src/WallpaperEngine/Audio/CAudioStream.h @@ -4,12 +4,12 @@ extern "C" { - #include - #include - #include - #include - #include - #include +#include +#include +#include +#include +#include +#include } #include @@ -19,6 +19,11 @@ extern "C" namespace WallpaperEngine::Audio { + class CAudioContext; + + /** + * Represents a playable audio stream for the audio driver + */ class CAudioStream { public: @@ -38,66 +43,165 @@ namespace WallpaperEngine::Audio */ void dequeuePacket (AVPacket* output); + /** + * @return to the codec context, which provides information on the audio stream's format + */ AVCodecContext* getContext (); + /** + * @returns the format context, which controls how data is read off the audio stream + */ AVFormatContext* getFormatContext (); + /** + * @return The audio stream index of the given file + */ int getAudioStream (); + /** + * @return If the audio stream can be played or not + */ bool isInitialized (); + /** + * @param newRepeat true = repeat, false = no repeat + */ void setRepeat (bool newRepeat = true); + /** + * @return If the stream is to be repeated at the end or not + */ bool isRepeat (); + /** + * Stops decoding and playbak of the stream + */ void stop (); + /** + * @return The file data buffer + */ const void* getBuffer (); + /** + * @return The length of the file data buffer + */ int getLength (); + /** + * @return The read position of the data buffer + */ int getPosition (); + /** + * Updates the read position of the data buffer + * + * @param current + */ void setPosition (int current); + /** + * @return The SDL_cond used to signal waiting for data + */ SDL_cond* getWaitCondition (); + /** + * @return The data queue size + */ int getQueueSize (); + /** + * @return The amount of packets ready to be converted and played + */ int getQueuePacketCount (); + /** + * @return The duration (in seconds) of the queued data to be played + */ int64_t getQueueDuration (); + /** + * @return Time unit used for packet playback + */ AVRational getTimeBase (); + /** + * @return If the data queue is empty or not + */ bool isQueueEmpty (); + /** + * @return The SDL_mutex used for thread synchronization + */ SDL_mutex* getMutex (); + /** + * Reads a frame from the audio stream, resamples it to the driver's settings + * and returns the data ready to be played + * + * @param audioBuffer + * @param bufferSize + * + * @return The amount of bytes available or < 0 for error + */ int decodeFrame (uint8_t* audioBuffer, int bufferSize); private: + /** + * Initializes ffmpeg to read the given file + * + * @param filename + */ void loadCustomContent (const char* filename = nullptr); - int resampleAudio (AVFrame * decoded_audio_frame, uint8_t* out_buf); + /** + * Converts the audio frame from the original format to one supported by the audio driver + * + * @param decoded_audio_frame + * @param out_buf + * @return + */ + int resampleAudio (AVFrame* decoded_audio_frame, uint8_t* out_buf); + /** + * Queues a packet into the play queue + * + * @param pkt + * @return + */ bool doQueue (AVPacket* pkt); + /** + * Initializes queues and ffmpeg resampling + */ void initialize (); #if FF_API_OLD_CHANNEL_LAYOUT + /** Chanel layout needed for old FFMPEG versions */ AVChannelLayout m_out_channel_layout; #endif - + /** The SwrContext that handles resampling */ SwrContext* m_swrctx; + /** The audio context this stream will be played under */ CAudioContext& m_audioContext; + /** If this stream was properly initialized or not */ bool m_initialized; + /** Repeat enabled? */ bool m_repeat; + /** The codec context that contains the original audio format information */ AVCodecContext* m_context = nullptr; + /** The format context that controls how data is read off the file */ AVFormatContext* m_formatContext = nullptr; + /** The stream index for the audio being played */ int m_audioStream = -1; + /** File data pointer */ const void* m_buffer; + /** The length of the file data pointer */ int m_length; + /** The read position on the file data pointer */ int m_position = 0; struct MyAVPacketList { - AVPacket *packet; + AVPacket* packet; }; + /** + * Packet queue information + */ struct PacketQueue { - #if FF_API_FIFO_OLD_API +#if FF_API_FIFO_OLD_API AVFifo* packetList; - #else +#else AVFifoBuffer* packetList; - #endif +#endif int nb_packets; int size; int64_t duration; - SDL_mutex *mutex; - SDL_cond *wait; - SDL_cond *cond; - } *m_queue; + SDL_mutex* mutex; + SDL_cond* wait; + SDL_cond* cond; + }* m_queue; }; } diff --git a/src/WallpaperEngine/Audio/Drivers/CAudioDriver.h b/src/WallpaperEngine/Audio/Drivers/CAudioDriver.h index b24172d..8b1a4c6 100644 --- a/src/WallpaperEngine/Audio/Drivers/CAudioDriver.h +++ b/src/WallpaperEngine/Audio/Drivers/CAudioDriver.h @@ -11,14 +11,32 @@ namespace WallpaperEngine::Audio namespace WallpaperEngine::Audio::Drivers { + /** + * Base class for audio driver implementations + */ class CAudioDriver { public: + /** + * Registers the given stream in the driver for playing + * + * @param stream + */ virtual void addStream (CAudioStream* stream) = 0; - virtual AVSampleFormat getFormat () const = 0; - virtual int getSampleRate () const = 0; - virtual int getChannels () const = 0; - private: + /** + * TODO: MAYBE THIS SHOULD BE OUR OWN DEFINITIONS INSTEAD OF LIBRARY SPECIFIC ONES? + * + * @return The audio format the driver supports + */ + [[nodiscard]] virtual AVSampleFormat getFormat () const = 0; + /** + * @return The sample rate the driver supports + */ + [[nodiscard]] virtual int getSampleRate () const = 0; + /** + * @return The channels the driver supports + */ + [[nodiscard]] virtual int getChannels () const = 0; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp b/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp index b91e087..1535005 100644 --- a/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp +++ b/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp @@ -75,7 +75,7 @@ void audio_callback (void* userdata, uint8_t* streamData, int length) CSDLAudioDriver::CSDLAudioDriver () : m_initialized (false), - m_audioSpec () + m_audioSpec () { if (SDL_InitSubSystem (SDL_INIT_AUDIO) < 0) { @@ -122,6 +122,7 @@ void CSDLAudioDriver::addStream (CAudioStream* stream) { this->m_streams.push_back (new CSDLAudioBuffer { stream }); } + const std::vector & CSDLAudioDriver::getStreams () { return this->m_streams; diff --git a/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.h b/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.h index e2f298a..ac8f8db 100644 --- a/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.h +++ b/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.h @@ -12,31 +12,52 @@ namespace WallpaperEngine::Audio::Drivers { + /** + * Audio output buffers for streams being played under SDL + */ struct CSDLAudioBuffer { CAudioStream* stream; - uint8_t audio_buf[(MAX_AUDIO_FRAME_SIZE * 3) / 2]; + uint8_t audio_buf[(MAX_AUDIO_FRAME_SIZE * 3) / 2] = {0}; unsigned int audio_buf_size = 0; unsigned int audio_buf_index = 0; }; + /** + * SDL's audio driver implementation + */ class CSDLAudioDriver : public CAudioDriver { public: CSDLAudioDriver (); ~CSDLAudioDriver (); + /** @inheritdoc */ void addStream (CAudioStream* stream) override; + /** + * @return All the registered audio streams + */ const std::vector & getStreams (); - AVSampleFormat getFormat () const override; - int getSampleRate () const override; - int getChannels () const override; - const SDL_AudioSpec& getSpec () const; + /** @inheritdoc */ + [[nodiscard]] AVSampleFormat getFormat () const override; + /** @inheritdoc */ + [[nodiscard]] int getSampleRate () const override; + /** @inheritdoc */ + [[nodiscard]] int getChannels () const override; + /** + * @return The SDL's audio driver settings + */ + [[nodiscard]] const SDL_AudioSpec& getSpec () const; + private: + /** The device's ID */ SDL_AudioDeviceID m_deviceID; + /** If the driver is initialized or not */ bool m_initialized; + /** The sound output configuration */ SDL_AudioSpec m_audioSpec; + /** All the playable steams */ std::vector m_streams; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/CProject.cpp b/src/WallpaperEngine/Core/CProject.cpp index 412c2f4..4fc7397 100644 --- a/src/WallpaperEngine/Core/CProject.cpp +++ b/src/WallpaperEngine/Core/CProject.cpp @@ -39,7 +39,7 @@ CProject* CProject::fromFile (const std::string& filename, CContainer* container else sLog.exception ("Unsupported wallpaper type: ", type); - project->setWallpaper (wallpaper); + project->setWallpaper (wallpaper); if (general != content.end ()) { @@ -62,7 +62,7 @@ CProject* CProject::fromFile (const std::string& filename, CContainer* container void CProject::setWallpaper (CWallpaper* wallpaper) { - this->m_wallpaper = wallpaper; + this->m_wallpaper = wallpaper; } CWallpaper* CProject::getWallpaper () const diff --git a/src/WallpaperEngine/Core/CProject.h b/src/WallpaperEngine/Core/CProject.h index 0c024cc..0dda0cf 100644 --- a/src/WallpaperEngine/Core/CProject.h +++ b/src/WallpaperEngine/Core/CProject.h @@ -29,7 +29,7 @@ namespace WallpaperEngine::Core protected: CProject (std::string title, std::string type, CContainer* container); - void setWallpaper (CWallpaper* wallpaper); + void setWallpaper (CWallpaper* wallpaper); void insertProperty (Projects::CProperty* property); private: std::vector m_properties; diff --git a/src/WallpaperEngine/Core/CScene.cpp b/src/WallpaperEngine/Core/CScene.cpp index 6cbcf63..746c8f5 100644 --- a/src/WallpaperEngine/Core/CScene.cpp +++ b/src/WallpaperEngine/Core/CScene.cpp @@ -9,26 +9,26 @@ using namespace WallpaperEngine::Core; CScene::CScene ( - CProject& project, - CContainer* container, - Scenes::CCamera* camera, - glm::vec3 ambientColor, - CUserSettingBoolean* bloom, - CUserSettingFloat* bloomStrength, - CUserSettingFloat* bloomThreshold, - bool cameraFade, - bool cameraParallax, - double cameraParallaxAmount, - double cameraParallaxDelay, - double cameraParallaxMouseInfluence, - bool cameraPreview, - bool cameraShake, - double cameraShakeAmplitude, - double cameraShakeRoughness, - double cameraShakeSpeed, - CUserSettingVector3* clearColor, - Scenes::CProjection* orthogonalProjection, - glm::vec3 skylightColor) : + CProject& project, + CContainer* container, + Scenes::CCamera* camera, + glm::vec3 ambientColor, + CUserSettingBoolean* bloom, + CUserSettingFloat* bloomStrength, + CUserSettingFloat* bloomThreshold, + bool cameraFade, + bool cameraParallax, + double cameraParallaxAmount, + double cameraParallaxDelay, + double cameraParallaxMouseInfluence, + bool cameraPreview, + bool cameraShake, + double cameraShakeAmplitude, + double cameraShakeRoughness, + double cameraShakeSpeed, + CUserSettingVector3* clearColor, + Scenes::CProjection* orthogonalProjection, + glm::vec3 skylightColor) : CWallpaper (Type, project), m_container (container), m_camera (camera), @@ -81,26 +81,26 @@ CScene* CScene::fromFile (const std::string& filename, CProject& project, CConta auto skylightcolor = jsonFindDefault (*general_it, "skylightcolor", "0 0 0"); CScene* scene = new CScene ( - project, - container, - Scenes::CCamera::fromJSON (*camera_it), - WallpaperEngine::Core::aToColorf(ambientcolor), - bloom, - bloomstrength, - bloomthreshold, - camerafade, - cameraparallax, - cameraparallaxamount, - cameraparallaxdelay, - cameraparallaxmouseinfluence, - camerapreview, - camerashake, - camerashakeamplitude, - camerashakeroughness, - camerashakespeed, - clearcolor, - Scenes::CProjection::fromJSON (*orthogonalprojection_it), - WallpaperEngine::Core::aToColorf(skylightcolor) + project, + container, + Scenes::CCamera::fromJSON (*camera_it), + WallpaperEngine::Core::aToColorf(ambientcolor), + bloom, + bloomstrength, + bloomthreshold, + camerafade, + cameraparallax, + cameraparallaxamount, + cameraparallaxdelay, + cameraparallaxmouseinfluence, + camerapreview, + camerashake, + camerashakeamplitude, + camerashakeroughness, + camerashakespeed, + clearcolor, + Scenes::CProjection::fromJSON (*orthogonalprojection_it), + WallpaperEngine::Core::aToColorf(skylightcolor) ); for (const auto& cur : *objects_it) diff --git a/src/WallpaperEngine/Core/CScene.h b/src/WallpaperEngine/Core/CScene.h index d327d7f..89a191d 100644 --- a/src/WallpaperEngine/Core/CScene.h +++ b/src/WallpaperEngine/Core/CScene.h @@ -45,26 +45,26 @@ namespace WallpaperEngine::Core friend class CWallpaper; CScene ( - CProject& project, - CContainer* container, - Scenes::CCamera* camera, - glm::vec3 ambientColor, - CUserSettingBoolean* bloom, - CUserSettingFloat* bloomStrength, - CUserSettingFloat* bloomThreshold, - bool cameraFade, - bool cameraParallax, - double cameraParallaxAmount, - double cameraParallaxDelay, - double cameraParallaxMouseInfluence, - bool cameraPreview, - bool cameraShake, - double cameraShakeAmplitude, - double cameraShakeRoughness, - double cameraShakeSpeed, - CUserSettingVector3* clearColor, - Scenes::CProjection* orthogonalProjection, - glm::vec3 skylightColor + CProject& project, + CContainer* container, + Scenes::CCamera* camera, + glm::vec3 ambientColor, + CUserSettingBoolean* bloom, + CUserSettingFloat* bloomStrength, + CUserSettingFloat* bloomThreshold, + bool cameraFade, + bool cameraParallax, + double cameraParallaxAmount, + double cameraParallaxDelay, + double cameraParallaxMouseInfluence, + bool cameraPreview, + bool cameraShake, + double cameraShakeAmplitude, + double cameraShakeRoughness, + double cameraShakeSpeed, + CUserSettingVector3* clearColor, + Scenes::CProjection* orthogonalProjection, + glm::vec3 skylightColor ); static const std::string Type; diff --git a/src/WallpaperEngine/Core/CVideo.cpp b/src/WallpaperEngine/Core/CVideo.cpp index 493faeb..9049d46 100644 --- a/src/WallpaperEngine/Core/CVideo.cpp +++ b/src/WallpaperEngine/Core/CVideo.cpp @@ -5,8 +5,8 @@ using namespace WallpaperEngine::Core; CVideo::CVideo (std::string filename, CProject& project) : - CWallpaper (Type, project), - m_filename (std::move(filename)) + CWallpaper (Type, project), + m_filename (std::move(filename)) { } diff --git a/src/WallpaperEngine/Core/CVideo.h b/src/WallpaperEngine/Core/CVideo.h index 2f7cae4..debe3bd 100644 --- a/src/WallpaperEngine/Core/CVideo.h +++ b/src/WallpaperEngine/Core/CVideo.h @@ -5,10 +5,10 @@ extern "C" { - #include - #include - #include - #include +#include +#include +#include +#include } namespace WallpaperEngine::Core diff --git a/src/WallpaperEngine/Core/CWallpaper.cpp b/src/WallpaperEngine/Core/CWallpaper.cpp index 42aaa79..a162f19 100644 --- a/src/WallpaperEngine/Core/CWallpaper.cpp +++ b/src/WallpaperEngine/Core/CWallpaper.cpp @@ -6,7 +6,7 @@ using namespace WallpaperEngine::Core; CWallpaper::CWallpaper (std::string type, CProject& project) : m_type (std::move(type)), - m_project (project) + m_project (project) { } diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index 4cb2530..9835091 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -21,12 +21,12 @@ using namespace WallpaperEngine::Core::Objects; using namespace WallpaperEngine::Core::UserSettings; CEffect::CEffect ( - std::string name, - std::string description, - std::string group, - std::string preview, - Core::CObject* object, - CUserSettingBoolean* visible): + std::string name, + std::string description, + std::string group, + std::string preview, + CObject* object, + CUserSettingBoolean* visible): m_name (std::move(name)), m_description (std::move(description)), m_group (std::move(group)), @@ -36,7 +36,7 @@ CEffect::CEffect ( { } -CEffect* CEffect::fromJSON (json data, CUserSettingBoolean* visible, Core::CObject* object, CContainer* container) +CEffect* CEffect::fromJSON (json data, CUserSettingBoolean* visible, CObject* object, CContainer* container) { auto file_it = jsonFindRequired (data, "file", "Object effect must have a file"); auto effectpasses_it = data.find ("passes"); diff --git a/src/WallpaperEngine/Core/Objects/CEffect.h b/src/WallpaperEngine/Core/Objects/CEffect.h index 6d67ae6..9decf01 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.h +++ b/src/WallpaperEngine/Core/Objects/CEffect.h @@ -23,6 +23,9 @@ namespace WallpaperEngine::Core::Objects using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Core::UserSettings; + /** + * Represents an effect applied to background objects + */ class CEffect { public: @@ -31,17 +34,35 @@ namespace WallpaperEngine::Core::Objects std::string description, std::string group, std::string preview, - Core::CObject* object, + CObject* object, CUserSettingBoolean* visible ); - static CEffect* fromJSON (json data, CUserSettingBoolean* visible, Core::CObject* object, CContainer* container); - - const std::vector& getDependencies () const; - const std::vector& getMaterials () const; - const std::vector& getFbos () const; - bool isVisible () const; + static CEffect* fromJSON (json data, UserSettings::CUserSettingBoolean* visible, CObject* object, CContainer* container); + /** + * @return List of dependencies for the effect to work + */ + [[nodiscard]] const std::vector& getDependencies () const; + /** + * @return List of materials the effect applies + */ + [[nodiscard]] const std::vector& getMaterials () const; + /** + * @return The list of FBOs to be used for this effect + */ + [[nodiscard]] const std::vector& getFbos () const; + /** + * @return If the effect is visible or not + */ + [[nodiscard]] bool isVisible () const; + /** + * Searches the FBOs list for the given FBO + * + * @param name The FBO to search for + * + * @return + */ Effects::CFBO* findFBO (const std::string& name); protected: static void constantsFromJSON (json::const_iterator constants_it, Core::Objects::Images::Materials::CPass* pass); @@ -55,15 +76,24 @@ namespace WallpaperEngine::Core::Objects void insertFBO (Effects::CFBO* fbo); private: + /** Effect's name */ std::string m_name; + /** Effect's description used in the UI */ std::string m_description; + /** Effect's group used in the UI */ std::string m_group; + /** A project that previews the given effect, used in the UI */ std::string m_preview; - Core::CObject* m_object; - CUserSettingBoolean* m_visible; + /** The object the effect applies to */ + CObject* m_object; + /** If the effect is visible or not */ + UserSettings::CUserSettingBoolean* m_visible; + /** List of dependencies for the effect */ std::vector m_dependencies; + /** List of materials the effect applies */ std::vector m_materials; + /** List of FBOs required for this effect */ std::vector m_fbos; }; } diff --git a/src/WallpaperEngine/Core/Objects/CImage.cpp b/src/WallpaperEngine/Core/Objects/CImage.cpp index dc50ea9..5155bd1 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.cpp +++ b/src/WallpaperEngine/Core/Objects/CImage.cpp @@ -23,7 +23,7 @@ CImage::CImage ( const glm::vec3& angles, const glm::vec2& size, std::string alignment, - CUserSettingVector3* color, + CUserSettingVector3* color, CUserSettingFloat* alpha, float brightness, uint32_t colorBlendMode, diff --git a/src/WallpaperEngine/Core/Objects/CImage.h b/src/WallpaperEngine/Core/Objects/CImage.h index 4c775a5..f35f8a5 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.h +++ b/src/WallpaperEngine/Core/Objects/CImage.h @@ -22,60 +22,80 @@ namespace WallpaperEngine::Core::Objects using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Core::UserSettings; + /** + * Represents an image in a background + */ class CImage : public CObject { friend class CObject; public: static CObject* fromJSON ( - CScene* scene, - json data, - CContainer* container, - CUserSettingBoolean* visible, - uint32_t id, - std::string name, - CUserSettingVector3* origin, - CUserSettingVector3* scale, - const glm::vec3& angles + CScene* scene, json data, CContainer* container, CUserSettingBoolean* visible, uint32_t id, + std::string name, CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles ); - const Images::CMaterial* getMaterial () const; - const glm::vec2& getSize () const; - const std::string& getAlignment () const; - float getAlpha () const; - glm::vec3 getColor () const; - float getBrightness () const; - uint32_t getColorBlendMode () const; - const glm::vec2& getParallaxDepth () const; + /** + * @return The base material to use for the image + */ + [[nodiscard]] const Images::CMaterial* getMaterial () const; + /** + * @return The size of the image + */ + [[nodiscard]] const glm::vec2& getSize () const; + /** + * @return The type of alignment to use for image positioning + */ + [[nodiscard]] const std::string& getAlignment () const; + /** + * @return The alpha value for the image's rendering + */ + [[nodiscard]] float getAlpha () const; + /** + * @return The color to use for the image + */ + [[nodiscard]] glm::vec3 getColor () const; + /** + * @return The brightness to use for the image + */ + [[nodiscard]] float getBrightness () const; + /** + * @return The color blending mode to be used, special value for shaders + */ + [[nodiscard]] uint32_t getColorBlendMode () const; + /** + * @return Parallax depth of the image + */ + [[nodiscard]] const glm::vec2& getParallaxDepth () const; protected: CImage ( - CScene* scene, - Images::CMaterial* material, - CUserSettingBoolean* visible, - uint32_t id, - std::string name, - CUserSettingVector3* origin, - CUserSettingVector3* scale, - const glm::vec3& angles, - const glm::vec2& size, - std::string alignment, - CUserSettingVector3* color, - CUserSettingFloat* alpha, - float brightness, - uint32_t colorBlendMode, - const glm::vec2& parallaxDepth + CScene* scene, Images::CMaterial* material, CUserSettingBoolean* visible, uint32_t id, std::string name, + CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles, const glm::vec2& size, + std::string alignment, CUserSettingVector3* color, CUserSettingFloat* alpha, float brightness, + uint32_t colorBlendMode, const glm::vec2& parallaxDepth ); + /** + * Type value used to differentiate the different types of objects in a background + */ static const std::string Type; private: + /** The image's size */ glm::vec2 m_size; + /** Parallax depth */ const glm::vec2 m_parallaxDepth; + /** Base material for the image */ Images::CMaterial* m_material; + /** What type of alignment to use for the image's position */ std::string m_alignment; + /** The alpha value for the image */ CUserSettingFloat* m_alpha; + /** The brightness for the image */ float m_brightness; + /** The color to use for the image */ CUserSettingVector3* m_color; + /** The color blending mode used for the image, special value for shaders */ uint32_t m_colorBlendMode; }; } diff --git a/src/WallpaperEngine/Core/Objects/CParticle.cpp b/src/WallpaperEngine/Core/Objects/CParticle.cpp index 61e1303..dec4c17 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.cpp +++ b/src/WallpaperEngine/Core/Objects/CParticle.cpp @@ -46,17 +46,17 @@ CParticle* CParticle::fromFile ( } CParticle::CParticle ( - CScene* scene, - uint32_t starttime, - uint32_t maxcount, - CUserSettingBoolean* visible, - uint32_t id, - std::string name, - CUserSettingVector3* origin, - CUserSettingVector3* scale): - CObject (scene, visible, id, std::move(name), Type, origin, scale, glm::vec3 ()), - m_starttime (starttime), - m_maxcount (maxcount) + CScene* scene, + uint32_t starttime, + uint32_t maxcount, + CUserSettingBoolean* visible, + uint32_t id, + std::string name, + CUserSettingVector3* origin, + CUserSettingVector3* scale): + CObject (scene, visible, id, std::move(name), Type, origin, scale, glm::vec3 ()), + m_starttime (starttime), + m_maxcount (maxcount) { } diff --git a/src/WallpaperEngine/Core/Objects/CParticle.h b/src/WallpaperEngine/Core/Objects/CParticle.h index ebb4c5e..5a0b10b 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.h +++ b/src/WallpaperEngine/Core/Objects/CParticle.h @@ -11,25 +11,37 @@ namespace WallpaperEngine::Core::Objects { using json = nlohmann::json; + /** + * Represents a particle system in the background + */ class CParticle : public CObject { friend class CObject; public: static CParticle* fromFile ( - CScene* scene, - const std::string& filename, - CContainer* container, - CUserSettingBoolean* visible, - uint32_t id, - std::string name, - CUserSettingVector3* origin, - CUserSettingVector3* scale + CScene* scene, + const std::string& filename, + CContainer* container, + CUserSettingBoolean* visible, + uint32_t id, + std::string name, + CUserSettingVector3* origin, + CUserSettingVector3* scale ); - const std::vector& getEmitters () const; - const std::vector& getControlPoints () const; - const std::vector& getInitializers () const; + /** + * @return The list of emitters for the particle system + */ + [[nodiscard]] const std::vector& getEmitters () const; + /** + * @return The list of control points for the particle system + */ + [[nodiscard]] const std::vector& getControlPoints () const; + /** + * @return The list of initializers for the particle system + */ + [[nodiscard]] const std::vector& getInitializers () const; protected: CParticle ( @@ -42,16 +54,35 @@ namespace WallpaperEngine::Core::Objects CUserSettingVector3* origin, CUserSettingVector3* scale ); + + /** + * @param controlpoint The control point to add to the particle system + */ void insertControlPoint (Particles::CControlPoint* controlpoint); + /** + * @param emitter The emitter to add to the particle system + */ void insertEmitter (Particles::CEmitter* emitter); + /** + * @param initializer The initializer to add to the particle system + */ void insertInitializer (Particles::CInitializer* initializer); + /** + * Type value used to differentiate the different types of objects in a background + */ static const std::string Type; + private: + /** The time at which the particle system should start emitting */ uint32_t m_starttime; + /** Maximum number of particles at the same time */ uint32_t m_maxcount; + /** List of control points */ std::vector m_controlpoints; + /** List of emitters */ std::vector m_emitters; + /** List of initializers */ std::vector m_initializers; }; } diff --git a/src/WallpaperEngine/Core/Objects/CSound.cpp b/src/WallpaperEngine/Core/Objects/CSound.cpp index 7a3bdaf..e22dd65 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.cpp +++ b/src/WallpaperEngine/Core/Objects/CSound.cpp @@ -20,14 +20,14 @@ CSound::CSound ( } WallpaperEngine::Core::CObject* CSound::fromJSON ( - CScene* scene, - json data, - CUserSettingBoolean* visible, - uint32_t id, - const std::string& name, - CUserSettingVector3* origin, - CUserSettingVector3* scale, - const glm::vec3& angles) + CScene* scene, + json data, + CUserSettingBoolean* visible, + uint32_t id, + const std::string& name, + CUserSettingVector3* origin, + CUserSettingVector3* scale, + const glm::vec3& angles) { bool repeat = false; // TODO: PARSE AUDIO VOLUME diff --git a/src/WallpaperEngine/Core/Objects/CSound.h b/src/WallpaperEngine/Core/Objects/CSound.h index cade9e9..096ec2a 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.h +++ b/src/WallpaperEngine/Core/Objects/CSound.h @@ -9,6 +9,9 @@ namespace WallpaperEngine::Core::Objects using json = nlohmann::json; using namespace WallpaperEngine::Core::UserSettings; + /** + * Represents a sound played while the background is working + */ class CSound : public CObject { friend class CObject; @@ -25,9 +28,14 @@ namespace WallpaperEngine::Core::Objects const glm::vec3& angles ); - void insertSound (const std::string& filename); - const std::vector& getSounds () const; - bool isRepeat () const; + /** + * @return The list of sounds to play + */ + [[nodiscard]] const std::vector& getSounds () const; + /** + * @return If the sound should repeat or not + */ + [[nodiscard]] bool isRepeat () const; protected: CSound ( @@ -41,9 +49,20 @@ namespace WallpaperEngine::Core::Objects bool repeat ); + /** + * @param filename The sound to add + */ + void insertSound (const std::string& filename); + + /** + * Type value used to differentiate the different types of objects in a background + */ static const std::string Type; + private: + /** If the sounds should repeat or not */ bool m_repeat; + /** The list of sounds to play */ std::vector m_sounds; }; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/CBind.h b/src/WallpaperEngine/Core/Objects/Effects/CBind.h index 280e3d8..0bb2995 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CBind.h +++ b/src/WallpaperEngine/Core/Objects/Effects/CBind.h @@ -8,18 +8,37 @@ namespace WallpaperEngine::Core::Objects::Effects { using json = nlohmann::json; + /** + * Material's bind information, describes for passes what textures to bind + * in what positions for shaders. Used to override the textures specified inside + * the object's passes + */ class CBind { public: + /** + * Parses bind information off the given json data + * + * @param data + * @return + */ static CBind* fromJSON (json data); CBind (std::string name, uint32_t index); - const std::string& getName () const; - const uint32_t& getIndex () const; + /** + * @return The texture name, previous to use the one already specified by the object's passes + */ + [[nodiscard]] const std::string& getName () const; + /** + * @return The texture index to replace + */ + [[nodiscard]] const uint32_t& getIndex () const; private: + /** The texture's name */ std::string m_name; + /** The texture index to replace */ uint32_t m_index; }; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/CFBO.h b/src/WallpaperEngine/Core/Objects/Effects/CFBO.h index f3e84c0..bba9ce4 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CFBO.h +++ b/src/WallpaperEngine/Core/Objects/Effects/CFBO.h @@ -1,14 +1,19 @@ #pragma once -#include - #include "WallpaperEngine/Core/Core.h" + #include +#include namespace WallpaperEngine::Core::Objects::Effects { using json = nlohmann::json; + /** + * FBO = Frame Buffer Object + * + * Represents a framebuffer object used in objects with multiple effects or render passes + */ class CFBO { public: @@ -16,13 +21,25 @@ namespace WallpaperEngine::Core::Objects::Effects static CFBO* fromJSON (json data); - const std::string& getName () const; - const float& getScale () const; - const std::string& getFormat () const; + /** + * @return The FBO name used to identify it in the background's files + */ + [[nodiscard]] const std::string& getName () const; + /** + * @return The scale factor of the FBO + */ + [[nodiscard]] const float& getScale () const; + /** + * @return The FBO's format for the render + */ + [[nodiscard]] const std::string& getFormat () const; private: + /** The name of the FBO */ std::string m_name; + /** The scale factor of the FBO */ float m_scale; + /** The FBO's format for the render */ std::string m_format; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h index 781e2a5..f773035 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h @@ -4,6 +4,9 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants { + /** + * Shader constants base class + */ class CShaderConstant { public: @@ -13,7 +16,11 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants template T* as () { assert (is ()); return (T*) this; } template bool is () { return this->m_type == T::Type; } - const std::string& getType () const; + + /** + * @return The type name of this constant + */ + [[nodiscard]] const std::string& getType () const; private: std::string m_type; diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp index aec7fba..2ba0687 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp @@ -2,7 +2,6 @@ using namespace WallpaperEngine::Core::Objects::Effects::Constants; - CShaderConstantFloat::CShaderConstantFloat (float value) : CShaderConstant (Type), m_value (value) diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h index 2d3aaba..03a8c5a 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h @@ -6,15 +6,25 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants { + /** + * Shader constant of type float + */ class CShaderConstantFloat : public CShaderConstant { public: explicit CShaderConstantFloat (float value); + /** + * @return A pointer to the actual value of the constant + */ float* getValue (); + /** + * Type string indicator + */ static const std::string Type; protected: + /** The constant's value */ float m_value; }; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp index 7769a34..24f5d02 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp @@ -2,7 +2,6 @@ using namespace WallpaperEngine::Core::Objects::Effects::Constants; - CShaderConstantInteger::CShaderConstantInteger (int32_t value) : CShaderConstant (Type), m_value (value) diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h index a0904fd..e72caeb 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h @@ -6,15 +6,25 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants { + /** + * Shader constant of type integer + */ class CShaderConstantInteger : public CShaderConstant { public: explicit CShaderConstantInteger (int32_t value); + /** + * @return A pointer to the actual value of the constant + */ int32_t* getValue (); + /** + * Type string indicator + */ static const std::string Type; protected: + /** The constant's value */ int32_t m_value; }; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h index 7848345..937de5d 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h @@ -8,15 +8,25 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants { + /** + * Shader constant of vector2 type + */ class CShaderConstantVector2 : public CShaderConstant { public: explicit CShaderConstantVector2 (glm::vec2 value); + /** + * @return A pointer to the actual value of the constant + */ glm::vec2* getValue (); + /** + * Type string indicator + */ static const std::string Type; protected: + /** The constant's value */ glm::vec2 m_value; }; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h index b06ab2b..9e7a40c 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h @@ -7,15 +7,25 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants { + /** + * Shader constant of vector3 type + */ class CShaderConstantVector3 : public CShaderConstant { public: explicit CShaderConstantVector3 (glm::vec3 value); + /** + * @return A pointer to the actual value of the constant + */ glm::vec3* getValue (); + /** + * Type string indicator + */ static const std::string Type; protected: + /** The constant's value */ glm::vec3 m_value; }; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.h index c080127..9ef0b5b 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.h @@ -7,15 +7,25 @@ namespace WallpaperEngine::Core::Objects::Effects::Constants { + /** + * Shader constant of vector4 type + */ class CShaderConstantVector4 : public CShaderConstant { public: - CShaderConstantVector4 (glm::vec4 value); + explicit CShaderConstantVector4 (glm::vec4 value); + /** + * @return A pointer to the actual value of the constant + */ glm::vec4* getValue (); + /** + * Type string indicator + */ static const std::string Type; protected: + /** The constant's value */ glm::vec4 m_value; }; } diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h index 5d2cc67..7a1b827 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h @@ -11,30 +11,64 @@ namespace WallpaperEngine::Core::Objects::Images using json = nlohmann::json; using namespace WallpaperEngine::Assets; + /** + * Represents a material in use in the background + */ class CMaterial { public: - static CMaterial* fromFile (const std::string& filename, CContainer* container); + static CMaterial* fromFile (const std::string& filename, Assets::CContainer* container); static CMaterial* fromJSON (const std::string& name, json data); - static CMaterial* fromFile (const std::string& filename, const std::string& target, CContainer* container); + static CMaterial* fromFile (const std::string& filename, const std::string& target, Assets::CContainer* container); static CMaterial* fromJSON (const std::string& name, json data, const std::string& target); - void insertPass (Materials::CPass* mass); + /** + * @param pass The rendering pass to add to the material + */ + void insertPass (Materials::CPass* pass); + /** + * @param bind Texture bind override for the material + */ void insertTextureBind (Effects::CBind* bind); - const std::vector & getPasses () const; - const std::map & getTextureBinds () const; - const std::string& getTarget () const; - bool hasTarget () const; - const std::string& getName () const; + /** + * @return All the rendering passes that happen for this material + */ + [[nodiscard]] const std::vector & getPasses () const; + /** + * @return The textures that have to be bound while rendering the material. + * These act as an override of the textures specified by the parent effect + */ + [[nodiscard]] const std::map & getTextureBinds () const; + /** + * @return The materials destination (fbo) if required + */ + [[nodiscard]] const std::string& getTarget () const; + /** + * @return Indicates if this material has a specific destination (fbo) while rendering + */ + [[nodiscard]] bool hasTarget () const; + /** + * @return The name of the material + */ + [[nodiscard]] const std::string& getName () const; + protected: explicit CMaterial (std::string name); + /** + * @param target The new target while rendering this material + */ void setTarget (const std::string& target); + private: + /** All the shader passes required to render this material */ std::vector m_passes; + /** List of texture bind overrides to use for this material */ std::map m_textureBindings; + /** The FBO target to render to (if any) */ std::string m_target; + /** The material's name */ std::string m_name; }; } diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp index 3af142f..368b0ab 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp @@ -43,7 +43,7 @@ CPass* CPass::fromJSON (json data) if (textures_it != data.end ()) for (const auto& cur : (*textures_it)) - pass->insertTexture (cur.is_null () ? "" : cur); + pass->insertTexture (cur.is_null () ? "" : cur); if (combos_it != data.end ()) { diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h index b785bbc..d28e5e4 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h @@ -13,40 +13,101 @@ namespace WallpaperEngine::Core::Objects::Images::Materials { using json = nlohmann::json; + /** + * Represents a shader pass of an object + */ class CPass { - friend class Core::Objects::CEffect; + friend class WallpaperEngine::Core::Objects::CEffect; public: static CPass* fromJSON (json data); - const std::vector& getTextures () const; - const std::map& getConstants () const; - - std::map* getCombos (); - const std::string& getShader () const; - const std::string& getBlendingMode () const; - const std::string& getCullingMode () const; - const std::string& getDepthTest () const; - const std::string& getDepthWrite () const; + /** + * @return The list of textures to bind while rendering + */ + [[nodiscard]] const std::vector& getTextures () const; + /** + * @return Shader constants that alter how the shader should behave + */ + [[nodiscard]] const std::map& getConstants () const; + /** + * @return Shader combos that alter how the shader should behave + */ + [[nodiscard]] std::map* getCombos (); + /** + * @return Shader to be used while rendering the pass + */ + [[nodiscard]] const std::string& getShader () const; + /** + * @return The blending mode to use while rendering + */ + [[nodiscard]] const std::string& getBlendingMode () const; + /** + * @return The culling mode to use while rendering + */ + [[nodiscard]] const std::string& getCullingMode () const; + /** + * @return If depth testing has to happen while rendering + */ + [[nodiscard]] const std::string& getDepthTest () const; + /** + * @return If depth write has to happen while rendering + */ + [[nodiscard]] const std::string& getDepthWrite () const; + /** + * @param mode The new blending mode to use + */ void setBlendingMode (const std::string& mode); + /** + * Add a shader combo value to the list + * + * @param name The combo name + * @param value It's value + */ void insertCombo (const std::string& name, int value); + /** + * Adds a shader constant to the list + * + * @param name The constant's name + * @param constant It's value + */ void insertConstant (const std::string& name, Effects::Constants::CShaderConstant* constant); protected: CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, std::string shader); + /** + * Adds a new texture to the list of textures to bind while rendering + * + * @param texture + */ void insertTexture (const std::string& texture); + /** + * Updates a texture in the specified index for binding while rendering + * + * @param index + * @param texture + */ void setTexture (int index, const std::string& texture); private: + // TODO: CREATE ENUMERATIONS FOR THESE INSTEAD OF USING STRING VALUES! + /** The blending mode to use */ std::string m_blending; + /** The culling mode to use */ std::string m_cullmode; + /** If depthtesting has to happen while drawing */ std::string m_depthtest; + /** If depthwrite has to happen while drawing */ std::string m_depthwrite; + /** The shader to use */ std::string m_shader; + /** The list of textures to use */ std::vector m_textures; + /** Different combo settings for shader input */ std::map m_combos; + /** Shader constant values to use for the shaders */ std::map m_constants; }; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp index ef878d3..29d8f66 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp @@ -37,7 +37,7 @@ void CControlPoint::setFlags (uint32_t flags) } uint32_t CControlPoint::getId () const { - return this->m_id; + return this->m_id; } const glm::vec3& CControlPoint::getOffset () const diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h index 2385ff5..9ff961b 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h @@ -6,22 +6,45 @@ namespace WallpaperEngine::Core::Objects::Particles { using json = nlohmann::json; + /** + * Control point for particles + */ class CControlPoint { public: static CControlPoint* fromJSON (json data); - uint32_t getId () const; - const glm::vec3& getOffset () const; - uint32_t getFlags () const; + /** + * @return The id of the controlpoint used for ordering purposes + */ + [[nodiscard]] uint32_t getId () const; + /** + * @return The offset from origin + */ + [[nodiscard]] const glm::vec3& getOffset () const; + /** + * @return Flags for the control point, controls how it should behave + */ + [[nodiscard]] uint32_t getFlags () const; + protected: explicit CControlPoint (uint32_t id, uint32_t flags = 0); + /** + * @param offset The new offset + */ void setOffset (const glm::vec3& offset); + /** + * @param flags The new flags + */ void setFlags (uint32_t flags); + private: + /** ID used for ordering purposes */ uint32_t m_id; + /** Flags that control how it behaves */ uint32_t m_flags; + /** The offset from starting position */ glm::vec3 m_offset; }; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp index fbcca5c..37f8844 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp @@ -13,24 +13,24 @@ CEmitter* CEmitter::fromJSON (json data) auto rate_it = jsonFindRequired (data, "rate", "Particle emitter must have a rate"); return new CEmitter ( - WallpaperEngine::Core::aToVector3 (*directions_it), - *distancemax_it, - *distancemin_it, - (id_it == data.end () ? 0 : (uint32_t) (*id_it)), - *name_it, - WallpaperEngine::Core::aToVector3 (*origin_it), - *rate_it + WallpaperEngine::Core::aToVector3 (*directions_it), + *distancemax_it, + *distancemin_it, + (id_it == data.end () ? 0 : (uint32_t) (*id_it)), + *name_it, + WallpaperEngine::Core::aToVector3 (*origin_it), + *rate_it ); } CEmitter::CEmitter ( - const glm::vec3& directions, - uint32_t distancemax, - uint32_t distancemin, - uint32_t id, - std::string name, - const glm::vec3& origin, - double rate): + const glm::vec3& directions, + uint32_t distancemax, + uint32_t distancemin, + uint32_t id, + std::string name, + const glm::vec3& origin, + double rate): m_directions (directions), m_distancemax (distancemax), m_distancemin (distancemin), @@ -43,7 +43,7 @@ CEmitter::CEmitter ( uint32_t CEmitter::getId () const { - return this->m_id; + return this->m_id; } const std::string& CEmitter::getName () const diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h index 5e5cc21..d6a6f0f 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h @@ -6,35 +6,63 @@ namespace WallpaperEngine::Core::Objects::Particles { using json = nlohmann::json; + /** + * Particle emitter, controls the area where the particles have to be created + */ class CEmitter { public: static CEmitter* fromJSON (json data); - uint32_t getId () const; - const std::string& getName () const; - const uint32_t getDistanceMax () const; - const uint32_t getDistanceMin () const; - const glm::vec3& getDirections () const; - const glm::vec3& getOrigin () const; - const double getRate () const; + /** + * @return The ID of the emitter + */ + [[nodiscard]] uint32_t getId () const; + /** + * @return The name of the emitter, indicates what type of emission to do + */ + [[nodiscard]] const std::string& getName () const; + /** + * @return The maximum distance a particle can travel before being dead + */ + [[nodiscard]] const uint32_t getDistanceMax () const; + /** + * @return The minimum distance a particle can travel before being dead + */ + [[nodiscard]] const uint32_t getDistanceMin () const; + /** + * @return The direction a particle should move to + */ + [[nodiscard]] const glm::vec3& getDirections () const; + /** + * @return The center of the particle emission + */ + [[nodiscard]] const glm::vec3& getOrigin () const; + /** + * @return The rate of particle emission + */ + [[nodiscard]] const double getRate () const; + protected: CEmitter ( - const glm::vec3& directions, - uint32_t distancemax, - uint32_t distancemin, - uint32_t id, - std::string name, - const glm::vec3& origin, - double rate + const glm::vec3& directions, uint32_t distancemax, uint32_t distancemin, uint32_t id, std::string name, + const glm::vec3& origin, double rate ); + private: + /** Direction the particles should move to */ glm::vec3 m_directions; + /** Maximum distance before the particle is dead */ uint32_t m_distancemax; + /** Minimum distance before the particle is dead */ uint32_t m_distancemin; + /** ID of the emitter */ uint32_t m_id; + /** Name of the emitter, indicates the type of emitter */ std::string m_name; + /** The center of the emitter */ glm::vec3 m_origin; + /** The rate of emission */ double m_rate; }; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h index f049a39..c76d728 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h @@ -6,17 +6,31 @@ namespace WallpaperEngine::Core::Objects::Particles { using json = nlohmann::json; + /** + * Initializer for particles, controls the different attributes a particle will have + * on emission + */ class CInitializer { public: static CInitializer* fromJSON (json data); - const std::string& getName () const; - uint32_t getId () const; + /** + * @return The name of the particle initializer, indicates what type of initialization to do + */ + [[nodiscard]] const std::string& getName () const; + /** + * @return The id of the initializer + */ + [[nodiscard]] uint32_t getId () const; + protected: CInitializer (uint32_t id, std::string name); + private: + /** ID for ordering purposes */ uint32_t m_id; + /** The name of the initializer, indicates what type of initialization to do */ std::string m_name; }; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h index f51cc80..c8169ae 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h @@ -1,24 +1,36 @@ #pragma once -#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" - #include "WallpaperEngine/Core/Core.h" +#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" namespace WallpaperEngine::Core::Objects::Particles::Initializers { - class CAlphaRandom : CInitializer - { - public: - double getMinimum () const; - double getMaximum () const; - protected: - friend class CInitializer; + /** + * Initializer for particles that decides the base alpha for the particles + */ + class CAlphaRandom : CInitializer + { + public: + /** + * @return The minimum alpha value to be used + */ + [[nodiscard]] double getMinimum () const; + /** + * @return The maximum alpha value to be used + */ + [[nodiscard]] double getMaximum () const; - static CAlphaRandom* fromJSON (json data, uint32_t id); + protected: + friend class CInitializer; - CAlphaRandom (uint32_t id, double min, double max); - private: - double m_max; - double m_min; - }; + static CAlphaRandom* fromJSON (json data, uint32_t id); + + CAlphaRandom (uint32_t id, double min, double max); + + private: + /** Maximum alpha */ + double m_max; + /** Minimum alpha */ + double m_min; + }; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h index 762298b..ef45cb2 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h @@ -1,24 +1,36 @@ #pragma once -#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" - #include "WallpaperEngine/Core/Core.h" +#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" namespace WallpaperEngine::Core::Objects::Particles::Initializers { - class CAngularVelocityRandom : CInitializer - { - public: - const glm::vec3& getMinimum () const; - const glm::vec3& getMaximum () const; - protected: - friend class CInitializer; + /** + * Initializer for particles that decides the base angular velocity for particles + */ + class CAngularVelocityRandom : CInitializer + { + public: + /** + * @return Minimum angular velocity (direction * speed) + */ + [[nodiscard]] const glm::vec3& getMinimum () const; + /** + * @return Maximum angular velocity (direction * speed) + */ + [[nodiscard]] const glm::vec3& getMaximum () const; - static CAngularVelocityRandom* fromJSON (json data, uint32_t id); + protected: + friend class CInitializer; - CAngularVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max); - private: - glm::vec3 m_max; - glm::vec3 m_min; - }; + static CAngularVelocityRandom* fromJSON (json data, uint32_t id); + + CAngularVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max); + + private: + /** Maximum velocity (direction * speed) */ + glm::vec3 m_max; + /** Minimum velocity (direction * speed) */ + glm::vec3 m_min; + }; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h index a8a22a8..338994b 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h @@ -6,19 +6,32 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers { + /** + * Initializer for particles that decides the base color + */ class CColorRandom : CInitializer { public: - const glm::ivec3& getMinimum () const; - const glm::ivec3& getMaximum () const; + /** + * @return The minimum color to use (RGB) + */ + [[nodiscard]] const glm::ivec3& getMinimum () const; + /** + * @return The maximum color to use (RGB) + */ + [[nodiscard]] const glm::ivec3& getMaximum () const; + protected: friend class CInitializer; static CColorRandom* fromJSON (json data, uint32_t id); CColorRandom (uint32_t id, glm::ivec3 min, glm::ivec3 max); + private: + /** Maximum color */ glm::ivec3 m_max; + /** Minimum color */ glm::ivec3 m_min; }; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp index 3cd8816..fa7b5b9 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp @@ -12,9 +12,9 @@ CLifeTimeRandom* CLifeTimeRandom::fromJSON (json data, uint32_t id) CLifeTimeRandom::CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max) : - CInitializer (id, "lifetimerandom"), - m_min (min), - m_max (max) + CInitializer (id, "lifetimerandom"), + m_min (min), + m_max (max) { } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h index 35b1b64..2db0a7e 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h @@ -6,19 +6,31 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers { + /** + * Initializer for particles that decides the lifetime of each particle on startup + */ class CLifeTimeRandom : CInitializer { public: - uint32_t getMinimum () const; - uint32_t getMaximum () const; + /** + * @return The minimum lifetime to be used + */ + [[nodiscard]] uint32_t getMinimum () const; + /** + * @return The maximum lifetime to be used + */ + [[nodiscard]] uint32_t getMaximum () const; protected: friend class CInitializer; static CLifeTimeRandom* fromJSON (json data, uint32_t id); CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max); + private: + /** Maximum lifetime */ uint32_t m_max; + /** Minimum lifetime */ uint32_t m_min; }; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp index 3c6af87..8baa9e5 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp @@ -50,13 +50,13 @@ CRotationRandom::CRotationRandom ( double maxNumber, bool isMaximumVector ) : - CInitializer (id, "rotationrandom"), - m_minVector (minVector), - m_maxVector (maxVector), - m_minNumber (minNumber), - m_maxNumber (maxNumber), - m_isMinimumVector (isMinimumVector), - m_isMaximumVector (isMaximumVector) + CInitializer (id, "rotationrandom"), + m_minVector (minVector), + m_maxVector (maxVector), + m_minNumber (minNumber), + m_maxNumber (maxNumber), + m_isMinimumVector (isMinimumVector), + m_isMaximumVector (isMaximumVector) { } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h index 11570d8..3f9f3f1 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h @@ -6,18 +6,45 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers { + /** + * Initializer for particles that decides the base rotation for the particles + */ class CRotationRandom : CInitializer { public: - glm::vec3 getMinimumVector () const; - glm::vec3 getMaximumVector () const; - double getMinimumNumber () const; - double getMaximumNumber () const; + /** + * @return The minimum rotation in vector format if available + */ + [[nodiscard]] glm::vec3 getMinimumVector () const; + /** + * @return The maximum rotation in vector format if available + */ + [[nodiscard]] glm::vec3 getMaximumVector () const; + /** + * @return The minimum rotation in angle format if available + */ + [[nodiscard]] double getMinimumNumber () const; + /** + * @return The maximum rotation in angle format if available + */ + [[nodiscard]] double getMaximumNumber () const; - bool isMinimumVector () const; - bool isMinimumNumber () const; - bool isMaximumVector () const; - bool isMaximumNumber () const; + /** + * @return Indicates if the minimum rotation is a vector + */ + [[nodiscard]] bool isMinimumVector () const; + /** + * @return Indicates if the minimum rotation is an angle + */ + [[nodiscard]] bool isMinimumNumber () const; + /** + * @return Indicates if the maximum rotation is a vector + */ + [[nodiscard]] bool isMaximumVector () const; + /** + * @return Indicates if the maximum rotation is an angle + */ + [[nodiscard]] bool isMaximumNumber () const; protected: friend class CInitializer; @@ -33,13 +60,20 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers double maxNumber, bool isMaximumVector ); - private: - glm::vec3 m_maxVector; - double m_maxNumber; - glm::vec3 m_minVector; - double m_minNumber; + private: + /** Maximum rotation vector */ + glm::vec3 m_maxVector; + /** Maximum rotation angle */ + double m_maxNumber; + /** Minimum rotation vector */ + glm::vec3 m_minVector; + /** Minimum rotation angle */ + double m_minNumber; + + /** If minimum is a vector */ bool m_isMinimumVector; + /** If maximum is a vector */ bool m_isMaximumVector; }; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp index ddfa507..fde4dad 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp @@ -11,9 +11,9 @@ CSizeRandom* CSizeRandom::fromJSON (json data, uint32_t id) } CSizeRandom::CSizeRandom (uint32_t id, uint32_t min, uint32_t max) : - CInitializer (id, "sizerandom"), - m_min (min), - m_max (max) + CInitializer (id, "sizerandom"), + m_min (min), + m_max (max) { } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h index bd119dd..156ef3e 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h @@ -6,19 +6,32 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers { + /** + * Initializer for particles that decides the base size for the particles + */ class CSizeRandom : CInitializer { public: - uint32_t getMinimum () const; - uint32_t getMaximum () const; + /** + * @return The minimum size to be used + */ + [[nodiscard]] uint32_t getMinimum () const; + /** + * @return The maximum size to be used + */ + [[nodiscard]] uint32_t getMaximum () const; + protected: friend class CInitializer; static CSizeRandom* fromJSON (json data, uint32_t id); CSizeRandom (uint32_t id, uint32_t min, uint32_t max); + private: + /** Maximum size */ uint32_t m_max; + /** Minimum size */ uint32_t m_min; }; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp index 403e258..7db3190 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp @@ -36,13 +36,13 @@ CTurbulentVelocityRandom* CTurbulentVelocityRandom::fromJSON (json data, uint32_ CTurbulentVelocityRandom::CTurbulentVelocityRandom (uint32_t id, - double phasemax, double scale, double timescale, uint32_t speedmin, uint32_t speedmax) : - CInitializer (id, "turbulentvelocityrandom"), - m_phasemax (phasemax), - m_scale (scale), - m_timescale (timescale), - m_speedmin (speedmin), - m_speedmax (speedmax) + double phasemax, double scale, double timescale, uint32_t speedmin, uint32_t speedmax) : + CInitializer (id, "turbulentvelocityrandom"), + m_phasemax (phasemax), + m_scale (scale), + m_timescale (timescale), + m_speedmin (speedmin), + m_speedmax (speedmax) { } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h index 2f1026f..f8a1ebd 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h @@ -6,13 +6,31 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers { + /** + * Initializer for particles that decides the turbulent velocity for the particles + */ class CTurbulentVelocityRandom : CInitializer { public: + /** + * @return The phase to use + */ double getPhaseMax (); + /** + * @return The scale to use + */ double getScale (); + /** + * @return How time affects to the scale + */ double getTimeScale (); + /** + * @return The minimum speed + */ uint32_t getMinimumSpeed (); + /** + * @return The maximum speed + */ uint32_t getMaximumSpeed (); protected: @@ -21,12 +39,18 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers static CTurbulentVelocityRandom* fromJSON (json data, uint32_t id); CTurbulentVelocityRandom (uint32_t id, - double phasemax, double scale, double timescale, uint32_t speedmin, uint32_t speedmax); + double phasemax, double scale, double timescale, uint32_t speedmin, uint32_t speedmax); + private: + /** Phase */ double m_phasemax; + /** Scale */ double m_scale; + /** Time scale, how the time affects the scale */ double m_timescale; + /** Minimum speed */ uint32_t m_speedmin; + /** Maximum speed */ uint32_t m_speedmax; }; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp index d3d432f..c525b5d 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp @@ -8,17 +8,17 @@ CVelocityRandom* CVelocityRandom::fromJSON (json data, uint32_t id) auto max_it = jsonFindRequired (data, "max", "Velocityrandom initializer must have a maximum value"); return new CVelocityRandom ( - id, - WallpaperEngine::Core::aToVector3 (*min_it), - WallpaperEngine::Core::aToVector3 (*max_it) + id, + WallpaperEngine::Core::aToVector3 (*min_it), + WallpaperEngine::Core::aToVector3 (*max_it) ); } CVelocityRandom::CVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max) : - CInitializer (id, "velocityrandom"), - m_min (min), - m_max (max) + CInitializer (id, "velocityrandom"), + m_min (min), + m_max (max) { } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h index a11a609..0d56209 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h @@ -6,19 +6,32 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers { + /** + * Initializer for particles that decides the base velocity for the particles + */ class CVelocityRandom : CInitializer { public: - const glm::vec3& getMinimum () const; - const glm::vec3& getMaximum () const; + /** + * @return The minimum velocity (direction * speed) + */ + [[nodiscard]] const glm::vec3& getMinimum () const; + /** + * @return The maximum velocity (direction * speed) + */ + [[nodiscard]] const glm::vec3& getMaximum () const; + protected: friend class CInitializer; static CVelocityRandom* fromJSON (json data, uint32_t id); CVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max); + private: + /** Maximum velocity */ glm::vec3 m_max; + /** Minimum velocity */ glm::vec3 m_min; }; } diff --git a/src/WallpaperEngine/Core/Projects/CProperty.h b/src/WallpaperEngine/Core/Projects/CProperty.h index 9abdb71..a479975 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.h +++ b/src/WallpaperEngine/Core/Projects/CProperty.h @@ -6,6 +6,12 @@ namespace WallpaperEngine::Core::Projects { using json = nlohmann::json; + /** + * Represents a property in a background + * + * Properties are settings that alter how the background looks or works + * and are configurable by the user so they can customize it to their likings + */ class CPropertyColor; class CProperty @@ -18,17 +24,38 @@ namespace WallpaperEngine::Core::Projects template bool is () { return this->m_type == T::Type; } - virtual std::string dump () const = 0; + /** + * @return Representation of what the property does and the default values + */ + [[nodiscard]] virtual std::string dump () const = 0; + /** + * Updates the value of the property with the one in the string + * + * @param value New value for the property + */ virtual void update (const std::string& value) = 0; - const std::string& getName () const; - const std::string& getType () const; - const std::string& getText () const; + /** + * @return Name of the property + */ + [[nodiscard]] const std::string& getName () const; + /** + * @return Type of the property + */ + [[nodiscard]] const std::string& getType () const; + /** + * @return Text of the property + */ + [[nodiscard]] const std::string& getText () const; + protected: CProperty (std::string name, std::string type, std::string text); + /** Type of property */ std::string m_type; + /** Name of the property */ std::string m_name; + /** Description of the property for the user */ std::string m_text; }; } diff --git a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h index a6096f5..591e7bd 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h @@ -6,13 +6,21 @@ namespace WallpaperEngine::Core::Projects { using json = nlohmann::json; + /** + * Represents a boolean property + */ class CPropertyBoolean : public CProperty { public: static CPropertyBoolean* fromJSON (json data, const std::string& name); - bool getValue () const; - std::string dump () const override; + /** + * @return The value of the property + */ + [[nodiscard]] bool getValue () const; + /** @inheritdoc */ + [[nodiscard]] std::string dump () const override; + /** @inheritdoc */ void update (const std::string& value) override; static const std::string Type; @@ -20,6 +28,7 @@ namespace WallpaperEngine::Core::Projects private: CPropertyBoolean (bool value, const std::string& name, const std::string& text); + /** Property's value */ bool m_value; }; } diff --git a/src/WallpaperEngine/Core/Projects/CPropertyColor.h b/src/WallpaperEngine/Core/Projects/CPropertyColor.h index ec3dd18..b1ff3ba 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyColor.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyColor.h @@ -8,13 +8,19 @@ namespace WallpaperEngine::Core::Projects { using json = nlohmann::json; + /** + * Represents a color property + */ class CPropertyColor : public CProperty { public: static CPropertyColor* fromJSON (json data, const std::string& name); - const glm::vec3& getValue () const; - std::string dump () const override; + /** + * @return The RGB color value in the 0-1 range + */ + [[nodiscard]] const glm::vec3& getValue () const; + [[nodiscard]] std::string dump () const override; void update (const std::string& value) override; static const std::string Type; diff --git a/src/WallpaperEngine/Core/Projects/CPropertyCombo.h b/src/WallpaperEngine/Core/Projects/CPropertyCombo.h index be4c8f4..1340984 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyCombo.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyCombo.h @@ -6,6 +6,9 @@ namespace WallpaperEngine::Core::Projects { using json = nlohmann::json; + /** + * Represents different combo values + */ class CPropertyComboValue { public: @@ -13,13 +16,23 @@ namespace WallpaperEngine::Core::Projects std::string value; }; + /** + * Represents a combo property + * + * Combos are properties that have different values available and only one can be selected at once + * this limits the user's possibilities, used for things like the amount of samples to use in audioprocessing + * backgrounds + */ class CPropertyCombo : public CProperty { public: static CPropertyCombo* fromJSON (json data, const std::string& name); - const std::string& getValue () const; - std::string dump () const override; + /** + * @return The selected value + */ + [[nodiscard]] const std::string& getValue () const; + [[nodiscard]] std::string dump () const override; void update (const std::string& value) override; static const std::string Type; @@ -27,9 +40,17 @@ namespace WallpaperEngine::Core::Projects private: CPropertyCombo (const std::string& name, const std::string& text, std::string defaultValue); + /** + * Adds a combo value to the list of possible values + * + * @param label + * @param value + */ void addValue (std::string label, std::string value); + /** List of values available to select */ std::vector m_values; + /** The default value */ std::string m_defaultValue; }; } diff --git a/src/WallpaperEngine/Core/Projects/CPropertySlider.h b/src/WallpaperEngine/Core/Projects/CPropertySlider.h index 8d210f1..0188d8c 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertySlider.h +++ b/src/WallpaperEngine/Core/Projects/CPropertySlider.h @@ -8,16 +8,31 @@ namespace WallpaperEngine::Core::Projects { using json = nlohmann::json; + /** + * Represents a slider value with a minimum and maximum value + */ class CPropertySlider : public CProperty { public: static CPropertySlider* fromJSON (json data, const std::string& name); - const double& getValue () const; - const double& getMinValue () const; - const double& getMaxValue () const; - const double& getStep () const; - std::string dump () const override; + /** + * @return The slider's value + */ + [[nodiscard]] const double& getValue () const; + /** + * @return The slider's minimum value + */ + [[nodiscard]] const double& getMinValue () const; + /** + * @return The slider's maximum value + */ + [[nodiscard]] const double& getMaxValue () const; + /** + * @return The slider's value increment steps, only really used in the UI + */ + [[nodiscard]] const double& getStep () const; + [[nodiscard]] std::string dump () const override; void update (const std::string& value) override; static const std::string Type; @@ -25,9 +40,13 @@ namespace WallpaperEngine::Core::Projects private: CPropertySlider (double value, const std::string& name, const std::string& text, double min, double max, double step); + /** Actual slider value */ double m_value; + /** Minimum value */ double m_min; + /** Maximum value */ double m_max; + /** Increment steps for the slider in the UI */ double m_step; }; } diff --git a/src/WallpaperEngine/Core/Projects/CPropertyText.h b/src/WallpaperEngine/Core/Projects/CPropertyText.h index 5db16ff..f0d2277 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyText.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyText.h @@ -6,11 +6,14 @@ namespace WallpaperEngine::Core::Projects { using json = nlohmann::json; + /** + * Represents a text property + */ class CPropertyText : public CProperty { public: static CPropertyText* fromJSON (json data, const std::string& name); - std::string dump () const override; + [[nodiscard]] std::string dump () const override; void update (const std::string& value) override; static const std::string Type; diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.cpp b/src/WallpaperEngine/Core/Scenes/CProjection.cpp index d43bd4f..1350aee 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.cpp +++ b/src/WallpaperEngine/Core/Scenes/CProjection.cpp @@ -3,7 +3,7 @@ using namespace WallpaperEngine::Core::Scenes; CProjection::CProjection (uint32_t width, uint32_t height) : - m_isAuto (false), + m_isAuto (false), m_width (width), m_height (height) { @@ -11,8 +11,8 @@ CProjection::CProjection (uint32_t width, uint32_t height) : CProjection::CProjection (bool isAuto) : m_isAuto (isAuto), - m_width (0), - m_height (0) + m_width (0), + m_height (0) { } diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp b/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp index 647ce4f..18e5970 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp @@ -24,8 +24,8 @@ CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data) double defaultValue; std::string source; std::string expectedValue; - bool hasCondition = false; - bool hasSource = false; + bool hasCondition = false; + bool hasSource = false; if (data.is_object ()) { diff --git a/src/WallpaperEngine/Render/CRenderContext.cpp b/src/WallpaperEngine/Render/CRenderContext.cpp index e3f706b..22803f9 100644 --- a/src/WallpaperEngine/Render/CRenderContext.cpp +++ b/src/WallpaperEngine/Render/CRenderContext.cpp @@ -1,98 +1,103 @@ #include "common.h" #include -#include - -#include -#include -#include #include -#include #include "CRenderContext.h" #include "CVideo.h" +#include "CWallpaper.h" -using namespace WallpaperEngine::Render; - -CRenderContext::CRenderContext (const COutput* output, CVideoDriver& driver, CInputContext& input, CWallpaperApplication& app) : - m_defaultWallpaper (nullptr), - m_output (output), - m_driver (driver), - m_app (app), - m_input (input), - m_textureCache (new CTextureCache (*this)) +namespace WallpaperEngine::Render { -} - -void CRenderContext::render () -{ - bool firstFrame = true; - bool renderFrame = true; - - for (const auto& cur : this->m_output->getViewports ()) + CRenderContext::CRenderContext ( + const Drivers::Output::COutput* output, Drivers::CVideoDriver& driver, Input::CInputContext& input, + CWallpaperApplication& app + ) : + m_defaultWallpaper (nullptr), + m_output (output), + m_driver (driver), + m_app (app), + m_input (input), + m_textureCache (new CTextureCache (*this)) { -#if !NDEBUG - std::string str = "Rendering to output " + cur.first; - - glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ()); -#endif /* DEBUG */ - - // search the background in the viewport selection - auto ref = this->m_wallpapers.find (cur.first); - - // render the background - if (ref != this->m_wallpapers.end ()) - ref->second->render (cur.second.viewport, this->m_output->renderVFlip (), renderFrame, firstFrame); - else - this->m_defaultWallpaper->render (cur.second.viewport, this->m_output->renderVFlip (), renderFrame, firstFrame); - // scenes need to render a new frame for each viewport as they produce different results - // but videos should only be rendered once per group of viewports - firstFrame = false; -#if !NDEBUG - glPopDebugGroup (); -#endif /* DEBUG */ } - // read the full texture into the image - if (this->m_output->haveImageBuffer ()) - glReadPixels ( - 0, 0, this->m_output->getFullWidth (), this->m_output->getFullHeight (), - GL_BGRA, GL_UNSIGNED_BYTE, - this->m_output->getImageBuffer () - ); + void CRenderContext::render () + { + bool firstFrame = true; + bool renderFrame = true; - // update the output with the given image - this->m_output->updateRender (); - // finally swap buffers - this->m_driver.swapBuffers (); -} + for (const auto& cur : this->m_output->getViewports ()) + { +#if !NDEBUG + std::string str = "Rendering to output " + cur.first; -void CRenderContext::setDefaultWallpaper (CWallpaper* wallpaper) -{ - this->m_defaultWallpaper = wallpaper; -} + glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ()); +#endif /* DEBUG */ -void CRenderContext::setWallpaper (const std::string& display, CWallpaper* wallpaper) -{ - this->m_wallpapers.insert_or_assign (display, wallpaper); -} + // search the background in the viewport selection + auto ref = this->m_wallpapers.find (cur.first); -CInputContext& CRenderContext::getInputContext () const -{ - return this->m_input; -} + // render the background + if (ref != this->m_wallpapers.end ()) + ref->second->render (cur.second.viewport, this->m_output->renderVFlip (), renderFrame, firstFrame); + else + this->m_defaultWallpaper->render ( + cur.second.viewport, this->m_output->renderVFlip (), renderFrame, firstFrame + ); + // scenes need to render a new frame for each viewport as they produce different results + // but videos should only be rendered once per group of viewports + firstFrame = false; +#if !NDEBUG + glPopDebugGroup (); +#endif /* DEBUG */ + } -const CWallpaperApplication& CRenderContext::getApp () const -{ - return this->m_app; -} + // read the full texture into the image + if (this->m_output->haveImageBuffer ()) + glReadPixels ( + 0, 0, this->m_output->getFullWidth (), this->m_output->getFullHeight (), GL_BGRA, GL_UNSIGNED_BYTE, + this->m_output->getImageBuffer () + ); -const COutput* CRenderContext::getOutput () const -{ - return this->m_output; -} + // update the output with the given image + this->m_output->updateRender (); + // finally swap buffers + this->m_driver.swapBuffers (); + } -const ITexture* CRenderContext::resolveTexture (const std::string& name) -{ - return this->m_textureCache->resolve (name); + void CRenderContext::setDefaultWallpaper (CWallpaper* wallpaper) + { + this->m_defaultWallpaper = wallpaper; + } + + void CRenderContext::setWallpaper (const std::string& display, CWallpaper* wallpaper) + { + this->m_wallpapers.insert_or_assign (display, wallpaper); + } + + Input::CInputContext& CRenderContext::getInputContext () const + { + return this->m_input; + } + + const CWallpaperApplication& CRenderContext::getApp () const + { + return this->m_app; + } + + const Drivers::CVideoDriver& CRenderContext::getDriver () const + { + return this->m_driver; + } + + const Drivers::Output::COutput* CRenderContext::getOutput () const + { + return this->m_output; + } + + const ITexture* CRenderContext::resolveTexture (const std::string& name) + { + return this->m_textureCache->resolve (name); + } } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CRenderContext.h b/src/WallpaperEngine/Render/CRenderContext.h index d7881d3..87d4b31 100644 --- a/src/WallpaperEngine/Render/CRenderContext.h +++ b/src/WallpaperEngine/Render/CRenderContext.h @@ -4,60 +4,63 @@ #include #include "CTextureCache.h" -#include "CWallpaper.h" #include "WallpaperEngine/Application/CWallpaperApplication.h" #include "WallpaperEngine/Input/CInputContext.h" #include "WallpaperEngine/Input/CMouseInput.h" #include "WallpaperEngine/Render/Drivers/CVideoDriver.h" #include "WallpaperEngine/Render/Drivers/Output/COutput.h" -#include -using namespace WallpaperEngine::Application; -using namespace WallpaperEngine::Assets; -using namespace WallpaperEngine::Input; -using namespace WallpaperEngine::Render::Drivers; -using namespace WallpaperEngine::Render::Drivers::Output; - -namespace WallpaperEngine::Render::Drivers::Output +namespace WallpaperEngine { - class COutput; -} - -namespace WallpaperEngine::Render::Drivers -{ - class CVideoDriver; -} - -namespace WallpaperEngine::Application -{ - class CWallpaperApplication; -} - -namespace WallpaperEngine::Render -{ - class CWallpaper; - class CTextureCache; - - class CRenderContext + namespace Application { - public: - CRenderContext (const COutput* output, CVideoDriver& driver, CInputContext& input, CWallpaperApplication& app); + class CWallpaperApplication; + } - void render (); - void setDefaultWallpaper (CWallpaper* wallpaper); - void setWallpaper (const std::string& display, CWallpaper* wallpaper); - CInputContext& getInputContext () const; - const CWallpaperApplication& getApp () const; - const COutput* getOutput () const; - const ITexture* resolveTexture (const std::string& name); + namespace Render + { + namespace Drivers + { + class CVideoDriver; - private: - CVideoDriver& m_driver; - std::map m_wallpapers; - CWallpaper* m_defaultWallpaper; - CInputContext& m_input; - CWallpaperApplication& m_app; - CTextureCache* m_textureCache; - const COutput* m_output; - }; + namespace Output + { + class COutput; + } + } + + class CWallpaper; + class CTextureCache; + + class CRenderContext + { + public: + CRenderContext (const Drivers::Output::COutput* output, Drivers::CVideoDriver& driver, Input::CInputContext& input, CWallpaperApplication& app); + + void render (); + void setDefaultWallpaper (CWallpaper* wallpaper); + void setWallpaper (const std::string& display, CWallpaper* wallpaper); + [[nodiscard]] Input::CInputContext& getInputContext () const; + [[nodiscard]] const CWallpaperApplication& getApp () const; + [[nodiscard]] const Drivers::CVideoDriver& getDriver () const; + [[nodiscard]] const Drivers::Output::COutput* getOutput () const; + const ITexture* resolveTexture (const std::string& name); + + private: + /** Video driver in use */ + Drivers::CVideoDriver& m_driver; + /** Maps screen -> wallpaper list */ + std::map m_wallpapers; + /** Default wallpaper to use */ + CWallpaper* m_defaultWallpaper; + /** Input context for interactions */ + Input::CInputContext& m_input; + /** App that holds the render context */ + CWallpaperApplication& m_app; + /** Texture cache for the render */ + CTextureCache* m_textureCache; + /** Output driver that describes how the wallpapers are rendered */ + const Drivers::Output::COutput* m_output; + }; + } } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index 67c4760..c345ede 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -16,9 +16,9 @@ using namespace WallpaperEngine::Render; CScene::CScene (Core::CScene* scene, CRenderContext& context, CAudioContext& audioContext) : CWallpaper (scene, Type, context, audioContext), - m_mousePosition (), - m_mousePositionLast (), - m_parallaxDisplacement () + m_mousePosition (), + m_mousePositionLast (), + m_parallaxDisplacement () { // setup the scene camera this->m_camera = new CCamera (this, scene->getCamera ()); diff --git a/src/WallpaperEngine/Render/CTextureCache.cpp b/src/WallpaperEngine/Render/CTextureCache.cpp index 41a066f..d4d3007 100644 --- a/src/WallpaperEngine/Render/CTextureCache.cpp +++ b/src/WallpaperEngine/Render/CTextureCache.cpp @@ -1,17 +1,18 @@ #include "CTextureCache.h" +#include "WallpaperEngine/Render/Helpers/CContextAware.h" #include "WallpaperEngine/Assets/CAssetLoadException.h" using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Assets; CTextureCache::CTextureCache (CRenderContext& context) : - m_context (context) + Helpers::CContextAware (context) { } CTextureCache::~CTextureCache () - = default; += default; const ITexture* CTextureCache::resolve (const std::string& filename) { @@ -20,29 +21,30 @@ const ITexture* CTextureCache::resolve (const std::string& filename) if (found != this->m_textureCache.end ()) return (*found).second; - // search for the texture in all the different containers just in case - for (auto it : this->m_context.getApp ().getProjects ()) - { - const ITexture* texture = it.second->getContainer ()->readTexture (filename); + // search for the texture in all the different containers just in case + for (auto it : this->getContext ().getApp ().getBackgrounds ()) + { + const ITexture* texture = it.second->getContainer ()->readTexture (filename); - this->store (filename, texture); + this->store (filename, texture); - return texture; - } + return texture; + } - if (this->m_context.getApp ().getDefaultProject () != nullptr) - { - const ITexture* texture = this->m_context.getApp ().getDefaultProject ()->getContainer ()->readTexture (filename); + if (this->getContext ().getApp ().getDefaultBackground () != nullptr) + { + const ITexture* texture = + this->getContext ().getApp ().getDefaultBackground ()->getContainer ()->readTexture (filename); - this->store (filename, texture); + this->store (filename, texture); - return texture; - } + return texture; + } - throw CAssetLoadException (filename, "Cannot find file"); + throw CAssetLoadException (filename, "Cannot find file"); } -void CTextureCache::store (std::string name, const ITexture* texture) +void CTextureCache::store (const std::string& name, const ITexture* texture) { this->m_textureCache.insert_or_assign (name, texture); } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CTextureCache.h b/src/WallpaperEngine/Render/CTextureCache.h index 13953dc..94c6fc4 100644 --- a/src/WallpaperEngine/Render/CTextureCache.h +++ b/src/WallpaperEngine/Render/CTextureCache.h @@ -5,17 +5,23 @@ #include "WallpaperEngine/Assets/ITexture.h" #include "WallpaperEngine/Render/CRenderContext.h" +#include "WallpaperEngine/Render/Helpers/CContextAware.h" using namespace WallpaperEngine::Assets; namespace WallpaperEngine::Render { + namespace Helpers + { + class CContextAware; + } + class CRenderContext; - class CTextureCache + class CTextureCache : Helpers::CContextAware { public: - CTextureCache (CRenderContext& context); + explicit CTextureCache (CRenderContext& context); ~CTextureCache (); /** @@ -33,10 +39,10 @@ namespace WallpaperEngine::Render * @param name * @param texture */ - void store (std::string name, const ITexture* texture); + void store (const std::string& name, const ITexture* texture); private: - CRenderContext& m_context; + /** Cached textures */ std::map m_textureCache; }; } diff --git a/src/WallpaperEngine/Render/CVideo.cpp b/src/WallpaperEngine/Render/CVideo.cpp index 2b19f66..9cc64d6 100644 --- a/src/WallpaperEngine/Render/CVideo.cpp +++ b/src/WallpaperEngine/Render/CVideo.cpp @@ -19,7 +19,7 @@ CVideo::CVideo (Core::CVideo* video, CRenderContext& context, CAudioContext& aud CWallpaper (video, Type, context, audioContext), m_width (16), m_height (16), - m_mpvGl (nullptr) + m_mpvGl (nullptr) { double volume = g_AudioVolume * 100.0 / 128.0; @@ -54,9 +54,9 @@ CVideo::CVideo (Core::CVideo* video, CRenderContext& context, CAudioContext& aud if (mpv_render_context_create (&this->m_mpvGl, this->m_mpv, params) < 0) sLog.exception ("Failed to initialize MPV's GL context"); - std::filesystem::path videopath = this->getVideo ()->getProject ().getContainer ()->resolveRealFile (this->getVideo ()->getFilename ()); + std::filesystem::path videopath = this->getVideo ()->getProject ().getContainer ()->resolveRealFile (this->getVideo ()->getFilename ()); - // build the path to the video file + // build the path to the video file const char* command [] = { "loadfile", videopath.c_str (), nullptr }; @@ -102,14 +102,14 @@ void CVideo::renderFrame (glm::ivec4 viewport) break; // we do not care about any of the events - if (event->event_id == MPV_EVENT_VIDEO_RECONFIG) - { - int64_t width, height; + if (event->event_id == MPV_EVENT_VIDEO_RECONFIG) + { + int64_t width, height; - if (mpv_get_property (this->m_mpv, "dwidth", MPV_FORMAT_INT64, &width) >= 0 && - mpv_get_property (this->m_mpv, "dheight", MPV_FORMAT_INT64, &height) >= 0) - this->setSize (width, height); - } + if (mpv_get_property (this->m_mpv, "dwidth", MPV_FORMAT_INT64, &width) >= 0 && + mpv_get_property (this->m_mpv, "dheight", MPV_FORMAT_INT64, &height) >= 0) + this->setSize (width, height); + } } // render the next diff --git a/src/WallpaperEngine/Render/CWallpaper.cpp b/src/WallpaperEngine/Render/CWallpaper.cpp index e74a503..235484f 100644 --- a/src/WallpaperEngine/Render/CWallpaper.cpp +++ b/src/WallpaperEngine/Render/CWallpaper.cpp @@ -10,18 +10,18 @@ using namespace WallpaperEngine::Render; CWallpaper::CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext) : + CContextAware (context), m_wallpaperData (wallpaperData), m_type (std::move(type)), - m_context (context), m_destFramebuffer (GL_NONE), - m_sceneFBO (nullptr), - m_texCoordBuffer (GL_NONE), - m_positionBuffer (GL_NONE), - m_shader (GL_NONE), - g_Texture0 (GL_NONE), - a_Position (GL_NONE), - a_TexCoord (GL_NONE), - m_vaoBuffer (GL_NONE), + m_sceneFBO (nullptr), + m_texCoordBuffer (GL_NONE), + m_positionBuffer (GL_NONE), + m_shader (GL_NONE), + g_Texture0 (GL_NONE), + a_Position (GL_NONE), + a_TexCoord (GL_NONE), + m_vaoBuffer (GL_NONE), m_audioContext (audioContext) { // generate the VAO to stop opengl from complaining @@ -88,7 +88,7 @@ void CWallpaper::setupShaders () // give shader's source code to OpenGL to be compiled const char* sourcePointer = "#version 330\n" - "precision highp float;\n" + "precision highp float;\n" "in vec3 a_Position;\n" "in vec2 a_TexCoord;\n" "out vec2 v_TexCoord;\n" @@ -127,10 +127,10 @@ void CWallpaper::setupShaders () // give shader's source code to OpenGL to be compiled sourcePointer = "#version 330\n" - "precision highp float;\n" + "precision highp float;\n" "uniform sampler2D g_Texture0;\n" "in vec2 v_TexCoord;\n" - "out vec4 out_FragColor;\n" + "out vec4 out_FragColor;\n" "void main () {\n" "out_FragColor = texture (g_Texture0, v_TexCoord);\n" "}"; @@ -226,7 +226,7 @@ void CWallpaper::render (glm::ivec4 viewport, bool vflip, bool renderFrame, bool if ( (viewport.w > viewport.z && projectionWidth >= projectionHeight) || - (viewport.z > viewport.w && projectionHeight > projectionWidth) + (viewport.z > viewport.w && projectionHeight > projectionWidth) ) { if (vflip) @@ -253,7 +253,7 @@ void CWallpaper::render (glm::ivec4 viewport, bool vflip, bool renderFrame, bool if ( (viewport.z > viewport.w && projectionWidth >= projectionHeight) || - (viewport.w > viewport.z && projectionHeight > projectionWidth) + (viewport.w > viewport.z && projectionHeight > projectionWidth) ) { ustart = 0.0f; @@ -335,11 +335,6 @@ void CWallpaper::setupFramebuffers () ); } -CRenderContext& CWallpaper::getContext () -{ - return this->m_context; -} - CAudioContext& CWallpaper::getAudioContext () { return this->m_audioContext; diff --git a/src/WallpaperEngine/Render/CWallpaper.h b/src/WallpaperEngine/Render/CWallpaper.h index 5029b15..1ba10c9 100644 --- a/src/WallpaperEngine/Render/CWallpaper.h +++ b/src/WallpaperEngine/Render/CWallpaper.h @@ -3,23 +3,28 @@ #include #include +#include "WallpaperEngine/Assets/CContainer.h" +#include "WallpaperEngine/Audio/CAudioContext.h" + #include "WallpaperEngine/Core/CWallpaper.h" #include "WallpaperEngine/Core/CScene.h" #include "WallpaperEngine/Core/CVideo.h" -#include "CFBO.h" -#include "CRenderContext.h" -#include "WallpaperEngine/Assets/CContainer.h" -#include "WallpaperEngine/Audio/CAudioContext.h" +#include "WallpaperEngine/Render/CRenderContext.h" +#include "WallpaperEngine/Render/CFBO.h" +#include "WallpaperEngine/Render/Helpers/CContextAware.h" using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Audio; namespace WallpaperEngine::Render { - class CRenderContext; + namespace Helpers + { + class CContextAware; + } - class CWallpaper + class CWallpaper : public Helpers::CContextAware { public: template const T* as () const { assert (is ()); return (const T*) this; } @@ -27,7 +32,6 @@ namespace WallpaperEngine::Render template bool is () { return this->m_type == T::Type; } - CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext); ~CWallpaper (); /** @@ -38,12 +42,7 @@ namespace WallpaperEngine::Render /** * @return The container to resolve files for this wallpaper */ - CContainer* getContainer () const; - - /** - * @return The current context rendering this wallpaper - */ - CRenderContext& getContext (); + [[nodiscard]] CContainer* getContainer () const; /** * @return The current audio context for this wallpaper @@ -53,11 +52,11 @@ namespace WallpaperEngine::Render /** * @return The scene's framebuffer */ - virtual GLuint getWallpaperFramebuffer () const; + [[nodiscard]] virtual GLuint getWallpaperFramebuffer () const; /** * @return The scene's texture */ - virtual GLuint getWallpaperTexture () const; + [[nodiscard]] virtual GLuint getWallpaperTexture () const; /** * Creates a new FBO for this wallpaper * @@ -69,19 +68,19 @@ namespace WallpaperEngine::Render /** * @return The full FBO list to work with */ - const std::map& getFBOs () const; + [[nodiscard]] const std::map& getFBOs () const; /** * Searches the FBO list for the given FBO * * @param name * @return */ - CFBO* findFBO (const std::string& name) const; + [[nodiscard]] CFBO* findFBO (const std::string& name) const; /** * @return The main FBO of this wallpaper */ - CFBO* getFBO () const; + [[nodiscard]] CFBO* getFBO () const; /** * Updates the texcoord used for drawing to the used framebuffer @@ -98,12 +97,12 @@ namespace WallpaperEngine::Render /** * @return The width of this wallpaper */ - virtual uint32_t getWidth () const = 0; + [[nodiscard]] virtual uint32_t getWidth () const = 0; /** * @return The height of this wallpaper */ - virtual uint32_t getHeight () const = 0; + [[nodiscard]] virtual uint32_t getHeight () const = 0; /** * Creates a new instance of CWallpaper based on the information provided by the read backgrounds @@ -115,6 +114,8 @@ namespace WallpaperEngine::Render static CWallpaper* fromWallpaper (Core::CWallpaper* wallpaper, CRenderContext& context, CAudioContext& audioContext); protected: + CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext); + /** * Renders a frame of the wallpaper */ @@ -127,17 +128,13 @@ namespace WallpaperEngine::Render Core::CWallpaper* m_wallpaperData; - Core::CWallpaper* getWallpaperData () const; + [[nodiscard]] Core::CWallpaper* getWallpaperData () const; - /** - * The FBO used for scene output - */ + /** The FBO used for scene output */ CFBO* m_sceneFBO; private: - /** - * The texture used for the scene output - */ + /** The texture used for the scene output */ GLuint m_texCoordBuffer; GLuint m_positionBuffer; GLuint m_shader; @@ -146,30 +143,15 @@ namespace WallpaperEngine::Render GLint a_Position; GLint a_TexCoord; GLuint m_vaoBuffer; - /** - * The framebuffer to draw the background to - */ + /** The framebuffer to draw the background to */ GLuint m_destFramebuffer; - /** - * Setups OpenGL's shaders for this wallpaper backbuffer - */ + /** Setups OpenGL's shaders for this wallpaper backbuffer */ void setupShaders (); - /** - * The type of background this wallpaper is (used - */ + /** The type of background this wallpaper is */ std::string m_type; - - /** - * List of FBOs registered for this wallpaper - */ + /** List of FBOs registered for this wallpaper */ std::map m_fbos; - /** - * Context that is using this wallpaper - */ - CRenderContext& m_context; - /* - * Audio context that is using this wallpaper - */ + /** Audio context that is using this wallpaper */ CAudioContext& m_audioContext; }; } diff --git a/src/WallpaperEngine/Render/Drivers/COpenGLDriver.cpp b/src/WallpaperEngine/Render/Drivers/COpenGLDriver.cpp index 22b0c44..65cadc6 100644 --- a/src/WallpaperEngine/Render/Drivers/COpenGLDriver.cpp +++ b/src/WallpaperEngine/Render/Drivers/COpenGLDriver.cpp @@ -6,13 +6,13 @@ using namespace WallpaperEngine::Render::Drivers; void CustomGLFWErrorHandler (int errorCode, const char* reason) { - sLog.error ("GLFW error ", errorCode, ": ", reason); + sLog.error ("GLFW error ", errorCode, ": ", reason); } COpenGLDriver::COpenGLDriver (const char* windowTitle) : m_frameCounter (0) { - glfwSetErrorCallback (CustomGLFWErrorHandler); + glfwSetErrorCallback (CustomGLFWErrorHandler); // initialize glfw if (glfwInit () == GLFW_FALSE) @@ -26,7 +26,7 @@ COpenGLDriver::COpenGLDriver (const char* windowTitle) : glfwWindowHint (GLFW_VISIBLE, GLFW_FALSE); #if !NDEBUG - glfwWindowHint (GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); + glfwWindowHint (GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif /* DEBUG */ // create window, size doesn't matter as long as we don't show it @@ -54,7 +54,7 @@ COpenGLDriver::~COpenGLDriver () FreeImage_DeInitialise(); } -float COpenGLDriver::getRenderTime () +float COpenGLDriver::getRenderTime () const { return (float) glfwGetTime (); } @@ -71,7 +71,7 @@ void COpenGLDriver::resizeWindow (glm::ivec2 size) void COpenGLDriver::resizeWindow (glm::ivec4 sizeandpos) { - glfwSetWindowPos (this->m_window, sizeandpos.x, sizeandpos.y); + glfwSetWindowPos (this->m_window, sizeandpos.x, sizeandpos.y); glfwSetWindowSize (this->m_window, sizeandpos.z, sizeandpos.w); } @@ -85,7 +85,7 @@ void COpenGLDriver::hideWindow () glfwHideWindow (this->m_window); } -glm::ivec2 COpenGLDriver::getFramebufferSize () +glm::ivec2 COpenGLDriver::getFramebufferSize () const { glm::ivec2 size; @@ -104,7 +104,7 @@ void COpenGLDriver::swapBuffers () this->m_frameCounter ++; } -uint32_t COpenGLDriver::getFrameCounter () +uint32_t COpenGLDriver::getFrameCounter () const { return this->m_frameCounter; } @@ -112,4 +112,4 @@ uint32_t COpenGLDriver::getFrameCounter () GLFWwindow* COpenGLDriver::getWindow () { return this->m_window; -} \ No newline at end of file +} diff --git a/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h b/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h index e421b4f..14fd63d 100644 --- a/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h +++ b/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h @@ -7,12 +7,12 @@ namespace WallpaperEngine::Application { - class CApplicationContext; + class CApplicationContext; } namespace WallpaperEngine::Render::Drivers { - using namespace WallpaperEngine::Application; + using namespace WallpaperEngine::Application; class COpenGLDriver : public CVideoDriver { @@ -20,15 +20,15 @@ namespace WallpaperEngine::Render::Drivers explicit COpenGLDriver (const char* windowTitle); ~COpenGLDriver(); - float getRenderTime () override; + float getRenderTime () const override; bool closeRequested () override; void resizeWindow (glm::ivec2 size) override; - void resizeWindow (glm::ivec4 sizeandpos) override; + void resizeWindow (glm::ivec4 sizeandpos) override; void showWindow () override; void hideWindow () override; - glm::ivec2 getFramebufferSize () override; + glm::ivec2 getFramebufferSize () const override; void swapBuffers () override; - uint32_t getFrameCounter () override; + uint32_t getFrameCounter () const override; GLFWwindow* getWindow (); diff --git a/src/WallpaperEngine/Render/Drivers/CVideoDriver.h b/src/WallpaperEngine/Render/Drivers/CVideoDriver.h index 4d159df..90bd31c 100644 --- a/src/WallpaperEngine/Render/Drivers/CVideoDriver.h +++ b/src/WallpaperEngine/Render/Drivers/CVideoDriver.h @@ -8,14 +8,41 @@ namespace WallpaperEngine::Render::Drivers class CVideoDriver { public: - virtual float getRenderTime () = 0; + /** + * @return The time that has passed since the driver started + */ + virtual float getRenderTime () const = 0; + /** + * @return If a close was requested by the OS + */ virtual bool closeRequested () = 0; + /** + * @param size The new size for the window + */ virtual void resizeWindow (glm::ivec2 size) = 0; - virtual void resizeWindow (glm::ivec4 size) = 0; + /** + * @param size The new size and position of the window + */ + virtual void resizeWindow (glm::ivec4 positionAndSize) = 0; + /** + * Shows the window created by the driver + */ virtual void showWindow () = 0; + /** + * Hides the window created by the driver + */ virtual void hideWindow () = 0; - virtual glm::ivec2 getFramebufferSize () = 0; + /** + * @return The size of the framebuffer available for the driver + */ + virtual glm::ivec2 getFramebufferSize () const = 0; + /** + * Performs buffer swapping + */ virtual void swapBuffers () = 0; - virtual uint32_t getFrameCounter () = 0; + /** + * @return The number of rendered frames since the start of the driver + */ + virtual uint32_t getFrameCounter () const = 0; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.cpp b/src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.cpp new file mode 100644 index 0000000..bb03050 --- /dev/null +++ b/src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.cpp @@ -0,0 +1,78 @@ +#include +#include "CGLFWWindowOutput.h" +#include "WallpaperEngine/Logging/CLog.h" + +using namespace WallpaperEngine::Render::Drivers::Output; + +CGLFWWindowOutput::CGLFWWindowOutput (CApplicationContext& context, CVideoDriver& driver) : + COutput (context), + m_driver (driver) +{ + if ( + this->m_context.render.mode != Application::CApplicationContext::NORMAL_WINDOW && + this->m_context.render.mode != Application::CApplicationContext::EXPLICIT_WINDOW) + sLog.exception ("Initializing window output when not in output mode, how did you get here?!"); + + // window should be visible + driver.showWindow (); + + if (this->m_context.render.mode == Application::CApplicationContext::EXPLICIT_WINDOW) + { + this->m_fullWidth = this->m_context.render.window.geometry.z; + this->m_fullHeight = this->m_context.render.window.geometry.w; + this->repositionWindow (); + } + else + { + // take the size from the driver (default window size) + this->m_fullWidth = this->m_driver.getFramebufferSize ().x; + this->m_fullHeight = this->m_driver.getFramebufferSize ().y; + } + + // register the default viewport + this->m_viewports ["default"] = {{0, 0, this->m_fullWidth, this->m_fullHeight}, "default"}; +} + +void CGLFWWindowOutput::repositionWindow () +{ + // reposition the window + this->m_driver.resizeWindow (this->m_context.render.window.geometry); +} + +void CGLFWWindowOutput::reset () +{ + if (this->m_context.render.mode == Application::CApplicationContext::EXPLICIT_WINDOW) + this->repositionWindow (); +} + +bool CGLFWWindowOutput::renderVFlip () const +{ + return true; +} + +bool CGLFWWindowOutput::renderMultiple () const +{ + return false; +} + +bool CGLFWWindowOutput::haveImageBuffer () const +{ + return false; +} + +void* CGLFWWindowOutput::getImageBuffer () const +{ + return nullptr; +} +void CGLFWWindowOutput::updateRender () const +{ + if (this->m_context.render.mode != Application::CApplicationContext::NORMAL_WINDOW) + return; + + // take the size from the driver (default window size) + this->m_fullWidth = this->m_driver.getFramebufferSize ().x; + this->m_fullHeight = this->m_driver.getFramebufferSize ().y; + + // update the default viewport + this->m_viewports ["default"] = {{0, 0, this->m_fullWidth, this->m_fullHeight}, "default"}; +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.h b/src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.h new file mode 100644 index 0000000..17b638e --- /dev/null +++ b/src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.h @@ -0,0 +1,25 @@ +#pragma once + +#include "WallpaperEngine/Render/Drivers/CVideoDriver.h" +#include "COutput.h" + +namespace WallpaperEngine::Render::Drivers::Output +{ + class CGLFWWindowOutput : public COutput + { + public: + CGLFWWindowOutput (CApplicationContext& context, CVideoDriver& driver); + + void reset () override; + bool renderVFlip () const override; + bool renderMultiple () const override; + bool haveImageBuffer () const override; + void* getImageBuffer () const override; + void updateRender () const override; + + private: + void repositionWindow (); + + CVideoDriver& m_driver; + }; +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Drivers/Output/COutput.cpp b/src/WallpaperEngine/Render/Drivers/Output/COutput.cpp index fcfcf72..529e3a7 100644 --- a/src/WallpaperEngine/Render/Drivers/Output/COutput.cpp +++ b/src/WallpaperEngine/Render/Drivers/Output/COutput.cpp @@ -3,21 +3,21 @@ using namespace WallpaperEngine::Render::Drivers::Output; COutput::COutput (CApplicationContext& context) : - m_context (context) + m_context (context) { } const std::map & COutput::getViewports () const { - return this->m_viewports; + return this->m_viewports; } int COutput::getFullWidth () const { - return this->m_fullWidth; + return this->m_fullWidth; } int COutput::getFullHeight () const { - return this->m_fullHeight; + return this->m_fullHeight; } diff --git a/src/WallpaperEngine/Render/Drivers/Output/COutput.h b/src/WallpaperEngine/Render/Drivers/Output/COutput.h index 934924c..469cf44 100644 --- a/src/WallpaperEngine/Render/Drivers/Output/COutput.h +++ b/src/WallpaperEngine/Render/Drivers/Output/COutput.h @@ -10,38 +10,38 @@ using namespace WallpaperEngine::Application; namespace WallpaperEngine::Application { - class CApplicationContext; + class CApplicationContext; } namespace WallpaperEngine::Render::Drivers::Output { - class COutput - { - public: - COutput (CApplicationContext& context); + class COutput + { + public: + COutput (CApplicationContext& context); - virtual void reset () = 0; + virtual void reset () = 0; - int getFullWidth () const; - int getFullHeight () const; + int getFullWidth () const; + int getFullHeight () const; - struct ScreenInfo - { - glm::ivec4 viewport; - std::string name; - }; + struct ScreenInfo + { + glm::ivec4 viewport; + std::string name; + }; - virtual bool renderVFlip () const = 0; - virtual bool renderMultiple () const = 0; - virtual bool haveImageBuffer () const = 0; - const std::map & getViewports () const; - virtual void* getImageBuffer () const = 0; - virtual void updateRender () const = 0; + virtual bool renderVFlip () const = 0; + virtual bool renderMultiple () const = 0; + virtual bool haveImageBuffer () const = 0; + const std::map & getViewports () const; + virtual void* getImageBuffer () const = 0; + virtual void updateRender () const = 0; - protected: - mutable int m_fullWidth; - mutable int m_fullHeight; - mutable std::map m_viewports; - CApplicationContext& m_context; - }; + protected: + mutable int m_fullWidth; + mutable int m_fullHeight; + mutable std::map m_viewports; + CApplicationContext& m_context; + }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Drivers/Output/CWindowOutput.cpp b/src/WallpaperEngine/Render/Drivers/Output/CWindowOutput.cpp deleted file mode 100644 index f4bd914..0000000 --- a/src/WallpaperEngine/Render/Drivers/Output/CWindowOutput.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "CWindowOutput.h" -#include "WallpaperEngine/Logging/CLog.h" - -using namespace WallpaperEngine::Render::Drivers::Output; - -CWindowOutput::CWindowOutput (CApplicationContext& context, CVideoDriver& driver) : - COutput (context), - m_driver (driver) -{ - if ( - this->m_context.windowMode != Application::CApplicationContext::NORMAL_WINDOW && - this->m_context.windowMode != Application::CApplicationContext::EXPLICIT_WINDOW) - sLog.exception ("Inititalizing window output when not in output mode, how did you get here?!"); - - // window should be visible - driver.showWindow (); - - if (this->m_context.windowMode == Application::CApplicationContext::EXPLICIT_WINDOW) - { - this->m_fullWidth = this->m_context.windowGeometry.z; - this->m_fullHeight = this->m_context.windowGeometry.w; - this->repositionWindow (); - } - else - { - // take the size from the driver (default window size) - this->m_fullWidth = this->m_driver.getFramebufferSize ().x; - this->m_fullHeight = this->m_driver.getFramebufferSize ().y; - } - - // register the default viewport - this->m_viewports ["default"] = {{0, 0, this->m_fullWidth, this->m_fullHeight}, "default"}; -} - -void CWindowOutput::repositionWindow () -{ - // reposition the window - this->m_driver.resizeWindow (this->m_context.windowGeometry); -} - -void CWindowOutput::reset () -{ - if (this->m_context.windowMode == Application::CApplicationContext::EXPLICIT_WINDOW) - this->repositionWindow (); -} - -bool CWindowOutput::renderVFlip () const -{ - return true; -} - -bool CWindowOutput::renderMultiple () const -{ - return false; -} - -bool CWindowOutput::haveImageBuffer () const -{ - return false; -} - -void* CWindowOutput::getImageBuffer () const -{ - return nullptr; -} -void CWindowOutput::updateRender () const -{ - if (this->m_context.windowMode != Application::CApplicationContext::NORMAL_WINDOW) - return; - - // take the size from the driver (default window size) - this->m_fullWidth = this->m_driver.getFramebufferSize ().x; - this->m_fullHeight = this->m_driver.getFramebufferSize ().y; - - // update the default viewport - this->m_viewports ["default"] = {{0, 0, this->m_fullWidth, this->m_fullHeight}, "default"}; -} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Drivers/Output/CWindowOutput.h b/src/WallpaperEngine/Render/Drivers/Output/CWindowOutput.h deleted file mode 100644 index 1e2f0e6..0000000 --- a/src/WallpaperEngine/Render/Drivers/Output/CWindowOutput.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "WallpaperEngine/Render/Drivers/CVideoDriver.h" -#include "COutput.h" - -namespace WallpaperEngine::Render::Drivers::Output -{ - class CWindowOutput : public COutput - { - public: - CWindowOutput (CApplicationContext& context, CVideoDriver& driver); - - void reset () override; - bool renderVFlip () const override; - bool renderMultiple () const override; - bool haveImageBuffer () const override; - void* getImageBuffer () const override; - void updateRender () const override; - - private: - void repositionWindow (); - - CVideoDriver& m_driver; - }; -} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Drivers/Output/CX11Output.cpp b/src/WallpaperEngine/Render/Drivers/Output/CX11Output.cpp index 55578aa..6603828 100644 --- a/src/WallpaperEngine/Render/Drivers/Output/CX11Output.cpp +++ b/src/WallpaperEngine/Render/Drivers/Output/CX11Output.cpp @@ -40,137 +40,137 @@ int CustomXIOErrorHandler (Display* dsp) } CX11Output::CX11Output (CApplicationContext& context, CVideoDriver& driver) : - COutput (context), - m_driver (driver) + COutput (context), + m_driver (driver) { - // do not use previous handler, it might stop the app under weird circumstances - XSetErrorHandler (CustomXErrorHandler); - XSetIOErrorHandler (CustomXIOErrorHandler); + // do not use previous handler, it might stop the app under weird circumstances + XSetErrorHandler (CustomXErrorHandler); + XSetIOErrorHandler (CustomXIOErrorHandler); - this->loadScreenInfo (); + this->loadScreenInfo (); } CX11Output::~CX11Output () { - this->free (); + this->free (); } void CX11Output::reset () { - // first free whatever we have right now - this->free (); - // re-load screen info - this->loadScreenInfo (); + // first free whatever we have right now + this->free (); + // re-load screen info + this->loadScreenInfo (); } void CX11Output::free () { - // free all the resources we've got - XDestroyImage (this->m_image); - XFreeGC (this->m_display, this->m_gc); - XFreePixmap (this->m_display, this->m_pixmap); - delete this->m_imageData; - XCloseDisplay (this->m_display); + // free all the resources we've got + XDestroyImage (this->m_image); + XFreeGC (this->m_display, this->m_gc); + XFreePixmap (this->m_display, this->m_pixmap); + delete this->m_imageData; + XCloseDisplay (this->m_display); } void* CX11Output::getImageBuffer () const { - return this->m_imageData; + return this->m_imageData; } bool CX11Output::renderVFlip () const { - return false; + return false; } bool CX11Output::renderMultiple () const { - return this->m_viewports.size () > 1; + return this->m_viewports.size () > 1; } bool CX11Output::haveImageBuffer () const { - return true; + return true; } void CX11Output::loadScreenInfo () { - // reset the viewports - this->m_viewports.clear (); + // reset the viewports + this->m_viewports.clear (); - this->m_display = XOpenDisplay (nullptr); + this->m_display = XOpenDisplay (nullptr); // set the error handling to try and recover from X disconnections #ifdef HAVE_XSETIOERROREXITHANDLER XSetIOErrorExitHandler (this->m_display, CustomXIOErrorExitHandler, this); #endif /* HAVE_XSETIOERROREXITHANDLER */ - int xrandr_result, xrandr_error; + int xrandr_result, xrandr_error; - if (!XRRQueryExtension (this->m_display, &xrandr_result, &xrandr_error)) - { - sLog.error ("XRandr is not present, cannot detect specified screens, running in window mode"); - return; - } + if (!XRRQueryExtension (this->m_display, &xrandr_result, &xrandr_error)) + { + sLog.error ("XRandr is not present, cannot detect specified screens, running in window mode"); + return; + } - this->m_root = DefaultRootWindow (this->m_display); - this->m_fullWidth = DisplayWidth (this->m_display, DefaultScreen (this->m_display)); - this->m_fullHeight = DisplayHeight (this->m_display, DefaultScreen (this->m_display)); - XRRScreenResources* screenResources = XRRGetScreenResources (this->m_display, DefaultRootWindow (this->m_display)); + this->m_root = DefaultRootWindow (this->m_display); + this->m_fullWidth = DisplayWidth (this->m_display, DefaultScreen (this->m_display)); + this->m_fullHeight = DisplayHeight (this->m_display, DefaultScreen (this->m_display)); + XRRScreenResources* screenResources = XRRGetScreenResources (this->m_display, DefaultRootWindow (this->m_display)); - if (screenResources == nullptr) - { - sLog.error ("Cannot detect screen sizes using xrandr, running in window mode"); - return; - } + if (screenResources == nullptr) + { + sLog.error ("Cannot detect screen sizes using xrandr, running in window mode"); + return; + } - for (int i = 0; i < screenResources->noutput; i ++) - { - XRROutputInfo* info = XRRGetOutputInfo (this->m_display, screenResources, screenResources->outputs [i]); + for (int i = 0; i < screenResources->noutput; i ++) + { + XRROutputInfo* info = XRRGetOutputInfo (this->m_display, screenResources, screenResources->outputs [i]); - // screen not in use, ignore it - if (info == nullptr || info->connection != RR_Connected) - continue; + // screen not in use, ignore it + if (info == nullptr || info->connection != RR_Connected) + continue; - XRRCrtcInfo* crtc = XRRGetCrtcInfo (this->m_display, screenResources, info->crtc); + XRRCrtcInfo* crtc = XRRGetCrtcInfo (this->m_display, screenResources, info->crtc); - // add the screen to the list of screens - this->m_screens.push_back ( - { - {crtc->x, crtc->y, crtc->width, crtc->height}, - info->name - } - ); + // add the screen to the list of screens + this->m_screens.push_back ( + { + {crtc->x, crtc->y, crtc->width, crtc->height}, + info->name + } + ); - // only keep info of registered screens - if (this->m_context.screenSettings.find (info->name) != this->m_context.screenSettings.end ()) - { - sLog.out ("Found requested screen: ", info->name, " -> ", crtc->x, "x", crtc->y, ":", crtc->width, "x", crtc->height); + // only keep info of registered screens + if (this->m_context.general.screenBackgrounds.find (info->name) != this->m_context.general.screenBackgrounds.end ()) + { + sLog.out ("Found requested screen: ", info->name, " -> ", crtc->x, "x", crtc->y, ":", crtc->width, "x", crtc->height); - this->m_viewports[info->name] = - { - {crtc->x, crtc->y, crtc->width, crtc->height}, - info->name - }; - } + this->m_viewports[info->name] = + { + {crtc->x, crtc->y, crtc->width, crtc->height}, + info->name + }; + } - XRRFreeCrtcInfo (crtc); - } + XRRFreeCrtcInfo (crtc); + } - XRRFreeScreenResources (screenResources); + XRRFreeScreenResources (screenResources); - // create pixmap so we can draw things in there - this->m_pixmap = XCreatePixmap (this->m_display, this->m_root, this->m_fullWidth, this->m_fullHeight, 24); - this->m_gc = XCreateGC (this->m_display, this->m_pixmap, 0, nullptr); - // pre-fill it with black - XFillRectangle (this->m_display, this->m_pixmap, this->m_gc, 0, 0, this->m_fullWidth, this->m_fullHeight); - // set the window background as our pixmap - XSetWindowBackgroundPixmap (this->m_display, this->m_root, this->m_pixmap); - // allocate space for the image's data - this->m_imageData = new char [this->m_fullWidth * this->m_fullHeight * 4]; - // create an image so we can copy it over - this->m_image = XCreateImage (this->m_display, CopyFromParent, 24, ZPixmap, 0, this->m_imageData, this->m_fullWidth, this->m_fullHeight, 32, 0); - // setup driver's render changing the window's size - this->m_driver.resizeWindow ({this->m_fullWidth, this->m_fullHeight}); + // create pixmap so we can draw things in there + this->m_pixmap = XCreatePixmap (this->m_display, this->m_root, this->m_fullWidth, this->m_fullHeight, 24); + this->m_gc = XCreateGC (this->m_display, this->m_pixmap, 0, nullptr); + // pre-fill it with black + XFillRectangle (this->m_display, this->m_pixmap, this->m_gc, 0, 0, this->m_fullWidth, this->m_fullHeight); + // set the window background as our pixmap + XSetWindowBackgroundPixmap (this->m_display, this->m_root, this->m_pixmap); + // allocate space for the image's data + this->m_imageData = new char [this->m_fullWidth * this->m_fullHeight * 4]; + // create an image so we can copy it over + this->m_image = XCreateImage (this->m_display, CopyFromParent, 24, ZPixmap, 0, this->m_imageData, this->m_fullWidth, this->m_fullHeight, 32, 0); + // setup driver's render changing the window's size + this->m_driver.resizeWindow ({this->m_fullWidth, this->m_fullHeight}); } void CX11Output::updateRender () const @@ -189,46 +189,46 @@ void CX11Output::updateRender () const XClearWindow(this->m_display, this->m_root); XFlush(this->m_display); - // stop rendering if anything is fullscreen - bool isFullscreen = false; - XWindowAttributes attribs; - Window _; - Window* children; - unsigned int nchildren; + // stop rendering if anything is fullscreen + bool isFullscreen = false; + XWindowAttributes attribs; + Window _; + Window* children; + unsigned int nchildren; - do - { - isFullscreen = false; + do + { + isFullscreen = false; - if (!XQueryTree (this->m_display, this->m_root, &_, &_, &children, &nchildren)) - return; + if (!XQueryTree (this->m_display, this->m_root, &_, &_, &children, &nchildren)) + return; - for (int i = 0; i < nchildren; i++) - { - if (!XGetWindowAttributes (this->m_display, children [i], &attribs)) - continue; + for (int i = 0; i < nchildren; i++) + { + if (!XGetWindowAttributes (this->m_display, children [i], &attribs)) + continue; - if (attribs.map_state != IsViewable) - continue; + if (attribs.map_state != IsViewable) + continue; - // compare width and height with the different screens we have - for (const auto& screen : this->m_screens) - { - if ( - attribs.x == screen.viewport.x && attribs.y == screen.viewport.y && - attribs.width == screen.viewport.z && attribs.height == screen.viewport.w - ) - { - isFullscreen = true; - break; - } - } - } + // compare width and height with the different screens we have + for (const auto& screen : this->m_screens) + { + if ( + attribs.x == screen.viewport.x && attribs.y == screen.viewport.y && + attribs.width == screen.viewport.z && attribs.height == screen.viewport.w + ) + { + isFullscreen = true; + break; + } + } + } - XFree (children); + XFree (children); - // give the cpu some time to check again later - usleep (FULLSCREEN_CHECK_WAIT_TIME); - } - while (isFullscreen && g_KeepRunning); + // give the cpu some time to check again later + usleep (FULLSCREEN_CHECK_WAIT_TIME); + } + while (isFullscreen && g_KeepRunning); } diff --git a/src/WallpaperEngine/Render/Drivers/Output/CX11Output.h b/src/WallpaperEngine/Render/Drivers/Output/CX11Output.h index 2759847..d35b318 100644 --- a/src/WallpaperEngine/Render/Drivers/Output/CX11Output.h +++ b/src/WallpaperEngine/Render/Drivers/Output/CX11Output.h @@ -11,31 +11,31 @@ namespace WallpaperEngine::Render::Drivers::Output { - class CX11Output : public COutput - { - public: - CX11Output (CApplicationContext& context, CVideoDriver& driver); - ~CX11Output (); + class CX11Output : public COutput + { + public: + CX11Output (CApplicationContext& context, CVideoDriver& driver); + ~CX11Output (); - void reset () override; + void reset () override; - bool renderVFlip () const override; - bool renderMultiple () const override; - bool haveImageBuffer () const override; - void* getImageBuffer () const override; - void updateRender () const override; + bool renderVFlip () const override; + bool renderMultiple () const override; + bool haveImageBuffer () const override; + void* getImageBuffer () const override; + void updateRender () const override; - private: - void loadScreenInfo (); - void free (); + private: + void loadScreenInfo (); + void free (); - Display* m_display; - Pixmap m_pixmap; - Window m_root; - GC m_gc; - char* m_imageData; - XImage* m_image; - CVideoDriver& m_driver; - std::vector m_screens; - }; + Display* m_display; + Pixmap m_pixmap; + Window m_root; + GC m_gc; + char* m_imageData; + XImage* m_image; + CVideoDriver& m_driver; + std::vector m_screens; + }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Helpers/CContextAware.cpp b/src/WallpaperEngine/Render/Helpers/CContextAware.cpp new file mode 100644 index 0000000..ecd5593 --- /dev/null +++ b/src/WallpaperEngine/Render/Helpers/CContextAware.cpp @@ -0,0 +1,19 @@ +#include "CContextAware.h" + +namespace WallpaperEngine::Render::Helpers +{ + CContextAware::CContextAware (CContextAware& from) : + CContextAware (from.getContext ()) + { + } + + CContextAware::CContextAware (CRenderContext& context) : + m_context (context) + { + } + + CRenderContext& CContextAware::getContext () const + { + return this->m_context; + } +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Helpers/CContextAware.h b/src/WallpaperEngine/Render/Helpers/CContextAware.h new file mode 100644 index 0000000..cfa912e --- /dev/null +++ b/src/WallpaperEngine/Render/Helpers/CContextAware.h @@ -0,0 +1,31 @@ +#pragma once + +namespace WallpaperEngine::Render +{ + class CRenderContext; + + namespace Helpers + { + /** + * Small helper class that provides access to the CRenderContext + * in use currently + */ + class CContextAware + { + public: + /** + * @param from Object to get the render context from + */ + CContextAware (CContextAware& from); + explicit CContextAware (CRenderContext& context); + + /** + * @return The CRenderContext in use right now + */ + [[nodiscard]] CRenderContext& getContext () const; + + private: + CRenderContext& m_context; + }; + } +} \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Objects/CEffect.cpp b/src/WallpaperEngine/Render/Objects/CEffect.cpp index 39ce4b1..dbf1e6e 100644 --- a/src/WallpaperEngine/Render/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Render/Objects/CEffect.cpp @@ -40,6 +40,7 @@ void CEffect::generateFBOs () { for (const auto& cur : this->m_effect->getFbos ()) { + // TODO: IS THAT DIVISION OKAY? SHOULDN'T IT BE A MULTIPLICATION? WTF? this->m_fbos.push_back ( new CFBO ( cur->getName (), diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index c28c1da..01b4b82 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -7,20 +7,20 @@ using namespace WallpaperEngine::Render::Objects; CImage::CImage (CScene* scene, Core::Objects::CImage* image) : Render::CObject (scene, Type, image), m_image (image), - m_animationTime (0.0), - m_material (nullptr), - m_colorBlendMaterial (nullptr), + m_animationTime (0.0), + m_material (nullptr), + m_colorBlendMaterial (nullptr), m_texture (nullptr), m_initialized (false), - m_sceneSpacePosition (GL_NONE), - m_copySpacePosition (GL_NONE), - m_texcoordCopy (GL_NONE), - m_texcoordPass (GL_NONE), - m_passSpacePosition (GL_NONE), - m_modelViewProjectionScreen (), - m_modelViewProjectionCopy (), - m_modelViewProjectionPass (glm::mat4 (1.0)), - m_pos () + m_sceneSpacePosition (GL_NONE), + m_copySpacePosition (GL_NONE), + m_texcoordCopy (GL_NONE), + m_texcoordPass (GL_NONE), + m_passSpacePosition (GL_NONE), + m_modelViewProjectionScreen (), + m_modelViewProjectionCopy (), + m_modelViewProjectionPass (glm::mat4 (1.0)), + m_pos () { auto projection = this->getScene ()->getScene ()->getOrthogonalProjection (); @@ -102,7 +102,7 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) : // register both FBOs into the scene std::ostringstream nameA, nameB; - // TODO: determine when _rt_imageLayerComposite and _rt_imageLayerAlbedo is used + // TODO: determine when _rt_imageLayerComposite and _rt_imageLayerAlbedo is used nameA << "_rt_imageLayerComposite_" << this->getImage ()->getId () << "_a"; nameB << "_rt_imageLayerComposite_" << this->getImage ()->getId () << "_b"; @@ -163,10 +163,10 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) : width = static_cast (this->getTexture ()->getRealWidth ()) / static_cast (this->getTexture ()->getTextureWidth ()); height = static_cast (this->getTexture ()->getRealHeight ()) / static_cast (this->getTexture ()->getTextureHeight ()); } - // calculate the correct texCoord limits for the texture based on the texture screen size and real size + // calculate the correct texCoord limits for the texture based on the texture screen size and real size else if (this->getTexture () != nullptr && - (this->getTexture ()->getTextureWidth () != this->getTexture ()->getRealWidth () || - this->getTexture ()->getTextureHeight () != this->getTexture ()->getRealHeight ()) + (this->getTexture ()->getTextureWidth () != this->getTexture ()->getRealWidth () || + this->getTexture ()->getTextureHeight () != this->getTexture ()->getRealHeight ()) ) { uint32_t x = 1; @@ -232,7 +232,7 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) : glBufferData (GL_ARRAY_BUFFER, sizeof (texcoordPass), texcoordPass, GL_STATIC_DRAW); this->m_modelViewProjectionScreen = - this->getScene ()->getCamera ()->getProjection () * + this->getScene ()->getCamera ()->getProjection () * this->getScene ()->getCamera ()->getLookAt (); this->m_modelViewProjectionCopy = glm::ortho (0.0, size.x, 0.0, size.y); @@ -345,7 +345,7 @@ void CImage::setupPasses () // this one throws if no fbo was found drawTo = this->getScene ()->findFBO (target); } - // determine if it's the last element in the list as this is a screen-copy-like process + // determine if it's the last element in the list as this is a screen-copy-like process else if (std::next (cur) == end && this->getImage ()->isVisible ()) { // TODO: PROPERLY CHECK EFFECT'S VISIBILITY AND TAKE IT INTO ACCOUNT @@ -397,17 +397,17 @@ void CImage::render () this->updateScreenSpacePosition (); #if !NDEBUG - std::string str = "Rendering "; + std::string str = "Rendering "; - if (this->getScene ()->getScene ()->isBloom () && this->getId () == 0xFFFFFFFF) - str += "bloom"; - else - { - str += this->getImage ()->getName () + - " (" + std::to_string (this->getId ()) + ", " + this->getImage ()->getMaterial ()->getName () + ")"; - } + if (this->getScene ()->getScene ()->isBloom () && this->getId () == 0xFFFFFFFF) + str += "bloom"; + else + { + str += this->getImage ()->getName () + + " (" + std::to_string (this->getId ()) + ", " + this->getImage ()->getMaterial ()->getName () + ")"; + } - glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ()); + glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ()); #endif /* DEBUG */ auto cur = this->m_passes.begin (); @@ -423,7 +423,7 @@ void CImage::render () } #if !NDEBUG - glPopDebugGroup (); + glPopDebugGroup (); #endif /* DEBUG */ } @@ -442,7 +442,7 @@ void CImage::updateScreenSpacePosition () this->m_modelViewProjectionScreen = glm::translate ( this->getScene ()->getCamera ()->getProjection () * - this->getScene ()->getCamera ()->getLookAt (), + this->getScene ()->getCamera ()->getLookAt (), {x, y, 0.0f} ); } diff --git a/src/WallpaperEngine/Render/Objects/CSound.cpp b/src/WallpaperEngine/Render/Objects/CSound.cpp index 5f1819b..a2c923a 100644 --- a/src/WallpaperEngine/Render/Objects/CSound.cpp +++ b/src/WallpaperEngine/Render/Objects/CSound.cpp @@ -10,8 +10,8 @@ CSound::CSound (CScene* scene, Core::Objects::CSound* sound) : CObject (scene, Type, sound), m_sound (sound) { - if (g_AudioEnabled) - this->load (); + if (g_AudioEnabled) + this->load (); } void CSound::load () diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp index 5378ccf..8860168 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -50,7 +50,7 @@ const ITexture* CPass::resolveTexture (const ITexture* expected, int index, cons // a bind named "previous" is just another way of telling it to use whatever texture there was already if ((*it).second->getName () == "previous") - return previous ?: expected; + return previous ?: expected; // the bind actually has a name, search the FBO in the effect and return it auto fbo = this->m_material->m_effect->findFBO ((*it).second->getName ()); @@ -132,7 +132,7 @@ void CPass::render () if (texture->isAnimated ()) { // calculate current texture and frame - double currentRenderTime = fmod (static_cast (g_Time), this->m_material->getImage ()->getAnimationTime ()); + double currentRenderTime = fmod (static_cast (this->getMaterial ()->getImage ()->getScene ()->getContext ().getDriver ().getRenderTime ()), this->m_material->getImage ()->getAnimationTime ()); for (const auto& frameCur : texture->getFrames ()) { @@ -247,12 +247,12 @@ void CPass::render () glVertexAttribPointer (cur->id, cur->elements, cur->type, GL_FALSE, 0, nullptr); #if !NDEBUG - glObjectLabel (GL_BUFFER, *cur->value, -1, ( - "Image " + std::to_string (this->getMaterial ()->getImage ()->getId ()) + - " Pass " + this->m_pass->getShader() + - " " + cur->name - ).c_str () - ); + glObjectLabel (GL_BUFFER, *cur->value, -1, ( + "Image " + std::to_string (this->getMaterial ()->getImage ()->getId ()) + + " Pass " + this->m_pass->getShader() + + " " + cur->name + ).c_str () + ); #endif /* DEBUG */ } @@ -430,9 +430,9 @@ void CPass::setupShaders () } #if !NDEBUG - glObjectLabel (GL_PROGRAM, this->m_programID, -1, this->m_pass->getShader ().c_str ()); - glObjectLabel (GL_SHADER, vertexShaderID, -1, (this->m_pass->getShader () + ".vert").c_str ()); - glObjectLabel (GL_SHADER, fragmentShaderID, -1, (this->m_pass->getShader () + ".frag").c_str ()); + glObjectLabel (GL_PROGRAM, this->m_programID, -1, this->m_pass->getShader ().c_str ()); + glObjectLabel (GL_SHADER, vertexShaderID, -1, (this->m_pass->getShader () + ".vert").c_str ()); + glObjectLabel (GL_SHADER, fragmentShaderID, -1, (this->m_pass->getShader () + ".frag").c_str ()); #endif /* DEBUG */ // after being liked shaders can be dettached and deleted diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index b5a80d5..c118881 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -29,14 +29,14 @@ using namespace WallpaperEngine::Assets; namespace WallpaperEngine::Render::Shaders { Compiler::Compiler ( - CContainer* container, - std::string filename, - Type type, - std::map * combos, - std::map * foundCombos, - const std::vector & textures, - const std::map& constants, - bool recursive) : + CContainer* container, + std::string filename, + Type type, + std::map * combos, + std::map * foundCombos, + const std::vector & textures, + const std::map& constants, + bool recursive) : m_combos (combos), m_foundCombos (foundCombos), m_passTextures (textures), @@ -246,7 +246,7 @@ namespace WallpaperEngine::Render::Shaders void Compiler::precompile() { // TODO: SEPARATE THIS IN TWO SO THE COMBOS ARE DETECTED FIRST AND WE DO NOT REQUIRE DOUBLE COMPILATION OF THE SHADER'S SOURCE - #define BREAK_IF_ERROR if (this->m_error) { sLog.exception ("ERROR PRE-COMPILING SHADER.", this->m_errorInfo); } +#define BREAK_IF_ERROR if (this->m_error) { sLog.exception ("ERROR PRE-COMPILING SHADER.", this->m_errorInfo); } // parse the shader and find #includes and such things and translate them to the correct name // also remove any #version definition to prevent errors std::string::const_iterator it = this->m_content.begin (); @@ -323,21 +323,21 @@ namespace WallpaperEngine::Render::Shaders // parse the parameter information this->parseParameterConfiguration (type, name, configuration); BREAK_IF_ERROR this->m_compiledContent += "uniform "; - this->m_compiledContent += type; - this->m_compiledContent += " "; - this->m_compiledContent += name; - this->m_compiledContent += array; - this->m_compiledContent += "; // "; - this->m_compiledContent += configuration; + this->m_compiledContent += type; + this->m_compiledContent += " "; + this->m_compiledContent += name; + this->m_compiledContent += array; + this->m_compiledContent += "; // "; + this->m_compiledContent += configuration; } else { this->m_compiledContent += "uniform "; - this->m_compiledContent += type; - this->m_compiledContent += " "; - this->m_compiledContent += name; - this->m_compiledContent += array; - this->m_compiledContent += ";"; + this->m_compiledContent += type; + this->m_compiledContent += " "; + this->m_compiledContent += name; + this->m_compiledContent += array; + this->m_compiledContent += ";"; } } else @@ -506,8 +506,8 @@ namespace WallpaperEngine::Render::Shaders "// ======================================================\n" "precision highp float;\n" "#define mul(x, y) ((y) * (x))\n" - "#define max(x, y) max (y, x)\n" - "#define lerp mix\n" + "#define max(x, y) max (y, x)\n" + "#define lerp mix\n" "#define frac fract\n" "#define CAST2(x) (vec2(x))\n" "#define CAST3(x) (vec3(x))\n" @@ -517,21 +517,21 @@ namespace WallpaperEngine::Render::Shaders "#define texSample2D texture\n" "#define texSample2DLod textureLod\n" "#define atan2 atan\n" - "#define fmod(x, y) ((x)-(y)*trunc((x)/(y)))\n" + "#define fmod(x, y) ((x)-(y)*trunc((x)/(y)))\n" "#define ddx dFdx\n" "#define ddy(x) dFdy(-(x))\n" "#define GLSL 1\n\n"; - if (this->m_type == Type_Vertex) - { - finalCode += "#define attribute in\n" - "#define varying out\n"; - } - else - { - finalCode += "out vec4 out_FragColor;\n" - "#define varying in\n"; - } + if (this->m_type == Type_Vertex) + { + finalCode += "#define attribute in\n" + "#define varying out\n"; + } + else + { + finalCode += "out vec4 out_FragColor;\n" + "#define varying in\n"; + } finalCode += "// ======================================================\n" "// Shader combo parameter definitions\n" @@ -559,69 +559,69 @@ namespace WallpaperEngine::Render::Shaders finalCode += "#define " + cur.first + " " + std::to_string (cur.second) + "\n"; } - // define to 0 everything else found in the code - std::regex ifs ("#if ([A-Za-z0-9_]+)"); - auto words_begin = std::sregex_iterator (this->m_compiledContent.begin (), this->m_compiledContent.end (), ifs); - auto words_end = std::sregex_iterator (); - std::map inserted; + // define to 0 everything else found in the code + std::regex ifs ("#if ([A-Za-z0-9_]+)"); + auto words_begin = std::sregex_iterator (this->m_compiledContent.begin (), this->m_compiledContent.end (), ifs); + auto words_end = std::sregex_iterator (); + std::map inserted; - for (; words_begin != words_end; words_begin ++) - { - std::string define = (*words_begin).str ().substr (4); + for (; words_begin != words_end; words_begin ++) + { + std::string define = (*words_begin).str ().substr (4); - if ( - this->m_foundCombos->find (define) != this->m_foundCombos->end () || - this->m_baseCombos.find (define) != this->m_baseCombos.end () || - inserted.find (define) != inserted.end ()) - continue; + if ( + this->m_foundCombos->find (define) != this->m_foundCombos->end () || + this->m_baseCombos.find (define) != this->m_baseCombos.end () || + inserted.find (define) != inserted.end ()) + continue; - finalCode += "#define " + define + " 0\n"; + finalCode += "#define " + define + " 0\n"; - inserted.insert_or_assign (define, true); - } + inserted.insert_or_assign (define, true); + } } - // replace gl_FragColor with the equivalent - std::string from = "gl_FragColor"; - std::string to = "out_FragColor"; + // replace gl_FragColor with the equivalent + std::string from = "gl_FragColor"; + std::string to = "out_FragColor"; - size_t start_pos = 0; - while((start_pos = this->m_compiledContent.find(from, start_pos)) != std::string::npos) { - this->m_compiledContent.replace(start_pos, from.length(), to); - start_pos += to.length(); // Handles case where 'to' is a substring of 'from' - } + size_t start_pos = 0; + while((start_pos = this->m_compiledContent.find(from, start_pos)) != std::string::npos) { + this->m_compiledContent.replace(start_pos, from.length(), to); + start_pos += to.length(); // Handles case where 'to' is a substring of 'from' + } - // replace sample occurrences - from = "sample"; - to = "_sample"; + // replace sample occurrences + from = "sample"; + to = "_sample"; - start_pos = 0; - while((start_pos = this->m_compiledContent.find(from, start_pos)) != std::string::npos) { - // ensure that after it comes something like a space or a ; or a tab - std::string after = this->m_compiledContent.substr (start_pos + from.length (), 1); + start_pos = 0; + while((start_pos = this->m_compiledContent.find(from, start_pos)) != std::string::npos) { + // ensure that after it comes something like a space or a ; or a tab + std::string after = this->m_compiledContent.substr (start_pos + from.length (), 1); - if ( - after != " " && after != ";" && after != "\t" && - after != "=" && after != "+" && after != "-" && - after != "/" && after != "*" && after != "." && - after != "," && after != ")") - { - start_pos += to.length(); // Handles case where 'to' is a substring of 'from' - continue; - } + if ( + after != " " && after != ";" && after != "\t" && + after != "=" && after != "+" && after != "-" && + after != "/" && after != "*" && after != "." && + after != "," && after != ")") + { + start_pos += to.length(); // Handles case where 'to' is a substring of 'from' + continue; + } - this->m_compiledContent.replace(start_pos, from.length(), to); - start_pos += to.length(); // Handles case where 'to' is a substring of 'from' - } + this->m_compiledContent.replace(start_pos, from.length(), to); + start_pos += to.length(); // Handles case where 'to' is a substring of 'from' + } - try - { - this->applyPatches (); - } - catch (CAssetLoadException&) - { - // nothing important, no patch was found - } + try + { + this->applyPatches (); + } + catch (CAssetLoadException&) + { + // nothing important, no patch was found + } finalCode += this->m_compiledContent; @@ -633,59 +633,59 @@ namespace WallpaperEngine::Render::Shaders // store the final final code here this->m_compiledContent = finalCode; - #undef BREAK_IF_ERROR +#undef BREAK_IF_ERROR } - void Compiler::applyPatches () - { - // small patches for things, looks like the official wpengine does the same thing - std::filesystem::path file = this->m_file; - file = "patches" / file.filename (); + void Compiler::applyPatches () + { + // small patches for things, looks like the official wpengine does the same thing + std::filesystem::path file = this->m_file; + file = "patches" / file.filename (); - if (this->m_type == Type_Vertex) - file += ".vert"; - else if (this->m_type == Type_Pixel) - file += ".frag"; + if (this->m_type == Type_Vertex) + file += ".vert"; + else if (this->m_type == Type_Pixel) + file += ".frag"; - file += ".json"; + file += ".json"; - std::string tmp = file; - std::string patchContents = this->m_container->readFileAsString (file); + std::string tmp = file; + std::string patchContents = this->m_container->readFileAsString (file); - json data = json::parse (patchContents); - auto patches = data.find ("patches"); + json data = json::parse (patchContents); + auto patches = data.find ("patches"); - for (auto patch : *patches) - { - auto matches = patch.find ("matches"); + for (auto patch : *patches) + { + auto matches = patch.find ("matches"); - // check for matches first, as these signal whether the patch can be applied or not - for (const auto& match : *matches) - if (this->m_compiledContent.find (match) == std::string::npos) - continue; + // check for matches first, as these signal whether the patch can be applied or not + for (const auto& match : *matches) + if (this->m_compiledContent.find (match) == std::string::npos) + continue; - auto replacements = patch.find ("replacements"); + auto replacements = patch.find ("replacements"); - for (const auto& replacement : (*replacements).items ()) - { - // replace gl_FragColor with the equivalent - std::string from = replacement.key (); - std::string to = replacement.value (); + for (const auto& replacement : (*replacements).items ()) + { + // replace gl_FragColor with the equivalent + std::string from = replacement.key (); + std::string to = replacement.value (); - size_t start_pos = 0; - while((start_pos = this->m_compiledContent.find(from, start_pos)) != std::string::npos) { - this->m_compiledContent.replace(start_pos, from.length(), to); - start_pos += to.length(); // Handles case where 'to' is a substring of 'from' - } - } - } - } + size_t start_pos = 0; + while((start_pos = this->m_compiledContent.find(from, start_pos)) != std::string::npos) { + this->m_compiledContent.replace(start_pos, from.length(), to); + start_pos += to.length(); // Handles case where 'to' is a substring of 'from' + } + } + } + } void Compiler::parseComboConfiguration (const std::string& content, int defaultValue) { json data = json::parse (content); auto combo = jsonFindRequired (data, "combo", "cannot parse combo information"); - auto type = data.find ("type"); + auto type = data.find ("type"); auto defvalue = data.find ("default"); // add line feed just in case @@ -701,39 +701,39 @@ namespace WallpaperEngine::Render::Shaders // so only define the ones that are not already defined if (entry == this->m_combos->end ()) { - if (type != data.end () && (*type) == "audioprocessingoptions") - { - sLog.out ("Found audioprocessing value, nothing working yet"); - this->m_combos->insert (std::make_pair (*combo, 1)); - } - else - { - if (type != data.end ()) - sLog.error ("Resorting to default value as type ", *type, " is unknown"); + if (type != data.end () && (*type) == "audioprocessingoptions") + { + sLog.out ("Found audioprocessing value, nothing working yet"); + this->m_combos->insert (std::make_pair (*combo, 1)); + } + else + { + if (type != data.end ()) + sLog.error ("Resorting to default value as type ", *type, " is unknown"); - // if no combo is defined just load the default settings - if (defvalue == data.end ()) - { - // TODO: PROPERLY SUPPORT EMPTY COMBOS - this->m_combos->insert (std::make_pair (*combo, (int) defaultValue)); - } - else if ((*defvalue).is_number_float ()) - { - sLog.exception ("float combos are not supported in shader ", this->m_file, ". ", *combo); - } - else if ((*defvalue).is_number_integer ()) - { - this->m_combos->insert (std::make_pair (*combo, (*defvalue).get ())); - } - else if ((*defvalue).is_string ()) - { - sLog.exception ("string combos are not supported in shader ", this->m_file, ". ", *combo); - } - else - { - sLog.exception ("cannot parse combo information ", *combo, ". unknown type for ", defvalue->dump ()); - } - } + // if no combo is defined just load the default settings + if (defvalue == data.end ()) + { + // TODO: PROPERLY SUPPORT EMPTY COMBOS + this->m_combos->insert (std::make_pair (*combo, (int) defaultValue)); + } + else if ((*defvalue).is_number_float ()) + { + sLog.exception ("float combos are not supported in shader ", this->m_file, ". ", *combo); + } + else if ((*defvalue).is_number_integer ()) + { + this->m_combos->insert (std::make_pair (*combo, (*defvalue).get ())); + } + else if ((*defvalue).is_string ()) + { + sLog.exception ("string combos are not supported in shader ", this->m_file, ". ", *combo); + } + else + { + sLog.exception ("cannot parse combo information ", *combo, ". unknown type for ", defvalue->dump ()); + } + } } } @@ -879,11 +879,11 @@ namespace WallpaperEngine::Render::Shaders } std::vector Compiler::sTypes = - { - "vec4", "uvec4", "ivec4", "dvec4", "bvec4", - "vec3", "uvec3", "ivec3", "dvec3", "bvec3", - "vec2", "uvec2", "ivec2", "dvec2", "bvec2", - "float", "sampler2D", "mat4x3", "mat4", "mat3", "uint4", - "void" - }; + { + "vec4", "uvec4", "ivec4", "dvec4", "bvec4", + "vec3", "uvec3", "ivec3", "dvec3", "bvec3", + "vec2", "uvec2", "ivec2", "dvec2", "bvec2", + "float", "sampler2D", "mat4x3", "mat4", "mat3", "uint4", + "void" + }; } diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.h b/src/WallpaperEngine/Render/Shaders/Compiler.h index 99670b8..356e0cf 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.h +++ b/src/WallpaperEngine/Render/Shaders/Compiler.h @@ -199,10 +199,10 @@ namespace WallpaperEngine::Render::Shaders * @param content The parameter configuration */ void parseParameterConfiguration (const std::string& type, const std::string& name, const std::string& content); - /** - * Applies any available patches for this shader - */ - void applyPatches (); + /** + * Applies any available patches for this shader + */ + void applyPatches (); /** * The shader file this instance is loading @@ -237,38 +237,38 @@ namespace WallpaperEngine::Render::Shaders /** * The combos the shader should be generated with */ - std::map * m_combos; + std::map * m_combos; - /** - * Combos that come from the pass' chain that should be added - */ - std::map m_baseCombos; + /** + * Combos that come from the pass' chain that should be added + */ + std::map m_baseCombos; - /** - * The combos the shader code has defined (shared between fragment and vertex) - */ - std::map * m_foundCombos; + /** + * The combos the shader code has defined (shared between fragment and vertex) + */ + std::map * m_foundCombos; - /** - * The list of textures the pass knows about - */ - const std::vector m_passTextures; - /** - * The shader constants with values for variables inside the shader - */ - const std::map& m_constants; - /** - * Whether this compilation is a recursive one or not - */ - bool m_recursive; - /** - * The container to load files from - */ - CContainer* m_container; - /** - * List of textures that the shader expects (inferred from sampler2D and it's JSON data) - */ - std::map m_textures; - bool m_includesProcessed = false; + /** + * The list of textures the pass knows about + */ + const std::vector m_passTextures; + /** + * The shader constants with values for variables inside the shader + */ + const std::map& m_constants; + /** + * Whether this compilation is a recursive one or not + */ + bool m_recursive; + /** + * The container to load files from + */ + CContainer* m_container; + /** + * List of textures that the shader expects (inferred from sampler2D and it's JSON data) + */ + std::map m_textures; + bool m_includesProcessed = false; }; }