refactor: update render to use new data model

This commit is contained in:
Almamu 2025-08-13 08:50:34 +02:00
parent 73f716da84
commit 2569960681
101 changed files with 757 additions and 3593 deletions

View File

@ -261,9 +261,6 @@ add_executable(
src/WallpaperEngine/Logging/CLog.cpp src/WallpaperEngine/Logging/CLog.cpp
src/WallpaperEngine/Logging/CLog.h src/WallpaperEngine/Logging/CLog.h
src/WallpaperEngine/PrettyPrinter/CPrettyPrinter.cpp
src/WallpaperEngine/PrettyPrinter/CPrettyPrinter.h
src/WallpaperEngine/Application/CApplicationContext.cpp src/WallpaperEngine/Application/CApplicationContext.cpp
src/WallpaperEngine/Application/CApplicationContext.h src/WallpaperEngine/Application/CApplicationContext.h
src/WallpaperEngine/Application/CWallpaperApplication.cpp src/WallpaperEngine/Application/CWallpaperApplication.cpp
@ -361,6 +358,8 @@ add_executable(
src/WallpaperEngine/Render/CRenderContext.cpp src/WallpaperEngine/Render/CRenderContext.cpp
src/WallpaperEngine/Render/CTextureCache.h src/WallpaperEngine/Render/CTextureCache.h
src/WallpaperEngine/Render/CTextureCache.cpp src/WallpaperEngine/Render/CTextureCache.cpp
src/WallpaperEngine/Render/CFBOProvider.cpp
src/WallpaperEngine/Render/CFBOProvider.h
src/WallpaperEngine/Render/Helpers/CContextAware.cpp src/WallpaperEngine/Render/Helpers/CContextAware.cpp
src/WallpaperEngine/Render/Helpers/CContextAware.h src/WallpaperEngine/Render/Helpers/CContextAware.h
@ -384,15 +383,11 @@ add_executable(
src/WallpaperEngine/Render/Objects/CImage.cpp src/WallpaperEngine/Render/Objects/CImage.cpp
src/WallpaperEngine/Render/Objects/CSound.h src/WallpaperEngine/Render/Objects/CSound.h
src/WallpaperEngine/Render/Objects/CSound.cpp src/WallpaperEngine/Render/Objects/CSound.cpp
src/WallpaperEngine/Render/Objects/CEffect.h
src/WallpaperEngine/Render/Objects/CEffect.cpp
src/WallpaperEngine/Render/CFBO.h src/WallpaperEngine/Render/CFBO.h
src/WallpaperEngine/Render/CFBO.cpp src/WallpaperEngine/Render/CFBO.cpp
src/WallpaperEngine/Render/Objects/Effects/CPass.h src/WallpaperEngine/Render/Objects/Effects/CPass.h
src/WallpaperEngine/Render/Objects/Effects/CPass.cpp src/WallpaperEngine/Render/Objects/Effects/CPass.cpp
src/WallpaperEngine/Render/Objects/Effects/CMaterial.h
src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp
src/WallpaperEngine/WebBrowser/CEF/CRenderHandler.cpp src/WallpaperEngine/WebBrowser/CEF/CRenderHandler.cpp
src/WallpaperEngine/WebBrowser/CEF/CRenderHandler.h src/WallpaperEngine/WebBrowser/CEF/CRenderHandler.h
@ -421,19 +416,6 @@ add_executable(
src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp
src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h
src/WallpaperEngine/Core/CProject.cpp
src/WallpaperEngine/Core/CProject.h
src/WallpaperEngine/Core/CWallpaper.cpp
src/WallpaperEngine/Core/CWallpaper.h
src/WallpaperEngine/Core/Wallpapers/CScene.cpp
src/WallpaperEngine/Core/Wallpapers/CScene.h
src/WallpaperEngine/Core/Wallpapers/CVideo.cpp
src/WallpaperEngine/Core/Wallpapers/CVideo.h
src/WallpaperEngine/Core/Wallpapers/CWeb.cpp
src/WallpaperEngine/Core/Wallpapers/CWeb.h
src/WallpaperEngine/Core/CObject.cpp
src/WallpaperEngine/Core/CObject.h
src/WallpaperEngine/Core/Projects/CProperty.h src/WallpaperEngine/Core/Projects/CProperty.h
src/WallpaperEngine/Core/Projects/CProperty.cpp src/WallpaperEngine/Core/Projects/CProperty.cpp
src/WallpaperEngine/Core/Projects/CPropertyColor.h src/WallpaperEngine/Core/Projects/CPropertyColor.h
@ -447,24 +429,8 @@ add_executable(
src/WallpaperEngine/Core/Projects/CPropertyText.h src/WallpaperEngine/Core/Projects/CPropertyText.h
src/WallpaperEngine/Core/Projects/CPropertyText.cpp src/WallpaperEngine/Core/Projects/CPropertyText.cpp
src/WallpaperEngine/Core/Scenes/CCamera.cpp # src/WallpaperEngine/Core/Objects/CParticle.cpp
src/WallpaperEngine/Core/Scenes/CCamera.h # src/WallpaperEngine/Core/Objects/CParticle.h
src/WallpaperEngine/Core/Scenes/CProjection.cpp
src/WallpaperEngine/Core/Scenes/CProjection.h
src/WallpaperEngine/Core/Objects/CImage.cpp
src/WallpaperEngine/Core/Objects/CImage.h
src/WallpaperEngine/Core/Objects/CSound.cpp
src/WallpaperEngine/Core/Objects/CSound.h
src/WallpaperEngine/Core/Objects/CEffect.cpp
src/WallpaperEngine/Core/Objects/CEffect.h
src/WallpaperEngine/Core/Objects/CParticle.cpp
src/WallpaperEngine/Core/Objects/CParticle.h
src/WallpaperEngine/Core/Objects/Effects/CFBO.h
src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp
src/WallpaperEngine/Core/Objects/Effects/CBind.h
src/WallpaperEngine/Core/Objects/Effects/CBind.cpp
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp
@ -481,35 +447,29 @@ add_executable(
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantProperty.h src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantProperty.h
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantProperty.cpp src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantProperty.cpp
src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp # src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp
src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h # src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h
src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp # src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp
src/WallpaperEngine/Core/Objects/Particles/CEmitter.h # src/WallpaperEngine/Core/Objects/Particles/CEmitter.h
src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp # src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp
src/WallpaperEngine/Core/Objects/Particles/CInitializer.h # src/WallpaperEngine/Core/Objects/Particles/CInitializer.h
#
src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp # src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp
src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h # src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h
src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp # src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp
src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h # src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h
src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp # src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp
src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h # src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h
src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp # src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp
src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h # src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h
src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp # src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp
src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h # src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h
src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp # src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp
src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h # src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h
src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp # src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp
src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h # src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h
src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp # src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp
src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h # src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h
src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp
src/WallpaperEngine/Core/Objects/Images/CMaterial.h
src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp
src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h
src/WallpaperEngine/Data/Model/Types.h src/WallpaperEngine/Data/Model/Types.h
src/WallpaperEngine/Data/Model/Project.h src/WallpaperEngine/Data/Model/Project.h
@ -541,11 +501,11 @@ add_executable(
${WAYLAND_SOURCES} ${WAYLAND_SOURCES}
${X11_SOURCES} ${X11_SOURCES}
${DEMOMODE_SOURCES} ${DEMOMODE_SOURCES}
src/WallpaperEngine/Data/Dumpers/StringPrinter.cpp src/WallpaperEngine/Data/Dumpers/StringPrinter.cpp
src/WallpaperEngine/Data/Dumpers/StringPrinter.h src/WallpaperEngine/Data/Dumpers/StringPrinter.h
src/WallpaperEngine/Data/JSON.cpp src/WallpaperEngine/Data/JSON.cpp
src/WallpaperEngine/Data/Parsers/EffectParser.cpp src/WallpaperEngine/Data/Parsers/EffectParser.cpp
src/WallpaperEngine/Data/Parsers/EffectParser.h) src/WallpaperEngine/Data/Parsers/EffectParser.h)
target_link_libraries (linux-wallpaperengine PUBLIC target_link_libraries (linux-wallpaperengine PUBLIC
${OPENGL_LIBRARIES} ${OPENGL_LIBRARIES}

View File

@ -12,6 +12,8 @@
#include "WallpaperEngine/Assets/ITexture.h" #include "WallpaperEngine/Assets/ITexture.h"
#include "WallpaperEngine/Render/CWallpaperState.h" #include "WallpaperEngine/Render/CWallpaperState.h"
#include "WallpaperEngine/Data/Model/Project.h"
namespace WallpaperEngine::Application { namespace WallpaperEngine::Application {
/** /**
* Application information as parsed off the command line arguments * Application information as parsed off the command line arguments

View File

@ -8,13 +8,13 @@
#include "WallpaperEngine/Audio/Drivers/Detectors/CPulseAudioPlayingDetector.h" #include "WallpaperEngine/Audio/Drivers/Detectors/CPulseAudioPlayingDetector.h"
#include "WallpaperEngine/Logging/CLog.h" #include "WallpaperEngine/Logging/CLog.h"
#include "WallpaperEngine/Render/CRenderContext.h" #include "WallpaperEngine/Render/CRenderContext.h"
#include "WallpaperEngine/PrettyPrinter/CPrettyPrinter.h"
#include "WallpaperEngine/Core/Wallpapers/CWeb.h"
#include "WallpaperEngine/Render/Drivers/CVideoFactories.h" #include "WallpaperEngine/Render/Drivers/CVideoFactories.h"
#include "WallpaperEngine/Data/Parsers/ProjectParser.h" #include "WallpaperEngine/Data/Parsers/ProjectParser.h"
#include "WallpaperEngine/Data/Dumpers/StringPrinter.h" #include "WallpaperEngine/Data/Dumpers/StringPrinter.h"
#include "WallpaperEngine/Data/Model/Wallpaper.h"
#if DEMOMODE #if DEMOMODE
#include "recording.h" #include "recording.h"
#endif /* DEMOMODE */ #endif /* DEMOMODE */
@ -29,7 +29,9 @@ float g_Time;
float g_TimeLast; float g_TimeLast;
float g_Daytime; float g_Daytime;
namespace WallpaperEngine::Application { using namespace WallpaperEngine::Application;
using namespace WallpaperEngine::Data::Model;
CWallpaperApplication::CWallpaperApplication (CApplicationContext& context) : CWallpaperApplication::CWallpaperApplication (CApplicationContext& context) :
m_context (context) { m_context (context) {
this->loadBackgrounds (); this->loadBackgrounds ();
@ -37,7 +39,8 @@ CWallpaperApplication::CWallpaperApplication (CApplicationContext& context) :
this->setupBrowser(); this->setupBrowser();
} }
void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedContainer>& container, const std::string& bg) const { ContainerUniquePtr CWallpaperApplication::setupContainer (const std::string& bg) const {
auto container = std::make_unique <CCombinedContainer> ();
const std::filesystem::path basepath = bg; const std::filesystem::path basepath = bg;
container->add (std::make_unique<CDirectory> (basepath)); container->add (std::make_unique<CDirectory> (basepath));
@ -185,6 +188,8 @@ void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedConta
); );
container->add (std::move(virtualContainer)); container->add (std::move(virtualContainer));
return container;
} }
void CWallpaperApplication::loadBackgrounds () { void CWallpaperApplication::loadBackgrounds () {
@ -204,27 +209,16 @@ void CWallpaperApplication::loadBackgrounds () {
} }
} }
std::shared_ptr<Core::CProject> CWallpaperApplication::loadBackground (const std::string& bg) { ProjectUniquePtr CWallpaperApplication::loadBackground (const std::string& bg) {
const auto container = std::make_shared <CCombinedContainer> (); auto container = this->setupContainer (bg);
this->setupContainer (container, bg);
// do the parsing with the new parser first
auto json = WallpaperEngine::Data::JSON::JSON::parse (container->readFileAsString ("project.json")); auto json = WallpaperEngine::Data::JSON::JSON::parse (container->readFileAsString ("project.json"));
const auto project = WallpaperEngine::Data::Parsers::ProjectParser::parse (json, container);
auto dumper = WallpaperEngine::Data::Dumpers::StringPrinter (); return WallpaperEngine::Data::Parsers::ProjectParser::parse (json, std::move(container));
dumper.printWallpaper (*project->wallpaper);
std::cout << dumper.str () << std::endl;
return Core::CProject::fromFile ("project.json", container);
} }
void CWallpaperApplication::setupPropertiesForProject (const std::shared_ptr<const Core::CProject>& project) { void CWallpaperApplication::setupPropertiesForProject (const Project& project) {
// show properties if required // show properties if required
for (const auto& [key, cur] : project->getProperties ()) { for (const auto& [key, cur] : project.properties) {
// update the value of the property // update the value of the property
auto override = this->m_context.settings.general.properties.find (key); auto override = this->m_context.settings.general.properties.find (key);
@ -241,15 +235,16 @@ void CWallpaperApplication::setupPropertiesForProject (const std::shared_ptr<con
void CWallpaperApplication::setupProperties () { void CWallpaperApplication::setupProperties () {
for (const auto& [background, info] : this->m_backgrounds) for (const auto& [background, info] : this->m_backgrounds)
this->setupPropertiesForProject (info); this->setupPropertiesForProject (*info);
} }
void CWallpaperApplication::setupBrowser () { void CWallpaperApplication::setupBrowser () {
bool anyWebProject = std::any_of ( bool anyWebProject = std::any_of (
this->m_backgrounds.begin (), this->m_backgrounds.end (), this->m_backgrounds.begin (), this->m_backgrounds.end (),
[](const std::pair<const std::string, std::shared_ptr<const Core::CProject>>& pair) -> bool { [](const std::pair<const std::string, ProjectUniquePtr>& pair) -> bool {
return pair.second->getWallpaper()->is<Core::Wallpapers::CWeb> (); return pair.second->wallpaper->is<Web> ();
}); }
);
// do not perform any initialization if no web background is present // do not perform any initialization if no web background is present
if (!anyWebProject) { if (!anyWebProject) {
@ -350,9 +345,12 @@ void CWallpaperApplication::setupOutput () {
void CWallpaperApplication::setupAudio () { void CWallpaperApplication::setupAudio () {
// ensure audioprocessing is required by any background, and we have it enabled // ensure audioprocessing is required by any background, and we have it enabled
bool audioProcessingRequired = std::any_of (this->m_backgrounds.begin (), this->m_backgrounds.end (), [](const auto& pair) -> bool { bool audioProcessingRequired = std::any_of (
return pair.second->supportsAudioProcessing (); this->m_backgrounds.begin (), this->m_backgrounds.end (),
}); [](const std::pair<const std::string, ProjectUniquePtr>& pair) -> bool {
return pair.second->supportsAudioProcessing;
}
);
if (audioProcessingRequired && this->m_context.settings.audio.audioprocessing) { if (audioProcessingRequired && this->m_context.settings.audio.audioprocessing) {
this->m_audioRecorder = std::make_unique <WallpaperEngine::Audio::Drivers::Recorders::CPulseAudioPlaybackRecorder> (); this->m_audioRecorder = std::make_unique <WallpaperEngine::Audio::Drivers::Recorders::CPulseAudioPlaybackRecorder> ();
@ -382,7 +380,7 @@ void CWallpaperApplication::prepareOutputs () {
m_renderContext->setWallpaper ( m_renderContext->setWallpaper (
background, background,
WallpaperEngine::Render::CWallpaper::fromWallpaper ( WallpaperEngine::Render::CWallpaper::fromWallpaper (
info->getWallpaper (), *m_renderContext, *m_audioContext, m_browserContext.get (), *info->wallpaper, *m_renderContext, *m_audioContext, m_browserContext.get (),
this->m_context.settings.general.screenScalings [background], this->m_context.settings.general.screenScalings [background],
this->m_context.settings.general.screenClamps [background] this->m_context.settings.general.screenClamps [background]
) )
@ -399,6 +397,8 @@ void CWallpaperApplication::show () {
static struct tm* timeinfo; static struct tm* timeinfo;
if (this->m_context.settings.general.dumpStructure) { if (this->m_context.settings.general.dumpStructure) {
// TODO: REWRITE TO USE THE NEW DUMPER
/*
auto prettyPrinter = PrettyPrinter::CPrettyPrinter (); auto prettyPrinter = PrettyPrinter::CPrettyPrinter ();
for (const auto& [background, info] : this->m_renderContext->getWallpapers ()) { for (const auto& [background, info] : this->m_renderContext->getWallpapers ()) {
@ -406,6 +406,7 @@ void CWallpaperApplication::show () {
} }
std::cout << prettyPrinter.str () << std::endl; std::cout << prettyPrinter.str () << std::endl;
*/
} }
#if DEMOMODE #if DEMOMODE
@ -506,7 +507,7 @@ void CWallpaperApplication::signal (int signal) {
this->m_context.state.general.keepRunning = false; this->m_context.state.general.keepRunning = false;
} }
const std::map<std::string, std::shared_ptr<Core::CProject>>& CWallpaperApplication::getBackgrounds () const { const std::map<std::string, ProjectUniquePtr>& CWallpaperApplication::getBackgrounds () const {
return this->m_backgrounds; return this->m_backgrounds;
} }
@ -517,4 +518,3 @@ CApplicationContext& CWallpaperApplication::getContext () const {
const WallpaperEngine::Render::Drivers::Output::COutput& CWallpaperApplication::getOutput () const { const WallpaperEngine::Render::Drivers::Output::COutput& CWallpaperApplication::getOutput () const {
return this->m_renderContext->getOutput (); return this->m_renderContext->getOutput ();
} }
} // namespace WallpaperEngine::Application

View File

@ -4,8 +4,6 @@
#include "WallpaperEngine/Assets/CCombinedContainer.h" #include "WallpaperEngine/Assets/CCombinedContainer.h"
#include "WallpaperEngine/Core/CProject.h"
#include "WallpaperEngine/Render/CRenderContext.h" #include "WallpaperEngine/Render/CRenderContext.h"
#include "WallpaperEngine/Render/CWallpaper.h" #include "WallpaperEngine/Render/CWallpaper.h"
#include "WallpaperEngine/Render/Drivers/CGLFWOpenGLDriver.h" #include "WallpaperEngine/Render/Drivers/CGLFWOpenGLDriver.h"
@ -17,7 +15,10 @@
#include "WallpaperEngine/Input/CInputContext.h" #include "WallpaperEngine/Input/CInputContext.h"
#include "WallpaperEngine/WebBrowser/CWebBrowserContext.h" #include "WallpaperEngine/WebBrowser/CWebBrowserContext.h"
#include "WallpaperEngine/Data/Model/Types.h"
namespace WallpaperEngine::Application { namespace WallpaperEngine::Application {
using namespace WallpaperEngine::Data::Model;
/** /**
* Small wrapper class over the actual wallpaper's main application skeleton * Small wrapper class over the actual wallpaper's main application skeleton
* *
@ -40,7 +41,7 @@ class CWallpaperApplication {
/** /**
* @return Maps screens to loaded backgrounds * @return Maps screens to loaded backgrounds
*/ */
[[nodiscard]] const std::map<std::string, std::shared_ptr<Core::CProject>>& getBackgrounds () const; [[nodiscard]] const std::map<std::string, ProjectUniquePtr>& getBackgrounds () const;
/** /**
* @return The current application context * @return The current application context
*/ */
@ -61,7 +62,7 @@ class CWallpaperApplication {
* @param container * @param container
* @param bg * @param bg
*/ */
void setupContainer (const std::shared_ptr<CCombinedContainer>& container, const std::string& bg) const; ContainerUniquePtr setupContainer (const std::string& bg) const;
/** /**
* Loads projects based off the settings * Loads projects based off the settings
*/ */
@ -72,7 +73,7 @@ class CWallpaperApplication {
* @param bg * @param bg
* @return * @return
*/ */
[[nodiscard]] std::shared_ptr<Core::CProject> loadBackground (const std::string& bg); [[nodiscard]] ProjectUniquePtr loadBackground (const std::string& bg);
/** /**
* Prepares all background's values and updates their properties if required * Prepares all background's values and updates their properties if required
*/ */
@ -82,7 +83,7 @@ class CWallpaperApplication {
* *
* @param project * @param project
*/ */
void setupPropertiesForProject (const std::shared_ptr<const Core::CProject>& project); void setupPropertiesForProject (const Project& project);
/** /**
* Prepares CEF browser to be used * Prepares CEF browser to be used
*/ */
@ -109,7 +110,7 @@ class CWallpaperApplication {
/** The application context that contains the current app settings */ /** The application context that contains the current app settings */
CApplicationContext& m_context; CApplicationContext& m_context;
/** Maps screens to backgrounds */ /** Maps screens to backgrounds */
std::map<std::string, std::shared_ptr <Core::CProject>> m_backgrounds {}; std::map<std::string, ProjectUniquePtr> m_backgrounds {};
std::unique_ptr <WallpaperEngine::Audio::Drivers::Detectors::CAudioPlayingDetector> m_audioDetector = nullptr; std::unique_ptr <WallpaperEngine::Audio::Drivers::Detectors::CAudioPlayingDetector> m_audioDetector = nullptr;
std::unique_ptr <WallpaperEngine::Audio::CAudioContext> m_audioContext = nullptr; std::unique_ptr <WallpaperEngine::Audio::CAudioContext> m_audioContext = nullptr;

View File

@ -1,116 +0,0 @@
#include "CObject.h"
#include <utility>
#include "WallpaperEngine/Core/CProject.h"
#include "WallpaperEngine/Core/Objects/CImage.h"
#include "WallpaperEngine/Core/Objects/CParticle.h"
#include "WallpaperEngine/Core/Objects/CSound.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
#include "WallpaperEngine/Assets/CContainer.h"
#include "WallpaperEngine/Logging/CLog.h"
using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Core::UserSettings;
CObject::CObject (
std::shared_ptr <const Core::CProject> project, const CUserSettingBoolean* visible, int id, std::string name,
const CUserSettingVector3* origin, const CUserSettingVector3* scale, const CUserSettingVector3* angles,
std::vector<int> dependencies
) :
m_visible (visible),
m_id (id),
m_name (std::move(name)),
m_origin (origin),
m_scale (scale),
m_angles (angles),
m_project (project),
m_dependencies (std::move(dependencies)) {}
const CObject* CObject::fromJSON (
const json& data, std::shared_ptr <const Core::CProject> project, const std::shared_ptr<const CContainer>& container
) {
const auto id = jsonFindRequired <int> (data, "id", "Objects must have id");
const auto visible = jsonFindUserConfig<CUserSettingBoolean> (data, *project, "visible", true);
const auto origin = jsonFindUserConfig<CUserSettingVector3> (data, *project, "origin", {0, 0, 0});
const auto scale = jsonFindUserConfig<CUserSettingVector3> (data, *project, "scale", {1, 1, 1});
const auto angles_val = jsonFindUserConfig<CUserSettingVector3> (data, *project, "angles", glm::vec3 (0, 0, 0));
const auto name = jsonFindRequired <std::string> (data, "name", "Objects must have name");
const auto effects_it = data.find ("effects");
const auto dependencies_it = data.find ("dependencies");
const auto image_it = data.find ("image");
const auto sound_it = data.find ("sound");
const auto particle_it = data.find ("particle");
const auto text_it = data.find ("text");
const auto light_it = data.find ("light");
std::vector<int> dependencies;
std::vector<const Objects::CEffect*> effects;
const CObject* object;
if (dependencies_it != data.end () && dependencies_it->is_array ())
for (const auto& cur : *dependencies_it)
dependencies.push_back (cur);
if (image_it != data.end () && !image_it->is_null ()) {
object = Objects::CImage::fromJSON (
project, data, container, visible, id, name, origin, scale, angles_val, effects_it, dependencies);
} else if (sound_it != data.end () && !sound_it->is_null ()) {
object = Objects::CSound::fromJSON (project, data, visible, id, name, origin, scale, angles_val, dependencies);
} else if (particle_it != data.end () && !particle_it->is_null ()) {
/// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED
try {
object = Objects::CParticle::fromFile (
project, particle_it->get<std::string> (), container, visible, id, name, origin, angles_val, scale, dependencies);
} catch (std::runtime_error&) {
return nullptr;
}
} else if (text_it != data.end () && !text_it->is_null ()) {
/// TODO: XXXHACK -- TO REMOVE WHEN TEXT SUPPORT IS IMPLEMENTED
return nullptr;
} else if (light_it != data.end () && !light_it->is_null ()) {
/// TODO: XXXHACK -- TO REMOVE WHEN LIGHT SUPPORT IS IMPLEMENTED
return nullptr;
} else {
sLog.exception ("Unknown object type detected: ", name);
}
return object;
}
const glm::vec3& CObject::getOrigin () const {
return this->m_origin->getVec3 ();
}
const glm::vec3& CObject::getScale () const {
return this->m_scale->getVec3 ();
}
const glm::vec3& CObject::getAngles () const {
return this->m_angles->getVec3 ();
}
const std::string& CObject::getName () const {
return this->m_name;
}
const std::vector<int>& CObject::getDependencies () const {
return this->m_dependencies;
}
bool CObject::isVisible () const {
return this->m_visible->getBool ();
}
std::shared_ptr <const CProject> CObject::getProject () const {
return this->m_project;
}
int CObject::getId () const {
return this->m_id;
}

View File

@ -1,86 +0,0 @@
#pragma once
#include "Core.h"
#include "WallpaperEngine/Assets/CContainer.h"
#include "WallpaperEngine/Core/Objects/CEffect.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
namespace WallpaperEngine::Core::Wallpapers {
class CScene;
}
namespace WallpaperEngine::Core::Objects {
class CEffect;
}
namespace WallpaperEngine::Core::UserSettings {
class CUserSettingBoolean;
}
namespace WallpaperEngine::Core {
using json = nlohmann::json;
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Core::UserSettings;
class CObject {
friend class Wallpapers::CScene;
public:
static const CObject* fromJSON ( const json& data, std::shared_ptr <const Core::CProject> project,
const std::shared_ptr<const CContainer>& container);
template <class T> [[nodiscard]] const T* as () const {
if (is <T> ()) {
return static_cast <const T*> (this);
}
throw std::bad_cast ();
}
template <class T> [[nodiscard]] T* as () {
if (is <T> ()) {
return static_cast <T*> (this);
}
throw std::bad_cast ();
}
template <class T> [[nodiscard]] bool is () const {
return typeid (*this) == typeid(T);
}
[[nodiscard]] const std::vector<int>& getDependencies () const;
[[nodiscard]] int getId () const;
[[nodiscard]] const glm::vec3& getOrigin () const;
[[nodiscard]] const glm::vec3& getScale () const;
[[nodiscard]] const glm::vec3& getAngles () const;
[[nodiscard]] const std::string& getName () const;
[[nodiscard]] bool isVisible () const;
[[nodiscard]] std::shared_ptr <const Core::CProject> getProject () const;
protected:
CObject (
std::shared_ptr <const Core::CProject> scene, const CUserSettingBoolean* visible, int id, std::string name,
const CUserSettingVector3* origin, const CUserSettingVector3* scale, const CUserSettingVector3* angles,
std::vector<int> dependencies);
virtual ~CObject () = default;
private:
const CUserSettingBoolean* m_visible;
int m_id = 0;
const std::string m_name;
const CUserSettingVector3* m_origin;
const CUserSettingVector3* m_scale;
const CUserSettingVector3* m_angles;
const std::vector<int> m_dependencies;
const std::shared_ptr <const Core::CProject> m_project;
};
} // namespace WallpaperEngine::Core

View File

@ -1,118 +0,0 @@
#include <WallpaperEngine/Assets/CContainer.h>
#include <utility>
#include "CProject.h"
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
#include "WallpaperEngine/Core/Wallpapers/CVideo.h"
#include "WallpaperEngine/Core/Wallpapers/CWeb.h"
#include "WallpaperEngine/Logging/CLog.h"
using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Wallpapers;
using namespace WallpaperEngine::Assets;
static int backgroundId = -1;
CProject::CProject (
std::string title, std::string type, std::string workshopid, std::shared_ptr<const CContainer> container,
bool supportsaudioprocessing, const std::map<std::string, std::shared_ptr<Projects::CProperty>>& properties
) :
m_workshopid(std::move(workshopid)),
m_title (std::move(title)),
m_type (std::move(type)),
m_container (std::move(container)),
m_properties (properties),
m_supportsaudioprocessing (supportsaudioprocessing) {}
std::shared_ptr<CProject> CProject::fromFile (const std::string& filename, std::shared_ptr<const CContainer> container) {
json content = json::parse (container->readFileAsString (filename));
const auto dependency = jsonFindDefault<std::string> (content, "dependency", "No dependency");
if (dependency != "No dependency") {
sLog.exception ("Project have dependency. They are not supported, quiting");
}
// workshopid is not required, but we have to use it for some identification stuff,
// so using a static, decreasing number should be enough
bool supportsaudioprocessing = false;
auto type = jsonFindRequired <std::string> (content, "type", "Project type missing");
const auto file = jsonFindRequired <std::string> (content, "file", "Project's main file missing");
auto general = content.find ("general");
std::shared_ptr <const CWallpaper> wallpaper = nullptr;
std::map<std::string, std::shared_ptr <Projects::CProperty>> properties;
std::transform (type.begin (), type.end (), type.begin (), tolower);
if (general != content.end ()) {
supportsaudioprocessing = jsonFindDefault (general, "supportsaudioprocessing", false);
const auto properties_it = general->find ("properties");
if (properties_it != general->end ()) {
for (const auto& cur : properties_it->items ()) {
auto property = Projects::CProperty::fromJSON (cur.value (), cur.key ());
if (property == nullptr) {
continue;
}
properties.emplace (property->getName (), std::move (property));
}
}
}
std::shared_ptr<CProject> project = std::make_shared <CProject> (
jsonFindRequired <std::string> (content, "title", "Project title missing"),
type,
jsonFindDefault <std::string> (content, "workshopid", std::to_string (backgroundId--)),
container,
supportsaudioprocessing,
properties
);
if (type == "scene")
wallpaper = CScene::fromFile (file, project, container);
else if (type == "video")
wallpaper = std::make_shared<CVideo> (file, project);
else if (type == "web")
wallpaper = std::make_shared<CWeb> (file, project);
else
sLog.exception ("Unsupported wallpaper type: ", type);
project->setWallpaper (wallpaper);
return project;
}
void CProject::setWallpaper (std::shared_ptr <const CWallpaper> wallpaper) {
this->m_wallpaper = wallpaper;
}
const std::shared_ptr <const CWallpaper> CProject::getWallpaper () const {
return this->m_wallpaper;
}
const std::string& CProject::getTitle () const {
return this->m_title;
}
const std::string& CProject::getType () const {
return this->m_type;
}
const std::map<std::string, std::shared_ptr <Projects::CProperty>>& CProject::getProperties () const {
return this->m_properties;
}
const std::string& CProject::getWorkshopId () const {
return this->m_workshopid;
}
std::shared_ptr<const CContainer> CProject::getContainer () const {
return this->m_container;
}
bool CProject::supportsAudioProcessing () const {
return this->m_supportsaudioprocessing;
}

View File

@ -1,53 +0,0 @@
#pragma once
#include <map>
#include <nlohmann/json.hpp>
#include "CWallpaper.h"
#include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Core/Projects/CProperty.h"
#include "WallpaperEngine/Assets/CContainer.h"
namespace WallpaperEngine::Core::Projects {
class CProperty;
}
namespace WallpaperEngine::Core {
using json = nlohmann::json;
using namespace WallpaperEngine::Assets;
class CWallpaper;
class CProject {
public:
CProject (
std::string title, std::string type, std::string workshopid, std::shared_ptr<const CContainer> container,
bool supportsaudioprocessing, const std::map<std::string, std::shared_ptr<Projects::CProperty>>& properties);
static std::shared_ptr<CProject> fromFile (const std::string& filename, std::shared_ptr<const CContainer> container);
[[nodiscard]] const std::shared_ptr <const CWallpaper> getWallpaper () const;
[[nodiscard]] const std::string& getTitle () const;
[[nodiscard]] const std::string& getType () const;
[[nodiscard]] const std::map<std::string, std::shared_ptr <Projects::CProperty>>& getProperties () const;
[[nodiscard]] const std::string& getWorkshopId () const;
[[nodiscard]] bool supportsAudioProcessing () const;
[[nodiscard]] std::shared_ptr<const CContainer> getContainer () const;
protected:
void setWallpaper (std::shared_ptr <const CWallpaper> wallpaper);
private:
std::map<std::string, std::shared_ptr<Projects::CProperty>> m_properties;
const std::string m_workshopid;
const std::string m_title;
const std::string m_type;
const bool m_supportsaudioprocessing;
std::shared_ptr <const CWallpaper> m_wallpaper = nullptr;
std::shared_ptr<const CContainer> m_container = nullptr;
};
} // namespace WallpaperEngine::Core

View File

@ -1,12 +0,0 @@
#include "CWallpaper.h"
#include <utility>
using namespace WallpaperEngine::Core;
CWallpaper::CWallpaper (std::shared_ptr <const CProject> project) :
m_project (project) {}
std::shared_ptr <const CProject> CWallpaper::getProject () const {
return this->m_project;
}

View File

@ -1,44 +0,0 @@
#pragma once
#include <cassert>
#include <string>
#include "CProject.h"
namespace WallpaperEngine::Core {
class CProject;
class CWallpaper {
public:
template <class T> [[nodiscard]] const T* as () const {
if (is<T> ()) {
return static_cast <const T*> (this);
}
throw std::bad_cast ();
}
template <class T> [[nodiscard]] T* as () {
if (is<T> ()) {
return static_cast <T*> (this);
}
throw std::bad_cast ();
}
template <class T> [[nodiscard]] bool is () const {
return typeid(*this) == typeid(T);
}
std::shared_ptr <const CProject> getProject () const;
protected:
friend class CProject;
explicit CWallpaper (std::shared_ptr <const CProject> project);
virtual ~CWallpaper() = default;
private:
std::shared_ptr <const CProject> m_project;
};
} // namespace WallpaperEngine::Core

View File

@ -500,42 +500,3 @@ template const glm::vec4 Core::jsonFindDefault (const nlohmann::json& data, cons
template const glm::ivec2 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec2 defaultValue); template const glm::ivec2 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec2 defaultValue);
template const glm::ivec3 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec3 defaultValue); template const glm::ivec3 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec3 defaultValue);
template const glm::ivec4 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec4 defaultValue); template const glm::ivec4 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec4 defaultValue);
template <typename T> const T* Core::jsonFindUserConfig (
const nlohmann::json::const_iterator& data, const CProject& project, const char* key, typename T::data_type defaultValue
) {
const auto it = data->find (key);
if (it == data->end () || it->type () == nlohmann::detail::value_t::null)
return T::fromScalar (defaultValue);
return T::fromJSON (*it, project.getProperties ());
}
template const CUserSettingBoolean* Core::jsonFindUserConfig (
const nlohmann::json::const_iterator& data, const CProject& project, const char* key,
CUserSettingBoolean::data_type defaultValue);
template const CUserSettingVector3* Core::jsonFindUserConfig (
const nlohmann::json::const_iterator& data, const CProject& project, const char* key,
CUserSettingVector3::data_type defaultValue);
template const CUserSettingFloat* Core::jsonFindUserConfig (
const nlohmann::json::const_iterator& data, const CProject& project, const char* key,
CUserSettingFloat::data_type defaultValue);
template <typename T> const T* Core::jsonFindUserConfig (
const nlohmann::json& data, const CProject& project, const char* key, typename T::data_type defaultValue
) {
const auto it = data.find (key);
if (it == data.end () || it->type () == nlohmann::detail::value_t::null)
return T::fromScalar (defaultValue);
return T::fromJSON (*it, project.getProperties ());
}
template const CUserSettingBoolean* Core::jsonFindUserConfig (
const nlohmann::json& data, const CProject& project, const char* key, CUserSettingBoolean::data_type defaultValue);
template const CUserSettingVector3* Core::jsonFindUserConfig (
const nlohmann::json& data, const CProject& project, const char* key, CUserSettingVector3::data_type defaultValue);
template const CUserSettingFloat* Core::jsonFindUserConfig (
const nlohmann::json& data, const CProject& project, const char* key, CUserSettingFloat::data_type defaultValue);

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "CProject.h"
#include <glm/mat4x4.hpp> #include <glm/mat4x4.hpp>
#include <glm/vec2.hpp> #include <glm/vec2.hpp>
#include <glm/vec3.hpp> #include <glm/vec3.hpp>
@ -44,8 +43,4 @@ template <typename T> const T jsonFindDefault (
const nlohmann::json::const_iterator& data, const char* key, const T defaultValue); const nlohmann::json::const_iterator& data, const char* key, const T defaultValue);
template <typename T> const T jsonFindDefault ( template <typename T> const T jsonFindDefault (
const nlohmann::json& data, const char* key, const T defaultValue); const nlohmann::json& data, const char* key, const T defaultValue);
template <typename T> const T* jsonFindUserConfig (
const nlohmann::json::const_iterator& data, const CProject& project, const char* key, typename T::data_type defaultValue);
template <typename T> const T* jsonFindUserConfig (
const nlohmann::json& data, const CProject& project, const char* key, typename T::data_type defaultValue);
} // namespace WallpaperEngine::Core } // namespace WallpaperEngine::Core

View File

@ -1,319 +0,0 @@
#include "CEffect.h"
#include <utility>
#include "WallpaperEngine/Core/CProject.h"
#include "WallpaperEngine/Core/Objects/CImage.h"
#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantProperty.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Logging/CLog.h"
using namespace WallpaperEngine;
using namespace WallpaperEngine::Core::Objects;
using namespace WallpaperEngine::Core::UserSettings;
CEffect::CEffect (
std::string name, std::string description, std::string group, std::string preview,
std::shared_ptr <const Core::CProject> project, const CUserSettingBoolean* visible,
std::vector<std::string> dependencies, std::vector<const Effects::CFBO*> fbos,
std::vector<const Images::CMaterial*> materials
) :
m_name (std::move(name)),
m_description (std::move(description)),
m_group (std::move(group)),
m_preview (std::move(preview)),
m_visible (visible),
m_dependencies (std::move(dependencies)),
m_fbos (std::move(fbos)),
m_project (project),
m_materials (std::move(materials)) {}
const CEffect* CEffect::fromJSON (
const json& data, const CUserSettingBoolean* visible, std::shared_ptr <const Core::CProject> project,
const Images::CMaterial* material, const std::shared_ptr<const CContainer>& container
) {
const auto file = jsonFindRequired <std::string> (data, "file", "Object effect must have a file");
const auto effectpasses_it = data.find ("passes");
json content = json::parse (container->readFileAsString(file));
const auto effectName = jsonFindRequired <std::string> (content, "name", "Effect must have a name");
const auto passes_it = jsonFindRequired (content, "passes", "Effect must have a pass list");
const auto fbos_it = content.find ("fbos");
// info to override in the pass information, used by material generation
std::map<int, Images::CMaterial::OverrideInfo> overrides;
std::vector<const Effects::CFBO*> fbos;
if (fbos_it != content.end ())
fbos = CEffect::fbosFromJSON (fbos_it);
if (effectpasses_it != data.end ()) {
overrides = overridesFromJSON (effectpasses_it, material, project);
}
return new CEffect (
effectName,
jsonFindDefault<std::string> (content, "description", ""),
jsonFindRequired <std::string> (content, "group", "Effect must have a group"),
jsonFindDefault<std::string> (content, "preview", ""),
project,
visible,
dependenciesFromJSON (jsonFindRequired (content, "dependencies", "")),
fbos,
materialsFromJSON (passes_it, effectName, container, overrides)
);
}
std::map<std::string, int> CEffect::combosFromJSON (const json::const_iterator& combos_it) {
std::map<std::string, int> combos;
for (const auto& cur : combos_it->items ()) {
auto uppercase = std::string (cur.key ());
std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper);
combos.emplace (uppercase, cur.value ());
}
return combos;
}
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> CEffect::constantsFromJSON (
const json::const_iterator& constants_it, std::shared_ptr <const Core::CProject> project
) {
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
for (auto& cur : constants_it->items ()) {
auto val = cur.value ();
Effects::Constants::CShaderConstant* constant = nullptr;
// if the constant is an object, that means the constant has some extra information
// for the UI, take the value, which is what we need
if (cur.value ().is_object ()) {
auto user = cur.value ().find ("user");
auto it = cur.value ().find ("value");
if (user == cur.value ().end () && it == cur.value ().end ()) {
sLog.error (R"(Found object for shader constant without "value" and "user" setting)");
continue;
}
if (user != cur.value ().end () && user->is_string ()) {
// look for a property with the correct name
const auto& properties = project->getProperties ();
const auto property = properties.find (*user);
if (property != properties.end ()) {
constant = new Effects::Constants::CShaderConstantProperty (property->second);
} else {
sLog.error ("Shader constant pointing to non-existant project property: ", user->get <std::string> ());
val = it.value ();
}
} else {
val = it.value ();
}
}
// TODO: REFACTOR THIS SO IT'S NOT SO DEEP INTO THE FUNCTION
if (constant == nullptr) {
if (val.is_number_float ()) {
constant = new Effects::Constants::CShaderConstantFloat (val.get<float> ());
} else if (val.is_number_integer ()) {
constant = new Effects::Constants::CShaderConstantInteger (val.get<int> ());
} else if (val.is_string ()) {
// count the amount of spaces to determine which type of vector we have
std::string value = val;
size_t spaces =
std::count_if (value.begin (), value.end (), [&] (const auto& item) { return item == ' '; });
if (spaces == 1) {
constant =
new Effects::Constants::CShaderConstantVector2 (WallpaperEngine::Core::aToVector2 (value));
} else if (spaces == 2) {
constant =
new Effects::Constants::CShaderConstantVector3 (WallpaperEngine::Core::aToVector3 (value));
} else if (spaces == 3) {
constant =
new Effects::Constants::CShaderConstantVector4 (WallpaperEngine::Core::aToVector4 (value));
} else {
sLog.exception ("unknown shader constant type ", value);
}
} else {
sLog.exception ("unknown shader constant type ", val);
}
}
constants.emplace (cur.key (), constant);
}
return constants;
}
std::vector<const Effects::CFBO*> CEffect::fbosFromJSON (const json::const_iterator& fbos_it) {
std::vector<const Effects::CFBO*> fbos;
for (const auto& cur : (*fbos_it))
fbos.push_back (Effects::CFBO::fromJSON (cur));
return fbos;
}
std::vector<std::string> CEffect::dependenciesFromJSON (const json::const_iterator& dependencies_it) {
std::vector<std::string> dependencies;
for (const auto& cur : (*dependencies_it))
dependencies.push_back (cur);
return dependencies;
}
std::vector<const Images::CMaterial*> CEffect::materialsFromJSON (
const json::const_iterator& passes_it, const std::string& name, const std::shared_ptr<const CContainer>& container,
std::map<int, Images::CMaterial::OverrideInfo> overrides
) {
std::vector<const Images::CMaterial*> materials;
int materialNumber = -1;
for (const auto& cur : (*passes_it)) {
++materialNumber;
const auto materialfile = cur.find ("material");
const auto target_it = cur.find ("target");
const auto bind_it = cur.find ("bind");
const auto command_it = cur.find ("command");
const auto compose_it = cur.find ("compose");
const Images::CMaterial* material = nullptr;
if (compose_it != cur.end ()) {
sLog.error ("Composing materials is not supported yet...");
}
if (materialfile != cur.end ()) {
std::map<int, const Effects::CBind*> textureBindings;
if (bind_it != cur.end ()) {
for (const auto& bindCur : (*bind_it)) {
const auto* bind = Effects::CBind::fromJSON (bindCur);
textureBindings.emplace (bind->getIndex (), bind);
}
}
const Images::CMaterial::OverrideInfo* overrideInfo = nullptr;
const auto overrideIt = overrides.find (materialNumber);
if (overrideIt != overrides.end ()) {
overrideInfo = &overrideIt->second;
}
if (target_it == cur.end ()) {
material = Images::CMaterial::fromFile (
materialfile->get<std::string> (), container, false, textureBindings, overrideInfo);
} else {
material = Images::CMaterial::fromFile (
materialfile->get<std::string> (), *target_it, container, false, textureBindings, overrideInfo);
}
} else if (command_it != cur.end ()) {
material = Images::CMaterial::fromCommand (cur);
} else {
sLog.exception ("Material without command nor material file: ", name, " (", materialNumber,")");
}
materials.push_back (material);
}
return materials;
}
std::map<int, Images::CMaterial::OverrideInfo> CEffect::overridesFromJSON (
const json::const_iterator& passes_it, const Images::CMaterial* material,
std::shared_ptr <const Core::CProject> project
) {
std::map<int, Images::CMaterial::OverrideInfo> result;
int materialNumber = -1;
for (const auto& cur : (*passes_it)) {
++materialNumber;
auto constants_it = cur.find ("constantshadervalues");
auto combos_it = cur.find ("combos");
auto textures_it = cur.find ("textures");
Images::CMaterial::OverrideInfo override;
int textureNumber = -1;
if (combos_it != cur.end ()) {
override.combos = CEffect::combosFromJSON (combos_it);
}
if (constants_it != cur.end ()) {
override.constants = CEffect::constantsFromJSON (constants_it, project);
}
if (textures_it != cur.end ()) {
// TODO: MAYBE CHANGE THIS TO BE SOMEWHERE ELSE? THIS IS REALLY MODIFYING THE DATA
// BUT IT'S USEFUL TO HAVE TO SIMPLIFY RENDERING CODE
for (const auto& texture : (*textures_it)) {
++textureNumber;
std::string name;
if (texture.is_null () && textureNumber > 0) {
continue;
}
if (textureNumber == 0) {
auto passTextures = (*material->getPasses ().begin ())->getTextures ();
if (passTextures.empty()) {
continue;
} else {
name = passTextures.begin ()->second;
}
} else {
name = texture;
}
override.textures.emplace (textureNumber, name);
}
}
result.emplace (materialNumber, override);
}
return result;
}
const std::vector<std::string>& CEffect::getDependencies () const {
return this->m_dependencies;
}
const std::vector<const Images::CMaterial*>& CEffect::getMaterials () const {
return this->m_materials;
}
const std::vector<const Effects::CFBO*>& CEffect::getFbos () const {
return this->m_fbos;
}
const Core::CProject& CEffect::getProject () const {
return *this->m_project;
}
bool CEffect::isVisible () const {
return this->m_visible->getBool ();
}
const Effects::CFBO* CEffect::findFBO (const std::string& name) {
for (const auto& cur : this->m_fbos)
if (cur->getName () == name)
return cur;
sLog.exception ("cannot find fbo ", name);
}

View File

@ -1,102 +0,0 @@
#pragma once
#include "WallpaperEngine/Assets/CContainer.h"
#include "WallpaperEngine/Core/CObject.h"
#include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Core/Objects/Effects/CFBO.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
namespace WallpaperEngine::Core {
class CObject;
class CProject;
}
namespace WallpaperEngine::Core::UserSettings {
class CUserSettingBoolean;
}
namespace WallpaperEngine::Core::Objects {
using json = nlohmann::json;
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Core::UserSettings;
/**
* Represents an effect applied to background objects
*/
class CEffect {
public:
CEffect (
std::string name, std::string description, std::string group, std::string preview,
std::shared_ptr <const Core::CProject>, const CUserSettingBoolean* visible,
std::vector<std::string> dependencies, std::vector<const Effects::CFBO*> fbos,
std::vector<const Images::CMaterial*> materials);
static const CEffect* fromJSON (
const json& data, const CUserSettingBoolean* visible, std::shared_ptr <const Core::CProject> project,
const Images::CMaterial* material, const std::shared_ptr<const CContainer>& container);
/**
* @return List of dependencies for the effect to work
*/
[[nodiscard]] const std::vector<std::string>& getDependencies () const;
/**
* @return List of materials the effect applies
*/
[[nodiscard]] const std::vector<const Images::CMaterial*>& getMaterials () const;
/**
* @return The list of FBOs to be used for this effect
*/
[[nodiscard]] const std::vector<const Effects::CFBO*>& getFbos () const;
/**
* @return If the effect is visible or not
*/
[[nodiscard]] bool isVisible () const;
/**
* @return The project this effect is part of
*/
[[nodiscard]] const CProject& getProject () const;
/**
* Searches the FBOs list for the given FBO
*
* @param name The FBO to search for
*
* @return
*/
const Effects::CFBO* findFBO (const std::string& name);
protected:
static std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constantsFromJSON (
const json::const_iterator& constants_it, std::shared_ptr <const Core::CProject> project);
static std::map<std::string, int> combosFromJSON (const json::const_iterator& combos_it);
static std::vector<const Effects::CFBO*> fbosFromJSON (const json::const_iterator& fbos_it);
static std::vector<std::string> dependenciesFromJSON (const json::const_iterator& dependencies_it);
static std::vector<const Images::CMaterial*> materialsFromJSON (
const json::const_iterator& passes_it, const std::string& name,
const std::shared_ptr<const CContainer>& container, std::map<int, Images::CMaterial::OverrideInfo>);
static std::map<int, Images::CMaterial::OverrideInfo> overridesFromJSON (
const json::const_iterator& passes_it, const Images::CMaterial* material,
std::shared_ptr <const Core::CProject> project);
private:
/** Effect's name */
const std::string m_name;
/** Effect's description used in the UI */
const std::string m_description;
/** Effect's group used in the UI */
const std::string m_group;
/** A project that previews the given effect, used in the UI */
const std::string m_preview;
/** If the effect is visible or not */
const UserSettings::CUserSettingBoolean* m_visible;
/** Project this effect is part of */
std::shared_ptr <const Core::CProject> m_project;
/** List of dependencies for the effect */
const std::vector<std::string> m_dependencies;
/** List of materials the effect applies */
const std::vector<const Images::CMaterial*> m_materials;
/** List of FBOs required for this effect */
const std::vector<const Effects::CFBO*> m_fbos;
};
} // namespace WallpaperEngine::Core::Objects

View File

@ -1,142 +0,0 @@
#include "CImage.h"
#include <utility>
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
using namespace WallpaperEngine::Core::Objects;
using namespace WallpaperEngine::Core::UserSettings;
CImage::CImage (
std::shared_ptr <const Core::CProject> project, const Images::CMaterial* material,
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
const CUserSettingVector3* scale, const CUserSettingVector3* angles, glm::vec2 size, std::string alignment,
const CUserSettingVector3* color, const CUserSettingFloat* alpha, float brightness, uint32_t colorBlendMode,
glm::vec2 parallaxDepth, bool fullscreen, bool passthrough, bool autosize,
std::vector<const Objects::CEffect*> effects, std::vector<int> dependencies
) :
CObject (project, visible, id, std::move(name), origin, scale, angles, std::move(dependencies)),
m_size (size),
m_parallaxDepth (parallaxDepth),
m_material (material),
m_alignment (std::move(alignment)),
m_alpha (alpha),
m_brightness (brightness),
m_color (color),
m_colorBlendMode (colorBlendMode),
m_fullscreen (fullscreen),
m_passthrough (passthrough),
m_autosize (autosize),
m_effects (std::move(effects)) {}
const WallpaperEngine::Core::CObject* CImage::fromJSON (
std::shared_ptr <const Core::CProject> project, const json& data, const std::shared_ptr<const CContainer>& container,
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
const CUserSettingVector3* scale, const CUserSettingVector3* angles, const json::const_iterator& effects_it,
std::vector<int> dependencies
) {
const auto image = jsonFindRequired <std::string>(data, "image", "Image must have an image");
std::vector<const Objects::CEffect*> effects;
json content = json::parse (container->readFileAsString (image));
const auto material = Images::CMaterial::fromFile (
jsonFindRequired<std::string> (content, "material", "Image must have a material"),
container,
jsonFindDefault (content, "solidlayer", false)
);
if (effects_it != data.end () && effects_it->is_array ()) {
for (auto& cur : *effects_it) {
const auto effectVisible = jsonFindUserConfig<CUserSettingBoolean> (cur, *project, "visible", true);
// TODO: USER CANNOT MODIFY VALUES ON THE FLY, BUT IT MIGHT BE INTERESTING TO SUPPORT THAT AT SOME POINT?
// TODO: AT LEAST THE ORIGINAL SOFTWARE ALLOWS YOU TO DO THAT IN THE PREVIEW WINDOW
// TODO: THAT MIGHT INCREASE COMPLEXITY THO...
// TODO: ESPECIALLY IF THAT CHANGES RENDERING OF PASSES/IMAGES
// TODO: DECISIONS, DECISIONS, DECISIONS...
if (!effectVisible->getBool ())
continue;
effects.push_back (
Objects::CEffect::fromJSON (
cur, effectVisible, project, material, container
)
);
}
}
return new CImage (
project,
material,
visible,
id,
std::move(name),
origin,
scale,
angles,
jsonFindDefault<glm::vec2> (data, "size", glm::vec2 (0.0, 0.0)),
jsonFindDefault<std::string> (data, "alignment", "center"),
jsonFindUserConfig<CUserSettingVector3> (data, *project, "color", {1, 1, 1}),
jsonFindUserConfig<CUserSettingFloat> (data, *project, "alpha", 1.0),
jsonFindDefault<float> (data, "brightness", 1.0),
jsonFindDefault<uint32_t> (data, "colorBlendMode", 0),
jsonFindDefault<glm::vec2> (data, "parallaxDepth", glm::vec2 (0.0, 0.0)),
jsonFindDefault<bool> (content, "fullscreen", false),
jsonFindDefault<bool> (content, "passthrough", false),
jsonFindDefault<bool> (content, "autosize", false),
effects,
std::move(dependencies)
);
}
const Images::CMaterial* CImage::getMaterial () const {
return this->m_material;
}
const glm::vec2& CImage::getSize () const {
return this->m_size;
}
const std::string& CImage::getAlignment () const {
return this->m_alignment;
}
float CImage::getAlpha () const {
return this->m_alpha->getFloat ();
}
const glm::vec3& CImage::getColor () const {
return this->m_color->getVec3 ();
}
float CImage::getBrightness () const {
return this->m_brightness;
}
uint32_t CImage::getColorBlendMode () const {
return this->m_colorBlendMode;
}
const glm::vec2& CImage::getParallaxDepth () const {
return this->m_parallaxDepth;
}
bool CImage::isFullscreen () const {
return this->m_fullscreen;
}
bool CImage::isPassthrough () const {
return this->m_passthrough;
}
bool CImage::isAutosize () const {
return this->m_autosize;
}
const std::vector<const CEffect*>& CImage::getEffects () const {
return this->m_effects;
}

View File

@ -1,122 +0,0 @@
#pragma once
#include <vector>
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
#include "WallpaperEngine/Core/CObject.h"
#include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Assets/CContainer.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
namespace WallpaperEngine::Core::Wallpapers {
class CScene;
}
namespace WallpaperEngine::Core::Objects {
using json = nlohmann::json;
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Core::UserSettings;
/**
* Represents an image in a background
*/
class CImage : public CObject {
friend class CObject;
public:
static const CObject* fromJSON (
std::shared_ptr <const Core::CProject> project, const json& data,
const std::shared_ptr<const CContainer>& container, const CUserSettingBoolean* visible, int id,
std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale,
const CUserSettingVector3* angles, const json::const_iterator& effects_it, std::vector<int> dependencies);
/**
* @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]] const 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;
/**
* @return If the image is fullscreen or not
*/
[[nodiscard]] bool isFullscreen () const;
/**
* @return If the image is passthrough or not
*/
[[nodiscard]] bool isPassthrough () const;
/**
* @return If the image is autosized or not
*/
[[nodiscard]] bool isAutosize () const;
/**
* @return All of the effects applied to this image
*/
[[nodiscard]] const std::vector<const Objects::CEffect*>& getEffects () const;
protected:
CImage (
std::shared_ptr <const Core::CProject> project, const Images::CMaterial* material,
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
const CUserSettingVector3* scale, const CUserSettingVector3* angles, glm::vec2 size, std::string alignment,
const CUserSettingVector3* color, const CUserSettingFloat* alpha, float brightness, uint32_t colorBlendMode,
glm::vec2 parallaxDepth, bool fullscreen, bool passthrough, bool autosize,
std::vector<const Objects::CEffect*> effects, std::vector<int> dependencies);
private:
/** The image's size */
const glm::vec2 m_size;
/** Parallax depth */
const glm::vec2 m_parallaxDepth;
/** Base material for the image */
const Images::CMaterial* m_material;
/** What type of alignment to use for the image's position */
const std::string m_alignment;
/** The alpha value for the image */
const CUserSettingFloat* m_alpha;
/** The brightness for the image */
float m_brightness;
/** The color to use for the image */
const CUserSettingVector3* m_color;
/** The color blending mode used for the image, special value for shaders */
const uint32_t m_colorBlendMode;
/** Override for effects */
const std::vector<const Objects::CEffect*> m_effects;
/** If the image is fullscreen or not */
bool m_fullscreen = false;
/** If the image is passthrough or not */
bool m_passthrough = false;
/** If the image's size should be automatically determined */
bool m_autosize = false;
};
} // namespace WallpaperEngine::Core::Objects

View File

@ -1,53 +0,0 @@
#include "CSound.h"
#include <utility>
#include "WallpaperEngine/Core/CObject.h"
#include "WallpaperEngine/Logging/CLog.h"
using namespace WallpaperEngine::Core::Objects;
CSound::CSound (
std::shared_ptr <const Core::CProject> project, const CUserSettingBoolean* visible, int id, std::string name,
const CUserSettingVector3* origin, const CUserSettingVector3* scale, const CUserSettingVector3* angles,
bool repeat, std::vector<std::string> sounds, std::vector<int> dependencies
) :
CObject (project, visible, id, std::move(name), origin, scale, angles, std::move(dependencies)),
m_repeat (repeat),
m_sounds (std::move(sounds)) {}
const WallpaperEngine::Core::CObject* CSound::fromJSON (
std::shared_ptr <const Core::CProject> project, const json& data, const CUserSettingBoolean* visible,
int id, const std::string& name, const CUserSettingVector3* origin, const CUserSettingVector3* scale,
const CUserSettingVector3* angles, std::vector<int> dependencies
) {
// TODO: PARSE AUDIO VOLUME
std::vector<std::string> sounds;
const auto sound_it = jsonFindRequired (data, "sound", "Sound information not present");
if (!sound_it->is_array ())
sLog.exception ("Expected sound list on element ", name);
for (const auto& cur : (*sound_it))
sounds.push_back (cur);
return new CSound (
project,
visible,
id,
name,
origin,
scale,
angles,
jsonFindDefault<std::string> (data, "playbackmode", "") == "loop",
sounds,
std::move(dependencies)
);
}
const std::vector<std::string>& CSound::getSounds () const {
return this->m_sounds;
}
bool CSound::isRepeat () const {
return this->m_repeat;
}

View File

@ -1,48 +0,0 @@
#pragma once
#include "WallpaperEngine/Core/CObject.h"
#include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
namespace WallpaperEngine::Core::Wallpapers {
class CScene;
}
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;
public:
static const CObject* fromJSON (
std::shared_ptr <const Core::CProject> project, const json& data, const CUserSettingBoolean* visible,
int id, const std::string& name, const CUserSettingVector3* origin, const CUserSettingVector3* scale,
const CUserSettingVector3* angles, std::vector<int> dependencies);
/**
* @return The list of sounds to play
*/
[[nodiscard]] const std::vector<std::string>& getSounds () const;
/**
* @return If the sound should repeat or not
*/
[[nodiscard]] bool isRepeat () const;
protected:
CSound (
std::shared_ptr <const Core::CProject> project, const CUserSettingBoolean* visible, int id, std::string name,
const CUserSettingVector3* origin, const CUserSettingVector3* scale, const CUserSettingVector3* angles,
bool repeat, std::vector<std::string> sounds, std::vector<int> dependencies);
private:
/** If the sounds should repeat or not */
bool m_repeat = false;
/** The list of sounds to play */
std::vector<std::string> m_sounds = {};
};
} // namespace WallpaperEngine::Core::Objects

View File

@ -1,24 +0,0 @@
#include "CBind.h"
#include <utility>
using namespace WallpaperEngine::Core::Objects::Effects;
CBind::CBind (std::string name, uint32_t index) :
m_name (std::move(name)),
m_index (index) {}
const CBind* CBind::fromJSON (const json& data) {
return new CBind (
jsonFindRequired <std::string> (data, "name", "bind must have texture name"),
jsonFindRequired <uint32_t> (data, "index", "bind must have index")
);
}
const std::string& CBind::getName () const {
return this->m_name;
}
const uint32_t& CBind::getIndex () const {
return this->m_index;
}

View File

@ -1,43 +0,0 @@
#pragma once
#include <string>
#include "WallpaperEngine/Core/Core.h"
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 const CBind* fromJSON (const json& data);
/**
* @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;
protected:
CBind (std::string name, uint32_t index);
private:
/** The texture's name */
const std::string m_name;
/** The texture index to replace */
const uint32_t m_index;
};
} // namespace WallpaperEngine::Core::Objects::Effects

View File

@ -1,31 +0,0 @@
#include "CFBO.h"
#include <utility>
using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Objects::Effects;
CFBO::CFBO (std::string name, float scale, std::string format) :
m_name (std::move(name)),
m_scale (scale),
m_format (std::move(format)) {}
const CFBO* CFBO::fromJSON (const json& data) {
return new CFBO (
jsonFindRequired <std::string> (data, "name", "Name for an FBO is required"),
jsonFindDefault <float> (data, "scale", 1.0),
jsonFindDefault <std::string> (data, "format", "")
);
}
const std::string& CFBO::getName () const {
return this->m_name;
}
const float& CFBO::getScale () const {
return this->m_scale;
}
const std::string& CFBO::getFormat () const {
return this->m_format;
}

View File

@ -1,44 +0,0 @@
#pragma once
#include "WallpaperEngine/Core/Core.h"
#include <nlohmann/json.hpp>
#include <string>
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:
static const CFBO* fromJSON (const json& data);
/**
* @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;
protected:
CFBO (std::string name, float scale, std::string format);
private:
/** The name of the FBO */
const std::string m_name;
/** The scale factor of the FBO */
const float m_scale;
/** The FBO's format for the render */
const std::string m_format;
};
} // namespace WallpaperEngine::Core::Objects::Effects

View File

@ -1,120 +0,0 @@
#include "CMaterial.h"
#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h"
#include "WallpaperEngine/Logging/CLog.h"
#include <nlohmann/json.hpp>
#include <utility>
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Core::Objects;
using namespace WallpaperEngine::Core::Objects::Images;
CMaterial::CMaterial (
std::string name, bool solidlayer, std::map<int, const Effects::CBind*> textureBindings,
std::vector<const Materials::CPass*> passes
) :
m_name (std::move(name)),
m_textureBindings (std::move(textureBindings)),
m_passes (std::move(passes)),
m_solidlayer (solidlayer) {}
CMaterial::CMaterial (
std::string name, std::string target, bool solidlayer,
std::map<int, const Effects::CBind*> textureBindings, std::vector<const Materials::CPass*> passes
) :
m_name (std::move(name)),
m_target (std::move(target)),
m_textureBindings (std::move(textureBindings)),
m_passes (std::move(passes)),
m_solidlayer (solidlayer) {}
const CMaterial* CMaterial::fromFile (
const std::filesystem::path& filename, const std::shared_ptr<const CContainer>& container, bool solidlayer,
std::map<int, const Effects::CBind*> textureBindings, const OverrideInfo* overrides
) {
return fromJSON (filename, json::parse (container->readFileAsString (filename)), solidlayer, std::move(textureBindings), overrides);
}
const CMaterial* CMaterial::fromFile (
const std::filesystem::path& filename, const std::string& target, const std::shared_ptr<const CContainer>& container, bool solidlayer,
std::map<int, const Effects::CBind*> textureBindings, const OverrideInfo* overrides
) {
return fromJSON (filename, json::parse (container->readFileAsString (filename)), target, solidlayer, std::move(textureBindings), overrides);
}
const CMaterial* CMaterial::fromJSON (
const std::string& name, const json& data, const std::string& target, bool solidlayer,
std::map<int, const Effects::CBind*> textureBindings, const OverrideInfo* overrides
) {
const auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass");
std::vector<const Materials::CPass*> passes;
for (const auto& cur : (*passes_it))
passes.push_back (Materials::CPass::fromJSON (cur, overrides));
return new CMaterial (name, target, solidlayer, std::move(textureBindings), passes);
}
const CMaterial* CMaterial::fromJSON (
const std::string& name, const json& data, bool solidlayer, std::map<int, const Effects::CBind*> textureBindings,
const OverrideInfo* overrides
) {
const auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass");
std::vector<const Materials::CPass*> passes;
for (const auto& cur : (*passes_it))
passes.push_back (Materials::CPass::fromJSON (cur, overrides));
return new CMaterial (name, solidlayer, std::move(textureBindings), passes);
}
const CMaterial* CMaterial::fromCommand (const json& data) {
const std::string& command = jsonFindRequired <std::string> (data, "command", "Command material must have a command");
const std::string& target = jsonFindRequired <std::string> (data, "target", "Command material must have a target");
const std::string& source = jsonFindRequired <std::string> (data, "source", "Command material must have a source");
std::vector<const Materials::CPass*> passes;
if (command == "copy") {
passes.push_back (
Materials::CPass::fromJSON ({
{"blending", "normal"},
{"cullmode", "nocull"},
{"depthtest", "disabled"},
{"depthwrite", "disabled"},
{"shader", "commands/copy"},
{"textures", json::array ({source, target})}
}, nullptr)
);
} else if (command == "swap") {
// TODO: HOW TO IMPLEMENT THIS ONE?
sLog.exception ("Command material swap not implemented yet");
} else {
sLog.exception ("Unknown command: ", command);
}
return new CMaterial (command, false, {}, passes);
}
const std::vector<const Materials::CPass*>& CMaterial::getPasses () const {
return this->m_passes;
}
const std::map<int, const Effects::CBind*>& CMaterial::getTextureBinds () const {
return this->m_textureBindings;
}
const std::string& CMaterial::getTarget () const {
return this->m_target;
}
const std::string& CMaterial::getName () const {
return this->m_name;
}
bool CMaterial::hasTarget () const {
return !this->m_target.empty ();
}
bool CMaterial::isSolidLayer () const {
return this->m_solidlayer;
}

View File

@ -1,89 +0,0 @@
#pragma once
#include "WallpaperEngine/Core/Objects/Effects/CBind.h"
#include "WallpaperEngine/Assets/CContainer.h"
#include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
namespace WallpaperEngine::Core::Objects::Images::Materials {
class CPass;
}
namespace WallpaperEngine::Core::Objects::Images {
using json = nlohmann::json;
using namespace WallpaperEngine::Assets;
/**
* Represents a material in use in the background
*/
class CMaterial {
public:
struct OverrideInfo {
std::map<std::string, int> combos;
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
std::map<int, std::string> textures;
};
static const CMaterial* fromFile (
const std::filesystem::path& filename, const std::shared_ptr<const CContainer>& container, bool solidlayer = false,
std::map<int, const Effects::CBind*> textureBindings = {}, const OverrideInfo* overrides = nullptr);
static const CMaterial* fromFile (
const std::filesystem::path& filename, const std::string& target, const std::shared_ptr<const CContainer>& container,
bool solidlayer = false, std::map<int, const Effects::CBind*> textureBindings = {},
const OverrideInfo* overrides = nullptr);
static const CMaterial* fromJSON (
const std::string& name, const json& data, bool solidlayer = false,
std::map<int, const Effects::CBind*> textureBindings = {}, const OverrideInfo* overrides = nullptr);
static const CMaterial* fromJSON (
const std::string& name, const json& data, const std::string& target, bool solidlayer = false,
std::map<int, const Effects::CBind*> textureBindings = {}, const OverrideInfo* overrides = nullptr);
static const CMaterial* fromCommand (const json& data);
/**
* @return All the rendering passes that happen for this material
*/
[[nodiscard]] const std::vector<const Materials::CPass*>& 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<int, const Effects::CBind*>& 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;
/**
* @return If this material is a solidlayer or not
*/
[[nodiscard]] bool isSolidLayer () const;
protected:
CMaterial (
std::string name, bool solidlayer, std::map<int, const Effects::CBind*> textureBindings,
std::vector<const Materials::CPass*> passes);
CMaterial (
std::string name, std::string target, bool solidlayer, std::map<int, const Effects::CBind*> textureBindings,
std::vector<const Materials::CPass*> passes);
private:
/** All the shader passes required to render this material */
const std::vector<const Materials::CPass*> m_passes;
/** List of texture bind overrides to use for this material */
const std::map<int, const Effects::CBind*> m_textureBindings;
/** The FBO target to render to (if any) */
const std::string m_target;
/** The material's name */
const std::string m_name;
/** If this material is a solid layer or not */
const bool m_solidlayer;
};
} // namespace WallpaperEngine::Core::Objects::Images

View File

@ -1,105 +0,0 @@
#include "CPass.h"
#include "WallpaperEngine/Logging/CLog.h"
#include <utility>
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
using namespace WallpaperEngine::Core::Objects::Images::Materials;
CPass::CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite,
std::string shader, std::map<int, std::string> textures, std::map<std::string, int> combos,
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants) :
m_blending (std::move(blending)),
m_cullmode (std::move(cullmode)),
m_depthtest (std::move(depthtest)),
m_depthwrite (std::move(depthwrite)),
m_shader (std::move(shader)),
m_textures (std::move(textures)),
m_combos (std::move(combos)),
m_constants (std::move(constants)) {}
const CPass* CPass::fromJSON (const json& data, const CMaterial::OverrideInfo* overrides) {
// TODO: FIGURE OUT DEFAULT BLENDING MODE
const auto textures_it = data.find ("textures");
const auto combos_it = data.find ("combos");
std::map<int, std::string> textures;
std::map<std::string, int> combos;
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
if (textures_it != data.end ()) {
// TODO: FETCH THIS FROM CImage TO MAKE IT COMPATIBLE WITH OLDER WALLPAPERS
if (!textures_it->is_array ())
sLog.exception ("Material's textures must be a list");
int textureNumber = -1;
for (const auto& cur : (*textures_it))
textures.emplace (++textureNumber, cur.is_null () ? "" : cur);
}
if (combos_it != data.end ()) {
for (const auto& cur : combos_it->items ()) {
if (cur.value ().is_number_integer ()) {
std::string uppercase = std::string (cur.key ());
std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper);
combos.emplace (uppercase, cur.value ());
} else {
sLog.exception ("unexpected non-integer combo on pass");
}
}
}
// apply overrides
if (overrides != nullptr) {
for (const auto& [name, value] : overrides->combos)
combos[name] = value;
for (const auto& [name, value] : overrides->constants)
constants[name] = value;
for (const auto& [id, value] : overrides->textures)
textures[id] = value;
}
return new CPass (
jsonFindDefault<std::string> (data, "blending", "normal"),
jsonFindDefault<std::string> (data, "cullmode", "nocull"),
jsonFindRequired <std::string> (data, "depthtest", "Material pass must have depthtest specified"),
jsonFindRequired <std::string> (data, "depthwrite", "Material pass must have depthwrite specified"),
jsonFindRequired <std::string> (data, "shader", "Material pass must have shader specified"),
textures,
combos,
constants
);
}
const std::map<int, std::string>& CPass::getTextures () const {
return this->m_textures;
}
const std::map<std::string, const CShaderConstant*>& CPass::getConstants () const {
return this->m_constants;
}
const std::map<std::string, int>& CPass::getCombos () const {
return this->m_combos;
}
const std::string& CPass::getShader () const {
return this->m_shader;
}
const std::string& CPass::getBlendingMode () const {
return this->m_blending;
}
const std::string& CPass::getCullingMode () const {
return this->m_cullmode;
}
const std::string& CPass::getDepthTest () const {
return this->m_depthtest;
}
const std::string& CPass::getDepthWrite () const {
return this->m_depthwrite;
}

View File

@ -1,84 +0,0 @@
#pragma once
#include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
namespace WallpaperEngine::Core::Objects {
class CEffect;
}
namespace WallpaperEngine::Core::Objects::Images {
class CMaterial;
}
namespace WallpaperEngine::Core::Objects::Images::Materials {
using json = nlohmann::json;
/**
* Represents a shader pass of an object
*/
class CPass {
friend class WallpaperEngine::Core::Objects::CEffect;
public:
static const CPass* fromJSON (const json& data, const CMaterial::OverrideInfo* overrides);
/**
* @return The list of textures to bind while rendering
*/
[[nodiscard]] const std::map<int, std::string>& getTextures () const;
/**
* @return Shader constants that alter how the shader should behave
*/
[[nodiscard]] const std::map<std::string, const Effects::Constants::CShaderConstant*>& getConstants () const;
/**
* @return Shader combos that alter how the shader should behave
*/
[[nodiscard]] const std::map<std::string, int>& getCombos () const;
/**
* @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;
protected:
CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite,
std::string shader, std::map<int, std::string> textures, std::map<std::string, int> combos,
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants);
private:
// TODO: CREATE ENUMERATIONS FOR THESE INSTEAD OF USING STRING VALUES!
/** The blending mode to use */
const std::string m_blending;
/** The culling mode to use */
const std::string m_cullmode;
/** If depthtesting has to happen while drawing */
const std::string m_depthtest;
/** If depthwrite has to happen while drawing */
const std::string m_depthwrite;
/** The shader to use */
const std::string m_shader;
/** The list of textures to use */
const std::map<int, std::string> m_textures;
/** Different combo settings for shader input */
const std::map<std::string, int> m_combos;
/** Shader constant values to use for the shaders */
const std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> m_constants;
};
} // namespace WallpaperEngine::Core::Objects::Images::Materials

View File

@ -1,28 +0,0 @@
#include "CCamera.h"
using namespace WallpaperEngine::Core::Scenes;
CCamera::CCamera (glm::vec3 center, glm::vec3 eye, glm::vec3 up) :
m_center (center),
m_eye (eye),
m_up (up) {}
const glm::vec3& CCamera::getCenter () const {
return this->m_center;
}
const glm::vec3& CCamera::getEye () const {
return this->m_eye;
}
const glm::vec3& CCamera::getUp () const {
return this->m_up;
}
const CCamera* CCamera::fromJSON (const json::const_iterator& data) {
return new CCamera (
jsonFindRequired <glm::vec3> (data, "center", "Camera must have a center position"),
jsonFindRequired <glm::vec3> (data, "eye", "Camera must have an eye position"),
jsonFindRequired <glm::vec3> (data, "up", "Camera must have a up position")
);
}

View File

@ -1,24 +0,0 @@
#pragma once
#include "WallpaperEngine/Core/Core.h"
namespace WallpaperEngine::Core::Scenes {
using json = nlohmann::json;
class CCamera {
public:
static const CCamera* fromJSON (const json::const_iterator& data);
const glm::vec3& getCenter () const;
const glm::vec3& getEye () const;
const glm::vec3& getUp () const;
protected:
CCamera (glm::vec3 center, glm::vec3 eye, glm::vec3 up);
private:
const glm::vec3 m_center;
const glm::vec3 m_eye;
const glm::vec3 m_up;
};
} // namespace WallpaperEngine::Core::Scenes

View File

@ -1,46 +0,0 @@
#include "CProjection.h"
using namespace WallpaperEngine::Core::Scenes;
CProjection::CProjection (int width, int height) :
m_width (width),
m_height (height),
m_isAuto (false) {}
CProjection::CProjection (bool isAuto) :
m_width (0),
m_height (0),
m_isAuto (isAuto) {}
const int& CProjection::getWidth () const {
return this->m_width;
}
const int& CProjection::getHeight () const {
return this->m_height;
}
bool CProjection::isAuto () const {
return this->m_isAuto;
}
void CProjection::setWidth (int width) const {
this->m_width = width;
}
void CProjection::setHeight (int height) const {
this->m_height = height;
}
const CProjection* CProjection::fromJSON (const json::const_iterator& data) {
const auto auto_it = jsonFindDefault<bool> (data, "auto", false);
const auto width_it = jsonFindRequired (data, "width", "Projection must have width");
const auto height_it = jsonFindRequired (data, "height", "Projection must have height");
// TODO: PROPERLY SUPPORT AUTO-DETECTING SIZE
if (auto_it)
return new CProjection (true);
return new CProjection (*width_it, *height_it);
}

View File

@ -1,29 +0,0 @@
#pragma once
#include "WallpaperEngine/Core/Core.h"
namespace WallpaperEngine::Core::Scenes {
using json = nlohmann::json;
class CProjection {
public:
static const CProjection* fromJSON (const json::const_iterator& data);
[[nodiscard]] const int& getWidth () const;
[[nodiscard]] const int& getHeight () const;
[[nodiscard]] bool isAuto () const;
// TODO: CHANGE THIS SO THE RENDER IS THE ONE RESPONSIBLE FOR THIS?
void setWidth (int width) const;
void setHeight (int height) const;
protected:
CProjection (int width, int height);
explicit CProjection (bool isAuto);
private:
mutable int m_width;
mutable int m_height;
const bool m_isAuto;
};
} // namespace WallpaperEngine::Core::Scenes

View File

@ -3,7 +3,6 @@
#include <utility> #include <utility>
#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Core/CProject.h"
#include "WallpaperEngine/Core/Projects/CProperty.h" #include "WallpaperEngine/Core/Projects/CProperty.h"
#include "WallpaperEngine/Core/Projects/CPropertyBoolean.h" #include "WallpaperEngine/Core/Projects/CPropertyBoolean.h"
#include "WallpaperEngine/Core/Projects/CPropertyCombo.h" #include "WallpaperEngine/Core/Projects/CPropertyCombo.h"

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "CUserSettingValue.h" #include "CUserSettingValue.h"
#include "WallpaperEngine/Core/CProject.h"
namespace WallpaperEngine::Core::Projects { namespace WallpaperEngine::Core::Projects {
class CProperty; class CProperty;

View File

@ -3,7 +3,6 @@
#include <utility> #include <utility>
#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Core/CProject.h"
#include "WallpaperEngine/Core/Projects/CProperty.h" #include "WallpaperEngine/Core/Projects/CProperty.h"
#include "WallpaperEngine/Core/Projects/CPropertySlider.h" #include "WallpaperEngine/Core/Projects/CPropertySlider.h"
#include "WallpaperEngine/Logging/CLog.h" #include "WallpaperEngine/Logging/CLog.h"

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "CUserSettingValue.h" #include "CUserSettingValue.h"
#include "WallpaperEngine/Core/CProject.h"
namespace WallpaperEngine::Core::Projects { namespace WallpaperEngine::Core::Projects {
class CProperty; class CProperty;

View File

@ -3,7 +3,6 @@
#include <glm/vec3.hpp> #include <glm/vec3.hpp>
#include "CUserSettingValue.h" #include "CUserSettingValue.h"
#include "WallpaperEngine/Core/CProject.h"
namespace WallpaperEngine::Core::Projects { namespace WallpaperEngine::Core::Projects {
class CProperty; class CProperty;

View File

@ -1,172 +0,0 @@
#include "CScene.h"
#include <utility>
#include "WallpaperEngine/Core/CProject.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Wallpapers;
CScene::CScene (
std::shared_ptr <const CProject> project, std::shared_ptr<const CContainer> container, const Scenes::CCamera* camera,
glm::vec3 ambientColor, const CUserSettingBoolean* bloom, const CUserSettingFloat* bloomStrength,
const CUserSettingFloat* bloomThreshold, bool cameraFade, bool cameraParallax, float cameraParallaxAmount,
float cameraParallaxDelay, float cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake,
float cameraShakeAmplitude, float cameraShakeRoughness, float cameraShakeSpeed,
const CUserSettingVector3* clearColor, const Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor
) :
CWallpaper (project),
m_container (std::move(container)),
m_camera (camera),
m_ambientColor (ambientColor),
m_bloom (bloom),
m_bloomStrength (bloomStrength),
m_bloomThreshold (bloomThreshold),
m_cameraFade (cameraFade),
m_cameraParallax (cameraParallax),
m_cameraParallaxAmount (cameraParallaxAmount),
m_cameraParallaxDelay (cameraParallaxDelay),
m_cameraParallaxMouseInfluence (cameraParallaxMouseInfluence),
m_cameraPreview (cameraPreview),
m_cameraShake (cameraShake),
m_cameraShakeAmplitude (cameraShakeAmplitude),
m_cameraShakeRoughness (cameraShakeRoughness),
m_cameraShakeSpeed (cameraShakeSpeed),
m_clearColor (clearColor),
m_orthogonalProjection (orthogonalProjection),
m_skylightColor (skylightColor) {}
std::shared_ptr <const CScene> CScene::fromFile (
const std::string& filename, std::shared_ptr <const Core::CProject> project,
const std::shared_ptr<const CContainer>& container
) {
json content = json::parse (container->readFileAsString (filename));
const auto general_it = jsonFindRequired (content, "general", "Scenes must have a general section");
const auto objects_it = jsonFindRequired (content, "objects", "Scenes must have a list of objects to display");
// TODO: FIND IF THESE DEFAULTS ARE SENSIBLE OR NOT AND PERFORM PROPER VALIDATION WHEN CAMERA PREVIEW AND CAMERA
// PARALLAX ARE PRESENT
auto scene = std::make_shared <CScene> (
project, container,
Scenes::CCamera::fromJSON (jsonFindRequired (content, "camera", "Scenes must have a defined camera")),
jsonFindDefault<glm::vec3> (*general_it, "ambientcolor", glm::vec3 (0, 0, 0)),
jsonFindUserConfig<CUserSettingBoolean> (*general_it, *project, "bloom", false),
jsonFindUserConfig<CUserSettingFloat> (*general_it, *project, "bloomstrength", 0.0),
jsonFindUserConfig<CUserSettingFloat> (*general_it, *project, "bloomthreshold", 0.0),
jsonFindDefault<bool> (*general_it, "camerafade", false),
jsonFindDefault<bool> (*general_it, "cameraparallax", true),
jsonFindDefault<float> (*general_it, "cameraparallaxamount", 1.0f),
jsonFindDefault<float> (*general_it, "cameraparallaxdelay", 0.0f),
jsonFindDefault<float> (*general_it, "cameraparallaxmouseinfluence", 1.0f),
jsonFindDefault<bool> (*general_it, "camerapreview", false),
jsonFindDefault<bool> (*general_it, "camerashake", false),
jsonFindDefault<float> (*general_it, "camerashakeamplitude", 0.0f),
jsonFindDefault<float> (*general_it, "camerashakeroughness", 0.0f),
jsonFindDefault<float> (*general_it, "camerashakespeed", 0.0f),
jsonFindUserConfig<CUserSettingVector3> (*general_it, *project, "clearcolor", {1, 1, 1}),
Scenes::CProjection::fromJSON (jsonFindRequired (*general_it, "orthogonalprojection", "General section must have orthogonal projection info")),
jsonFindDefault<glm::vec3> (*general_it, "skylightcolor", glm::vec3 (0, 0, 0))
);
for (const auto& cur : *objects_it)
scene->insertObject (CObject::fromJSON (cur, project, container));
return scene;
}
const std::map<uint32_t, const CObject*>& CScene::getObjects () const {
return this->m_objects;
}
const std::vector<const CObject*>& CScene::getObjectsByRenderOrder () const {
return this->m_objectsByRenderOrder;
}
void CScene::insertObject (const CObject* object) {
/// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED
if (object != nullptr) {
this->m_objects.emplace (object->getId (), object);
this->m_objectsByRenderOrder.emplace_back (object);
}
}
std::shared_ptr<const CContainer> CScene::getContainer () const {
return this->m_container;
}
const Scenes::CCamera* CScene::getCamera () const {
return this->m_camera;
}
const glm::vec3& CScene::getAmbientColor () const {
return this->m_ambientColor;
}
bool CScene::isBloom () const {
return this->m_bloom->getBool ();
}
float CScene::getBloomStrength () const {
return this->m_bloomStrength->getFloat ();
}
float CScene::getBloomThreshold () const {
return this->m_bloomThreshold->getFloat ();
}
bool CScene::isCameraFade () const {
return this->m_cameraFade;
}
bool CScene::isCameraParallax () const {
return this->m_cameraParallax;
}
float CScene::getCameraParallaxAmount () const {
return this->m_cameraParallaxAmount;
}
float CScene::getCameraParallaxDelay () const {
return this->m_cameraParallaxDelay;
}
float CScene::getCameraParallaxMouseInfluence () const {
return this->m_cameraParallaxMouseInfluence;
}
bool CScene::isCameraPreview () const {
return this->m_cameraPreview;
}
bool CScene::isCameraShake () const {
return this->m_cameraShake;
}
float CScene::getCameraShakeAmplitude () const {
return this->m_cameraShakeAmplitude;
}
float CScene::getCameraShakeRoughness () const {
return this->m_cameraShakeRoughness;
}
float CScene::getCameraShakeSpeed () const {
return this->m_cameraShakeSpeed;
}
const glm::vec3& CScene::getClearColor () const {
return this->m_clearColor->getVec3 ();
}
const Scenes::CProjection* CScene::getOrthogonalProjection () const {
return this->m_orthogonalProjection;
}
const glm::vec3& CScene::getSkylightColor () const {
return this->m_skylightColor;
}

View File

@ -1,88 +0,0 @@
#pragma once
#include "WallpaperEngine/Core/CObject.h"
#include "WallpaperEngine/Core/CWallpaper.h"
#include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Core/Scenes/CCamera.h"
#include "WallpaperEngine/Core/Scenes/CProjection.h"
namespace WallpaperEngine::Core {
class CObject;
}
namespace WallpaperEngine::Core::Wallpapers {
using json = nlohmann::json;
class CScene : public CWallpaper {
public:
CScene (
std::shared_ptr <const Core::CProject> project, std::shared_ptr<const CContainer> container,
const Scenes::CCamera* camera, glm::vec3 ambientColor, const CUserSettingBoolean* bloom,
const CUserSettingFloat* bloomStrength, const CUserSettingFloat* bloomThreshold, bool cameraFade,
bool cameraParallax, float cameraParallaxAmount, float cameraParallaxDelay, float cameraParallaxMouseInfluence,
bool cameraPreview, bool cameraShake, float cameraShakeAmplitude, float cameraShakeRoughness,
float cameraShakeSpeed, const CUserSettingVector3* clearColor, const Scenes::CProjection* orthogonalProjection,
glm::vec3 skylightColor);
static std::shared_ptr <const CScene> fromFile (
const std::string& filename, std::shared_ptr <const Core::CProject> project,
const std::shared_ptr<const CContainer>& container);
[[nodiscard]] const std::map<uint32_t, const CObject*>& getObjects () const;
[[nodiscard]] const std::vector<const CObject*>& getObjectsByRenderOrder () const;
[[nodiscard]] const glm::vec3& getAmbientColor () const;
[[nodiscard]] bool isBloom () const;
[[nodiscard]] float getBloomStrength () const;
[[nodiscard]] float getBloomThreshold () const;
[[nodiscard]] bool isCameraFade () const;
[[nodiscard]] bool isCameraParallax () const;
[[nodiscard]] float getCameraParallaxAmount () const;
[[nodiscard]] float getCameraParallaxDelay () const;
[[nodiscard]] float getCameraParallaxMouseInfluence () const;
[[nodiscard]] bool isCameraPreview () const;
[[nodiscard]] bool isCameraShake () const;
[[nodiscard]] float getCameraShakeAmplitude () const;
[[nodiscard]] float getCameraShakeRoughness () const;
[[nodiscard]] float getCameraShakeSpeed () const;
[[nodiscard]] const glm::vec3& getClearColor () const;
[[nodiscard]] const Scenes::CProjection* getOrthogonalProjection () const;
[[nodiscard]] const glm::vec3& getSkylightColor () const;
[[nodiscard]] const Scenes::CCamera* getCamera () const;
protected:
friend class CWallpaper;
void insertObject (const CObject* object);
[[nodiscard]] std::shared_ptr<const CContainer> getContainer () const;
private:
const std::shared_ptr<const CContainer> m_container;
const Scenes::CCamera* m_camera;
// data from general section on the json
const glm::vec3 m_ambientColor;
const CUserSettingBoolean* m_bloom;
const CUserSettingFloat* m_bloomStrength;
const CUserSettingFloat* m_bloomThreshold;
const bool m_cameraFade;
const bool m_cameraParallax;
const float m_cameraParallaxAmount;
const float m_cameraParallaxDelay;
const float m_cameraParallaxMouseInfluence;
const bool m_cameraPreview;
const bool m_cameraShake;
const float m_cameraShakeAmplitude;
const float m_cameraShakeRoughness;
const float m_cameraShakeSpeed;
const CUserSettingVector3* m_clearColor;
const Scenes::CProjection* m_orthogonalProjection;
const glm::vec3 m_skylightColor;
std::map<uint32_t, const CObject*> m_objects = {};
std::vector<const CObject*> m_objectsByRenderOrder = {};
};
} // namespace WallpaperEngine::Core

View File

@ -1,14 +0,0 @@
#include "CVideo.h"
#include <utility>
using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Wallpapers;
CVideo::CVideo (std::string filename, std::shared_ptr <const CProject> project) :
CWallpaper (project),
m_filename (std::move(filename)) {}
const std::string& CVideo::getFilename () const {
return this->m_filename;
}

View File

@ -1,25 +0,0 @@
#pragma once
#include "WallpaperEngine/Core/CWallpaper.h"
#include "WallpaperEngine/Core/Core.h"
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
}
namespace WallpaperEngine::Core::Wallpapers {
class CVideo : public CWallpaper {
public:
CVideo (std::string filename, std::shared_ptr <const CProject> project);
const std::string& getFilename () const;
protected:
friend class CWallpaper;
const std::string m_filename;
};
} // namespace WallpaperEngine::Core

View File

@ -1,14 +0,0 @@
#include "CWeb.h"
#include <utility>
using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Wallpapers;
const std::string& CWeb::getFilename () const {
return this->m_filename;
}
CWeb::CWeb (std::string filename, std::shared_ptr <const CProject> project) :
CWallpaper (project),
m_filename (std::move(filename)) {}

View File

@ -1,31 +0,0 @@
#pragma once
#include "WallpaperEngine/Core/CWallpaper.h"
#include "WallpaperEngine/Core/Core.h"
// Chromium Embedded Framework
#include "include/cef_render_handler.h"
#include "include/cef_client.h"
#include "include/cef_app.h"
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
}
namespace WallpaperEngine::Core::Wallpapers {
class CWeb : public CWallpaper {
public:
CWeb (std::string filename, std::shared_ptr <const CProject> project);
const std::string& getFilename () const;
protected:
friend class CWallpaper;
const std::string m_filename;
};
}

View File

@ -39,7 +39,7 @@ void StringPrinter::printWallpaper (const Wallpaper& wallpaper) {
for (const auto& object : scene->objects) { for (const auto& object : scene->objects) {
this->lineEnd (); this->lineEnd ();
this->printObject (*object.second); this->printObject (*object);
this->lineEnd (); this->lineEnd ();
} }

View File

@ -29,7 +29,7 @@ struct EffectPass {
/** The material to use for this effect's pass */ /** The material to use for this effect's pass */
MaterialUniquePtr material; MaterialUniquePtr material;
/** Texture bindings for this effect's pass */ /** Texture bindings for this effect's pass */
std::map <int, std::string> binds; TextureMap binds;
/** The command this material executes (if specified) */ /** The command this material executes (if specified) */
std::optional <PassCommand> command; std::optional <PassCommand> command;
/** The target this material renders to (if specified) */ /** The target this material renders to (if specified) */

View File

@ -21,9 +21,9 @@ struct MaterialPass {
/** Shader file to use for this pass */ /** Shader file to use for this pass */
std::string shader; std::string shader;
/** List of textures defined for this pass */ /** List of textures defined for this pass */
std::map <int, std::string> textures; TextureMap textures;
/** The combos and their values to pass onto the shader */ /** The combos and their values to pass onto the shader */
std::map <std::string, int> combos; ComboMap combos;
}; };
struct Material { struct Material {

View File

@ -110,6 +110,7 @@ class Image : public Object, public ImageData {
struct SoundData { struct SoundData {
/** Playback mode, loop, */ /** Playback mode, loop, */
// TODO: WRITE AN ENUM FOR THIS
std::optional <std::string> playbackmode; std::optional <std::string> playbackmode;
std::vector <std::string> sounds; std::vector <std::string> sounds;
}; };

View File

@ -6,7 +6,6 @@
#include "Types.h" #include "Types.h"
namespace WallpaperEngine::Data::Model { namespace WallpaperEngine::Data::Model {
using json = WallpaperEngine::Data::JSON::JSON;
/** /**
* Represents a wallpaper engine project * Represents a wallpaper engine project
*/ */
@ -31,8 +30,8 @@ struct Project {
Properties properties; Properties properties;
/** The wallpaper this project defines */ /** The wallpaper this project defines */
WallpaperSharedPtr wallpaper; WallpaperUniquePtr wallpaper;
/** VFS to access the project's files */ /** VFS to access the project's files */
ContainerWeakPtr container; ContainerUniquePtr container;
}; };
}; };

View File

@ -58,15 +58,12 @@ using ShaderConstantUniquePtr = std::unique_ptr <ShaderConstant>;
using ShaderConstantMap = std::map <std::string, ShaderConstantUniquePtr>; using ShaderConstantMap = std::map <std::string, ShaderConstantUniquePtr>;
using ProjectSharedPtr = std::shared_ptr <Project>; using ProjectUniquePtr = std::unique_ptr <Project>;
using WallpaperSharedPtr = std::shared_ptr <Wallpaper>; using WallpaperUniquePtr = std::unique_ptr <Wallpaper>;
using WallpaperWeakPtr = std::weak_ptr <Wallpaper>; using ContainerUniquePtr = std::unique_ptr <Container>;
using ProjectWeakPtr = std::weak_ptr <Project>; using SceneUniquePtr = std::unique_ptr <Scene>;
using ContainerSharedPtr = std::shared_ptr <Container>; using WebUniquePtr = std::unique_ptr <Web>;
using ContainerWeakPtr = std::weak_ptr <Container>; using VideoUniquePtr = std::unique_ptr <Video>;
using SceneSharedPtr = std::shared_ptr <Scene>;
using WebSharedPtr = std::shared_ptr <Web>;
using VideoSharedPtr = std::shared_ptr <Video>;
using ObjectUniquePtr = std::unique_ptr <Object>; using ObjectUniquePtr = std::unique_ptr <Object>;
using SoundUniquePtr = std::unique_ptr <Sound>; using SoundUniquePtr = std::unique_ptr <Sound>;
using ImageUniquePtr = std::unique_ptr <Image>; using ImageUniquePtr = std::unique_ptr <Image>;
@ -80,7 +77,7 @@ using EffectPassUniquePtr = std::unique_ptr <EffectPass>;
using FBOUniquePtr = std::unique_ptr <FBO>; using FBOUniquePtr = std::unique_ptr <FBO>;
using ModelUniquePtr = std::unique_ptr <ModelStruct>; using ModelUniquePtr = std::unique_ptr <ModelStruct>;
using ObjectMap = std::map<int, ObjectUniquePtr>; using ObjectList = std::vector<ObjectUniquePtr>;
using ComboMap = std::map<std::string, int>; using ComboMap = std::map<std::string, int>;
using TextureMap = std::map<int, std::string>; using TextureMap = std::map<int, std::string>;
} }

View File

@ -16,7 +16,7 @@ using TypeCaster = WallpaperEngine::Data::Utils::TypeCaster;
struct WallpaperData { struct WallpaperData {
std::string filename; std::string filename;
ProjectWeakPtr project; Project& project;
}; };
class Wallpaper : public TypeCaster, public WallpaperData { class Wallpaper : public TypeCaster, public WallpaperData {
@ -49,7 +49,7 @@ struct SceneData {
/** /**
* Camera configuration * Camera configuration
*/ */
struct { struct Camera {
/** Enable fade effect */ /** Enable fade effect */
bool fade; bool fade;
/** Used by the software to allow the users to preview the background or not? */ /** Used by the software to allow the users to preview the background or not? */
@ -104,8 +104,8 @@ struct SceneData {
bool isAuto; bool isAuto;
} projection; } projection;
} camera; } camera;
ObjectMap objects;
ProjectWeakPtr project; ObjectList objects;
}; };
class Scene : public Wallpaper, public SceneData { class Scene : public Wallpaper, public SceneData {

View File

@ -8,13 +8,13 @@
using namespace WallpaperEngine::Data::Parsers; using namespace WallpaperEngine::Data::Parsers;
using namespace WallpaperEngine::Data::Model; using namespace WallpaperEngine::Data::Model;
EffectUniquePtr EffectParser::load (const ProjectWeakPtr& project, const std::string& filename) { EffectUniquePtr EffectParser::load (Project& project, const std::string& filename) {
const auto effectJson = JSON::parse (project.lock ()->container.lock ()->readFileAsString (filename)); const auto effectJson = JSON::parse (project.container->readFileAsString (filename));
return parse (effectJson, project); return parse (effectJson, project);
} }
EffectUniquePtr EffectParser::parse (const JSON& it, const ProjectWeakPtr& project) { EffectUniquePtr EffectParser::parse (const JSON& it, Project& project) {
const auto dependencies = it.optional ("dependencies"); const auto dependencies = it.optional ("dependencies");
return std::make_unique <Effect> (Effect { return std::make_unique <Effect> (Effect {
@ -41,7 +41,7 @@ std::vector <std::string> EffectParser::parseDependencies (const JSON& it) {
return result; return result;
} }
std::vector <EffectPassUniquePtr> EffectParser::parseEffectPasses (const JSON& it, const ProjectWeakPtr& project) { std::vector <EffectPassUniquePtr> EffectParser::parseEffectPasses (const JSON& it, Project& project) {
std::vector <EffectPassUniquePtr> result = {}; std::vector <EffectPassUniquePtr> result = {};
if (!it.is_array ()) { if (!it.is_array ()) {

View File

@ -9,12 +9,12 @@ using namespace WallpaperEngine::Data::Model;
class EffectParser { class EffectParser {
public: public:
static EffectUniquePtr load (const ProjectWeakPtr& project, const std::string& filename); static EffectUniquePtr load (Project& project, const std::string& filename);
private: private:
static EffectUniquePtr parse (const JSON& it, const ProjectWeakPtr& project); static EffectUniquePtr parse (const JSON& it, Project& project);
static std::vector <std::string> parseDependencies (const JSON& it); static std::vector <std::string> parseDependencies (const JSON& it);
static std::vector <EffectPassUniquePtr> parseEffectPasses (const JSON& it, const ProjectWeakPtr& project); static std::vector <EffectPassUniquePtr> parseEffectPasses (const JSON& it, Project& project);
static std::map <int, std::string> parseBinds (const JSON& it); static std::map <int, std::string> parseBinds (const JSON& it);
}; };
} // namespace WallpaperEngine::Data::Parsers } // namespace WallpaperEngine::Data::Parsers

View File

@ -6,21 +6,20 @@
using namespace WallpaperEngine::Data::Parsers; using namespace WallpaperEngine::Data::Parsers;
using namespace WallpaperEngine::Data::Model; using namespace WallpaperEngine::Data::Model;
MaterialUniquePtr MaterialParser::load (const ProjectWeakPtr& project, const std::string& filename) { MaterialUniquePtr MaterialParser::load (Project& project, const std::string& filename) {
const auto materialJson = JSON::parse (project.lock ()->container.lock ()->readFileAsString (filename)); const auto materialJson = JSON::parse (project.container->readFileAsString (filename));
return parse (materialJson, project, filename); return parse (materialJson, project, filename);
} }
MaterialUniquePtr MaterialParser::parse (const JSON& it, const ProjectWeakPtr& project, const std::string& filename) { MaterialUniquePtr MaterialParser::parse (const JSON& it, Project& project, const std::string& filename) {
return std::make_unique <Material> (Material { return std::make_unique <Material> (Material {
.filename = filename, .filename = filename,
//TODO: PARSE PASSES
.passes = parsePasses (it.require ("passes", "Material must have passes to render"), project), .passes = parsePasses (it.require ("passes", "Material must have passes to render"), project),
}); });
} }
std::vector <MaterialPassUniquePtr> MaterialParser::parsePasses (const JSON& it, const ProjectWeakPtr& project) { std::vector <MaterialPassUniquePtr> MaterialParser::parsePasses (const JSON& it, Project& project) {
std::vector <MaterialPassUniquePtr> result = {}; std::vector <MaterialPassUniquePtr> result = {};
if (!it.is_array ()) { if (!it.is_array ()) {
@ -34,7 +33,7 @@ std::vector <MaterialPassUniquePtr> MaterialParser::parsePasses (const JSON& it,
return result; return result;
} }
MaterialPassUniquePtr MaterialParser::parsePass (const JSON& it, const ProjectWeakPtr& project) { MaterialPassUniquePtr MaterialParser::parsePass (const JSON& it, Project& project) {
const auto textures = it.optional ("textures"); const auto textures = it.optional ("textures");
const auto combos = it.optional ("combos"); const auto combos = it.optional ("combos");
const auto constants = it.optional ("constants"); const auto constants = it.optional ("constants");

View File

@ -9,10 +9,10 @@ using namespace WallpaperEngine::Data::Model;
class MaterialParser { class MaterialParser {
public: public:
static MaterialUniquePtr load (const ProjectWeakPtr& project, const std::string& filename); static MaterialUniquePtr load (Project& project, const std::string& filename);
static MaterialUniquePtr parse (const JSON& it, const ProjectWeakPtr& project, const std::string& filename); static MaterialUniquePtr parse (const JSON& it, Project& project, const std::string& filename);
static std::vector <MaterialPassUniquePtr> parsePasses (const JSON& it, const ProjectWeakPtr& project); static std::vector <MaterialPassUniquePtr> parsePasses (const JSON& it, Project& project);
static MaterialPassUniquePtr parsePass (const JSON& it, const ProjectWeakPtr& project); static MaterialPassUniquePtr parsePass (const JSON& it, Project& project);
static std::map <int, std::string> parseTextures (const JSON& it); static std::map <int, std::string> parseTextures (const JSON& it);
static std::map <std::string, int> parseCombos (const JSON& it); static std::map <std::string, int> parseCombos (const JSON& it);
}; };

View File

@ -8,13 +8,13 @@
using namespace WallpaperEngine::Data::Parsers; using namespace WallpaperEngine::Data::Parsers;
using namespace WallpaperEngine::Data::Model; using namespace WallpaperEngine::Data::Model;
ModelUniquePtr ModelParser::load (const ProjectWeakPtr& project, const std::string& filename) { ModelUniquePtr ModelParser::load (Project& project, const std::string& filename) {
const auto model = JSON::parse (project.lock ()->container.lock ()->readFileAsString (filename)); const auto model = JSON::parse (project.container->readFileAsString (filename));
return parse (model, project, filename); return parse (model, project, filename);
} }
ModelUniquePtr ModelParser::parse (const JSON& file, const ProjectWeakPtr& project, const std::string& filename) { ModelUniquePtr ModelParser::parse (const JSON& file, Project& project, const std::string& filename) {
const auto material = file.require <std::string> ("material", "Model must have a material"); const auto material = file.require <std::string> ("material", "Model must have a material");
return std::make_unique <ModelStruct> (ModelStruct { return std::make_unique <ModelStruct> (ModelStruct {

View File

@ -9,7 +9,7 @@ using namespace WallpaperEngine::Data::Model;
class ModelParser { class ModelParser {
public: public:
static ModelUniquePtr load (const ProjectWeakPtr& project, const std::string& filename); static ModelUniquePtr load (Project& project, const std::string& filename);
static ModelUniquePtr parse (const JSON& file, const ProjectWeakPtr& project, const std::string& filename); static ModelUniquePtr parse (const JSON& file, Project& project, const std::string& filename);
}; };
} // namespace WallpaperEngine::Data::Parsers } // namespace WallpaperEngine::Data::Parsers

View File

@ -10,7 +10,7 @@
using namespace WallpaperEngine::Data::Parsers; using namespace WallpaperEngine::Data::Parsers;
using namespace WallpaperEngine::Data::Model; using namespace WallpaperEngine::Data::Model;
ObjectUniquePtr ObjectParser::parse (const JSON& it, const ProjectWeakPtr& project) { ObjectUniquePtr ObjectParser::parse (const JSON& it, Project& project) {
const auto imageIt = it.find ("image"); const auto imageIt = it.find ("image");
const auto soundIt = it.find ("sound"); const auto soundIt = it.find ("sound");
const auto particleIt = it.find ("particle"); const auto particleIt = it.find ("particle");
@ -56,7 +56,7 @@ std::vector<int> ObjectParser::parseDependencies (const JSON& it) {
return result; return result;
} }
SoundUniquePtr ObjectParser::parseSound (const JSON& it, const ProjectWeakPtr& project, ObjectData base) { SoundUniquePtr ObjectParser::parseSound (const JSON& it, Project& project, ObjectData base) {
const auto soundIt = it.require ("sound", "Object must have a sound"); const auto soundIt = it.require ("sound", "Object must have a sound");
std::vector<std::string> sounds = {}; std::vector<std::string> sounds = {};
@ -74,8 +74,8 @@ SoundUniquePtr ObjectParser::parseSound (const JSON& it, const ProjectWeakPtr& p
} }
ImageUniquePtr ObjectParser::parseImage ( ImageUniquePtr ObjectParser::parseImage (
const JSON& it, const ProjectWeakPtr& project, ObjectData base, const std::string& image) { const JSON& it, Project& project, ObjectData base, const std::string& image) {
const auto& properties = project.lock ()->properties; const auto& properties = project.properties;
const auto& effects = it.optional ("effects"); const auto& effects = it.optional ("effects");
return std::make_unique <Image> ( return std::make_unique <Image> (
@ -98,7 +98,7 @@ ImageUniquePtr ObjectParser::parseImage (
); );
} }
std::vector <ImageEffectUniquePtr> ObjectParser::parseEffects (const JSON& it, const ProjectWeakPtr& project) { std::vector <ImageEffectUniquePtr> ObjectParser::parseEffects (const JSON& it, Project& project) {
if (!it.is_array ()) { if (!it.is_array ()) {
return {}; return {};
} }
@ -112,18 +112,18 @@ std::vector <ImageEffectUniquePtr> ObjectParser::parseEffects (const JSON& it, c
return result; return result;
} }
ImageEffectUniquePtr ObjectParser::parseEffect (const JSON& it, const ProjectWeakPtr& project) { ImageEffectUniquePtr ObjectParser::parseEffect (const JSON& it, Project& project) {
const auto& passsOverrides = it.optional ("passes"); const auto& passsOverrides = it.optional ("passes");
return std::make_unique <ImageEffect> (ImageEffect { return std::make_unique <ImageEffect> (ImageEffect {
.id = it.require <int> ("id", "Image effect must have an id"), .id = it.require <int> ("id", "Image effect must have an id"),
.name = it.require <std::string> ("name", "Image effect must have a name"), .name = it.require <std::string> ("name", "Image effect must have a name"),
.visible = it.user ("visible", project.lock ()->properties, true), .visible = it.user ("visible", project.properties, true),
.passOverrides = passsOverrides.has_value () ? parseEffectPassOverrides (passsOverrides.value (), project) : std::vector <ImageEffectPassOverrideUniquePtr> {}, .passOverrides = passsOverrides.has_value () ? parseEffectPassOverrides (passsOverrides.value (), project) : std::vector <ImageEffectPassOverrideUniquePtr> {},
.effect = EffectParser::load (project, it.require ("file", "Image effect must have an effect")) .effect = EffectParser::load (project, it.require ("file", "Image effect must have an effect"))
}); });
} }
std::vector <ImageEffectPassOverrideUniquePtr> ObjectParser::parseEffectPassOverrides (const JSON& it, const ProjectWeakPtr& project) { std::vector <ImageEffectPassOverrideUniquePtr> ObjectParser::parseEffectPassOverrides (const JSON& it, Project& project) {
if (!it.is_array ()) { if (!it.is_array ()) {
return {}; return {};
} }
@ -137,14 +137,14 @@ std::vector <ImageEffectPassOverrideUniquePtr> ObjectParser::parseEffectPassOver
return result; return result;
} }
ImageEffectPassOverrideUniquePtr ObjectParser::parseEffectPass (const JSON& it, const ProjectWeakPtr& project) { ImageEffectPassOverrideUniquePtr ObjectParser::parseEffectPass (const JSON& it, Project& project) {
const auto& combos = it.optional ("combos"); const auto& combos = it.optional ("combos");
const auto& textures = it.optional ("textures"); const auto& textures = it.optional ("textures");
const auto& constants = it.optional ("constantshadervalues"); const auto& constants = it.optional ("constantshadervalues");
// TODO: PARSE CONSTANT SHADER VALUES AND FIND REFS? // TODO: PARSE CONSTANT SHADER VALUES AND FIND REFS?
return std::make_unique <ImageEffectPassOverride> (ImageEffectPassOverride { return std::make_unique <ImageEffectPassOverride> (ImageEffectPassOverride {
.id = it.require <int> ("id", "Image effect pass must have an id"), .id = it.optional <int> ("id", -1),
.combos = combos.has_value () ? parseComboMap (combos.value ()) : ComboMap {}, .combos = combos.has_value () ? parseComboMap (combos.value ()) : ComboMap {},
.constants = constants.has_value () ? ShaderConstantParser::parse (constants.value (), project) : ShaderConstantMap {}, .constants = constants.has_value () ? ShaderConstantParser::parse (constants.value (), project) : ShaderConstantMap {},
.textures = textures.has_value () ? parseTextureMap (textures.value ()) : TextureMap {}, .textures = textures.has_value () ? parseTextureMap (textures.value ()) : TextureMap {},

View File

@ -15,17 +15,17 @@ using namespace WallpaperEngine::Data::Model;
class ObjectParser { class ObjectParser {
public: public:
static ObjectUniquePtr parse (const JSON& it, const ProjectWeakPtr& project); static ObjectUniquePtr parse (const JSON& it, Project& project);
private: private:
static std::vector<int> parseDependencies (const JSON& it); static std::vector<int> parseDependencies (const JSON& it);
static SoundUniquePtr parseSound (const JSON& it, const ProjectWeakPtr& project, ObjectData base); static SoundUniquePtr parseSound (const JSON& it, Project& project, ObjectData base);
static ImageUniquePtr parseImage ( static ImageUniquePtr parseImage (
const JSON& it, const ProjectWeakPtr& project, ObjectData base, const std::string& image); const JSON& it, Project& project, ObjectData base, const std::string& image);
static std::vector <ImageEffectUniquePtr> parseEffects (const JSON& it, const ProjectWeakPtr& project); static std::vector <ImageEffectUniquePtr> parseEffects (const JSON& it, Project& project);
static ImageEffectUniquePtr parseEffect (const JSON& it, const ProjectWeakPtr& project); static ImageEffectUniquePtr parseEffect (const JSON& it, Project& project);
static std::vector <ImageEffectPassOverrideUniquePtr> parseEffectPassOverrides (const JSON& it, const ProjectWeakPtr& project); static std::vector <ImageEffectPassOverrideUniquePtr> parseEffectPassOverrides (const JSON& it, Project& project);
static ImageEffectPassOverrideUniquePtr parseEffectPass (const JSON& it, const ProjectWeakPtr& project); static ImageEffectPassOverrideUniquePtr parseEffectPass (const JSON& it, Project& project);
static TextureMap parseTextureMap (const JSON& it); static TextureMap parseTextureMap (const JSON& it);
static ComboMap parseComboMap (const JSON& it); static ComboMap parseComboMap (const JSON& it);
}; };

View File

@ -5,27 +5,29 @@
#include "WallpaperParser.h" #include "WallpaperParser.h"
#include "WallpaperEngine/Data/Model/Wallpaper.h"
using namespace WallpaperEngine::Data::Parsers; using namespace WallpaperEngine::Data::Parsers;
static int backgroundId = 0; static int backgroundId = 0;
ProjectSharedPtr ProjectParser::parse (const JSON& data, const ContainerWeakPtr& container) { ProjectUniquePtr ProjectParser::parse (const JSON& data, ContainerUniquePtr container) {
const auto general = data.optional ("general"); const auto general = data.optional ("general");
auto type = data.require <std::string> ("type", "Project type missing"); auto type = data.require <std::string> ("type", "Project type missing");
// lowercase for consistency // lowercase for consistency
std::transform (type.begin (), type.end (), type.begin (), tolower); std::transform (type.begin (), type.end (), type.begin (), tolower);
auto result = std::make_shared <Project> (Project { auto result = std::make_unique <Project> (Project {
.title = data.require <std::string> ("title", "Project title missing"), .title = data.require <std::string> ("title", "Project title missing"),
.type = parseType (type), .type = parseType (type),
.workshopId = data.optional ("workshopid", std::to_string (--backgroundId)), .workshopId = data.optional ("workshopid", std::to_string (--backgroundId)),
.supportsAudioProcessing = general.has_value () && general.value ().optional ("supportsAudioProcessing", false), .supportsAudioProcessing = general.has_value () && general.value ().optional ("supportsAudioProcessing", false),
.properties = parseProperties (general), .properties = parseProperties (general),
.container = container, .container = std::move(container),
}); });
result->wallpaper = WallpaperParser::parse (data.require ("file", "Project's main file missing"), result); result->wallpaper = WallpaperParser::parse (data.require ("file", "Project's main file missing"), *result);
return result; return result;
} }

View File

@ -15,7 +15,7 @@ using namespace WallpaperEngine::Data::Model;
*/ */
class ProjectParser { class ProjectParser {
public: public:
static ProjectSharedPtr parse (const JSON& data, const ContainerWeakPtr& container); static ProjectUniquePtr parse (const JSON& data, ContainerUniquePtr container);
private: private:
static Project::Type parseType (const std::string& type); static Project::Type parseType (const std::string& type);

View File

@ -5,7 +5,7 @@
using namespace WallpaperEngine::Data::Parsers; using namespace WallpaperEngine::Data::Parsers;
using namespace WallpaperEngine::Data::Model; using namespace WallpaperEngine::Data::Model;
ShaderConstantMap ShaderConstantParser::parse (const JSON& it, const ProjectWeakPtr& project) { ShaderConstantMap ShaderConstantParser::parse (const JSON& it, Project& project) {
if (!it.is_object ()) { if (!it.is_object ()) {
return {}; return {};
} }
@ -19,7 +19,7 @@ ShaderConstantMap ShaderConstantParser::parse (const JSON& it, const ProjectWeak
return result; return result;
} }
ShaderConstantUniquePtr ShaderConstantParser::parseConstant (const JSON& it, const ProjectWeakPtr& project) { ShaderConstantUniquePtr ShaderConstantParser::parseConstant (const JSON& it, Project& project) {
ShaderConstant* constant = nullptr; ShaderConstant* constant = nullptr;
auto valueIt = it; auto valueIt = it;
@ -33,7 +33,7 @@ ShaderConstantUniquePtr ShaderConstantParser::parseConstant (const JSON& it, con
} }
if (user != it.end () && user->is_string ()) { if (user != it.end () && user->is_string ()) {
const auto& properties = project.lock ()->properties; const auto& properties = project.properties;
const auto& propertyIt = properties.find (*user); const auto& propertyIt = properties.find (*user);
if (propertyIt != properties.end ()) { if (propertyIt != properties.end ()) {

View File

@ -9,7 +9,7 @@ using namespace WallpaperEngine::Data::Model;
class ShaderConstantParser { class ShaderConstantParser {
public: public:
static ShaderConstantMap parse (const JSON& it, const ProjectWeakPtr& project); static ShaderConstantMap parse (const JSON& it, Project& project);
static ShaderConstantUniquePtr parseConstant (const JSON& it, const ProjectWeakPtr& project); static ShaderConstantUniquePtr parseConstant (const JSON& it, Project& project);
}; };
} // namespace WallpaperEngine::Data::Parsers } // namespace WallpaperEngine::Data::Parsers

View File

@ -7,31 +7,31 @@
using namespace WallpaperEngine::Data::Parsers; using namespace WallpaperEngine::Data::Parsers;
WallpaperSharedPtr WallpaperParser::parse (const JSON& file, const ProjectWeakPtr& project) { WallpaperUniquePtr WallpaperParser::parse (const JSON& file, Project& project) {
switch (project.lock ()->type) { switch (project.type) {
case Project::Type_Scene: case Project::Type_Scene:
return std::dynamic_pointer_cast <Wallpaper> (parseScene (file, project)); return parseScene (file, project);
case Project::Type_Video: case Project::Type_Video:
return std::dynamic_pointer_cast <Wallpaper> (parseVideo (file, project)); return parseVideo (file, project);
case Project::Type_Web: case Project::Type_Web:
return std::dynamic_pointer_cast <Wallpaper> (parseWeb (file, project)); return parseWeb (file, project);
default: default:
sLog.exception ("Unexpected project type value found... This is likely a bug"); sLog.exception ("Unexpected project type value found... This is likely a bug");
} }
} }
SceneSharedPtr WallpaperParser::parseScene (const JSON& file, const ProjectWeakPtr& project) { SceneUniquePtr WallpaperParser::parseScene (const JSON& file, Project& project) {
const auto scene = JSON::parse (project.lock ()->container.lock ()->readFileAsString (file)); const auto scene = JSON::parse (project.container->readFileAsString (file));
const auto camera = scene.require ("camera", "Scenes must have a camera section"); const auto camera = scene.require ("camera", "Scenes must have a camera section");
const auto general = scene.require ("general", "Scenes must have a general section"); const auto general = scene.require ("general", "Scenes must have a general section");
const auto projection = general.require ("orthogonalprojection", "General section must have orthogonal projection info"); const auto projection = general.require ("orthogonalprojection", "General section must have orthogonal projection info");
const auto objects = scene.require ("objects", "Scenes must have an objects section"); const auto objects = scene.require ("objects", "Scenes must have an objects section");
const auto& properties = project.lock ()->properties; const auto& properties = project.properties;
// TODO: FIND IF THESE DEFAULTS ARE SENSIBLE OR NOT AND PERFORM PROPER VALIDATION WHEN CAMERA PREVIEW AND CAMERA // TODO: FIND IF THESE DEFAULTS ARE SENSIBLE OR NOT AND PERFORM PROPER VALIDATION WHEN CAMERA PREVIEW AND CAMERA
// PARALLAX ARE PRESENT // PARALLAX ARE PRESENT
return std::make_shared <Scene> ( return std::make_unique <Scene> (
WallpaperData { WallpaperData {
.filename = "", .filename = "",
.project = project .project = project
@ -72,34 +72,34 @@ SceneSharedPtr WallpaperParser::parseScene (const JSON& file, const ProjectWeakP
.isAuto = projection.optional ("auto", false) .isAuto = projection.optional ("auto", false)
} }
}, },
.objects = parseObjects (objects, project) .objects = parseObjects (objects, project),
} }
); );
} }
VideoSharedPtr WallpaperParser::parseVideo (const JSON& file, const ProjectWeakPtr& project) { VideoUniquePtr WallpaperParser::parseVideo (const JSON& file, Project& project) {
return std::make_unique <Video> (WallpaperData { return std::make_unique <Video> (WallpaperData {
.filename = file, .filename = file,
.project = project .project = project
}); });
} }
WebSharedPtr WallpaperParser::parseWeb (const JSON& file, const ProjectWeakPtr& project) { WebUniquePtr WallpaperParser::parseWeb (const JSON& file, Project& project) {
return std::make_unique <Web> (WallpaperData { return std::make_unique <Web> (WallpaperData {
.filename = file, .filename = file,
.project = project, .project = project,
}); });
} }
ObjectMap WallpaperParser::parseObjects (const JSON& objects, const ProjectWeakPtr& project) { ObjectList WallpaperParser::parseObjects (const JSON& objects, Project& project) {
ObjectMap result = {}; ObjectList result = {};
for (const auto& cur : objects) { for (const auto& cur : objects) {
auto object = ObjectParser::parse (cur, project); auto object = ObjectParser::parse (cur, project);
//TODO: DO WE REALLY WANT TO DIRECTLY CONSTRUCT UNIQUE AND SHARED PTRS EVERYWHERE? //TODO: DO WE REALLY WANT TO DIRECTLY CONSTRUCT UNIQUE AND SHARED PTRS EVERYWHERE?
// SHOULDN'T THAT BE HANDLED BY CALLING CODE (LIKE THIS) INSTEAD? // SHOULDN'T THAT BE HANDLED BY CALLING CODE (LIKE THIS) INSTEAD?
result.emplace (object->id, std::move (object)); result.emplace_back (std::move (object));
} }
return result; return result;

View File

@ -9,12 +9,12 @@ using namespace WallpaperEngine::Data::Model;
class WallpaperParser { class WallpaperParser {
public: public:
static WallpaperSharedPtr parse (const JSON& file, const ProjectWeakPtr& project); static WallpaperUniquePtr parse (const JSON& file, Project& project);
private: private:
static SceneSharedPtr parseScene (const JSON& file, const ProjectWeakPtr& project); static SceneUniquePtr parseScene (const JSON& file, Project& project);
static VideoSharedPtr parseVideo (const JSON& file, const ProjectWeakPtr& project); static VideoUniquePtr parseVideo (const JSON& file, Project& project);
static WebSharedPtr parseWeb (const JSON& file, const ProjectWeakPtr& project); static WebUniquePtr parseWeb (const JSON& file, Project& project);
static ObjectMap parseObjects (const JSON& objects, const ProjectWeakPtr& project); static ObjectList parseObjects (const JSON& objects, Project& project);
}; };
} // namespace WallpaperEngine::Data::Parsers } // namespace WallpaperEngine::Data::Parsers

View File

@ -1,403 +0,0 @@
#include "CPrettyPrinter.h"
#include "WallpaperEngine/Render/Wallpapers/CVideo.h"
#include "WallpaperEngine/Render/Wallpapers/CWeb.h"
#include "WallpaperEngine/Render/Objects/CEffect.h"
using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::PrettyPrinter;
using namespace WallpaperEngine::Render::Objects;
CPrettyPrinter::CPrettyPrinter () :
m_out (&this->m_buffer) {}
void CPrettyPrinter::printWallpaper (const CWallpaper& wallpaper) {
bool isScene = wallpaper.is <Wallpapers::CScene> ();
bool isVideo = wallpaper.is <Wallpapers::CVideo> ();
bool isWeb = wallpaper.is <Wallpapers::CWeb> ();
if (isScene) {
const auto scene = wallpaper.as <Wallpapers::CScene> ();
this->m_out << "Scene wallpaper: ";
this->increaseIndentation ();
const auto fbos = scene->getFBOs ();
this->m_out << "FBOs count: " << fbos.size ();
if (!fbos.empty()) {
this->increaseIndentation ();
for (const auto& fbo : fbos) {
this->printFBO (*fbo.second);
}
this->decreaseIndentation ();
} else {
this->lineEnd ();
}
const auto objects = scene->getObjectsByRenderOrder ();
if (!objects.empty()) {
this->m_out << "Objects count: " << objects.size ();
this->increaseIndentation ();
for (const auto object : objects) {
if (object->is <CImage> ()) {
this->printImage (*object->as <CImage> ());
}
}
this->decreaseIndentation ();
}
this->decreaseIndentation ();
} else if (isVideo) {
const auto video = wallpaper.as <Wallpapers::CVideo> ();
this->m_out << "Video wallpaper: " << video->getVideo ()->getFilename ();
this->lineEnd ();
} else if (isWeb) {
const auto web = wallpaper.as <Wallpapers::CWeb> ();
this->m_out << "Web wallpaper";
this->lineEnd ();
}
}
void CPrettyPrinter::printImage (const CImage& image) {
auto base = image.getImage ();
this->m_out << "Image " << image.getId () << " " << base->getName () << ":";
this->increaseIndentation ();
const auto material = image.getMaterial ();
if (material != nullptr) {
this->printMaterial (*image.getMaterial ());
}
int effects = 0;
for (const auto effect : image.getEffects ()) {
this->printEffect (*effect, ++effects);
}
this->decreaseIndentation ();
}
void CPrettyPrinter::printEffect (const CEffect& effect, int effectId) {
if (effectId != 0) {
this->m_out << "Effect " << effectId << ":";
} else {
this->m_out << "Effect:";
}
this->increaseIndentation ();
this->m_out << "Visibility status: " << effect.isVisible ();
this->lineEnd ();
const auto& fbos = effect.getFBOs();
this->m_out << "FBOs count: " << fbos.size();
if (!fbos.empty()) {
this->increaseIndentation ();
for (const auto& [name, fbo] : fbos) {
this->printFBO (*fbo);
}
this->decreaseIndentation ();
} else {
this->lineEnd ();
}
const auto& materials = effect.getMaterials ();
for (const auto material : materials) {
this->printMaterial (*material);
}
this->decreaseIndentation ();
}
void CPrettyPrinter::printFBO (const CFBO& fbo) {
this->m_out << "FBO " << fbo.getName () << ":";
this->increaseIndentation ();
this->m_out << "Scale: " << fbo.getScale ();
this->lineEnd ();
this->printTextureInfo (fbo);
this->decreaseIndentation ();
}
void CPrettyPrinter::printMaterial (const CMaterial& material) {
const auto base = material.getMaterial ();
this->m_out << "Material " << base->getName () << ":";
this->increaseIndentation ();
if (base->hasTarget ()) {
this->m_out << "Target: " << base->getTarget ();
this->lineEnd ();
}
const auto& passes = material.getPasses ();
this->m_out << "Passes count: " << passes.size ();
if (!passes.empty()) {
this->increaseIndentation ();
int passId = 0;
for (const auto pass : passes) {
this->printPass (*pass, ++passId);
}
this->decreaseIndentation ();
} else {
this->lineEnd ();
}
const auto textureBinds = base->getTextureBinds ();
if (!textureBinds.empty()) {
this->m_out << "Texture binds count: " << textureBinds.size ();
this->increaseIndentation ();
for (const auto bind : textureBinds) {
this->m_out << "Bind " << bind.first << " = " << bind.second->getIndex () << "," << bind.second->getName ();
this->lineEnd ();
}
this->decreaseIndentation ();
}
this->decreaseIndentation ();
}
void CPrettyPrinter::printPass (const CPass& pass, int passId) {
const auto base = pass.getPass ();
this->m_out << "Pass " << passId << ":";
this->increaseIndentation ();
if (pass.getBlendingMode () != base->getBlendingMode ()) {
this->m_out << "Render blending mode: " << pass.getBlendingMode ();
this->lineEnd ();
this->m_out << "Blending mode: " << base->getBlendingMode ();
this->lineEnd ();
} else {
this->m_out << "Blending mode: " << base->getBlendingMode ();
this->lineEnd ();
}
this->m_out << "Culling mode: " << base->getCullingMode();
this->lineEnd ();
this->m_out << "Depth test: " << base->getDepthTest();
this->lineEnd ();
this->m_out << "Depth write: " << base->getDepthWrite();
this->lineEnd ();
this->m_out << "Shader: " << base->getShader();
this->lineEnd ();
const auto textures = base->getTextures ();
if (!textures.empty()) {
this->m_out << "Textures " << textures.size () << ":";
this->increaseIndentation ();
for (const auto& texture : textures) {
this->m_out << texture.first << ": " << texture.second;
this->lineEnd ();
}
this->decreaseIndentation ();
}
const auto& fragmentTextures = pass.getShader ()->getFragment ().getTextures ();
if (!fragmentTextures.empty()) {
this->m_out << "Fragment textures " << fragmentTextures.size () << ":";
this->increaseIndentation ();
for (const auto& texture : fragmentTextures) {
this->m_out << texture.first << ": " << texture.second;
this->lineEnd ();
}
this->decreaseIndentation ();
}
const auto& vertexTextures = pass.getShader ()->getFragment ().getTextures ();
if (!vertexTextures.empty()) {
this->m_out << "Vertex textures " << textures.size () << ":";
this->increaseIndentation ();
for (const auto& texture : vertexTextures) {
this->m_out << texture.first << ": " << texture.second;
this->lineEnd ();
}
this->decreaseIndentation ();
}
const auto& combos = base->getCombos();
if (!combos.empty()) {
this->m_out << "Combos " << combos.size () << ":";
this->increaseIndentation ();
for (const auto& combo : combos) {
this->m_out << combo.first << " = " << combo.second;
this->lineEnd ();
}
this->decreaseIndentation ();
}
const auto& vertexCombos = pass.getShader ()->getVertex ().getDiscoveredCombos ();
if (!vertexCombos.empty()) {
this->m_out << "Vertex combos " << vertexCombos.size () << ":";
this->increaseIndentation ();
for (const auto& combo : vertexCombos) {
this->m_out << combo.first << " = " << combo.second;
this->lineEnd ();
}
this->decreaseIndentation ();
}
const auto& fragmentCombos = pass.getShader ()->getFragment ().getDiscoveredCombos ();
if (!fragmentCombos.empty()) {
this->m_out << "Vertex combos " << fragmentCombos.size () << ":";
this->increaseIndentation ();
for (const auto& combo : fragmentCombos) {
this->m_out << combo.first << " = " << combo.second;
this->lineEnd ();
}
this->decreaseIndentation ();
}
const auto& constants = base->getConstants ();
if (!constants.empty()) {
this->m_out << "Constants " << constants.size () << ":";
this->increaseIndentation ();
for (const auto& constant : constants) {
this->m_out << constant.first << " = " << constant.second->toString ();
this->lineEnd ();
}
this->decreaseIndentation ();
}
this->decreaseIndentation ();
}
void CPrettyPrinter::printTextureInfo (const ITexture& texture) {
this->m_out << "Texture Dimensions: " << texture.getTextureWidth(0) << "x" << texture.getTextureHeight (0);
this->lineEnd ();
this->m_out << "Part Dimensions: " << texture.getRealWidth () << "x" << texture.getRealHeight ();
this->lineEnd ();
this->m_out << "Texture format: ";
this->printTextureFormat (texture.getFormat ());
this->lineEnd ();
this->m_out << "Texture flags: ";
this->printTextureFlags (texture.getFlags ());
this->lineEnd ();
this->m_out << "Is animated: " << texture.isAnimated ();
this->lineEnd ();
const auto& frames = texture.getFrames ();
if (frames.size () > 1) {
this->m_out << frames.size () << " frames: ";
this->increaseIndentation ();
for (const auto frame : frames) {
this->m_out << "Frame " << frame->frameNumber << ":";
this->increaseIndentation ();
this->m_out << "Frametime " << frame->frametime;
this->lineEnd ();
this->m_out << "Position in atlas: " << frame->x << "x" << frame->y;
this->lineEnd ();
this->m_out << "Size1: " << frame->width1 << "x" << frame->height1;
this->lineEnd ();
this->m_out << "Size2: " << frame->width2 << "x" << frame->height2;
this->decreaseIndentation ();
}
this->decreaseIndentation ();
}
}
void CPrettyPrinter::printTextureFormat (ITexture::TextureFormat format) {
switch (format) {
case ITexture::UNKNOWN: this->m_out << "UNKNOWN"; break;
case ITexture::ARGB8888: this->m_out << "ARGB8888"; break;
case ITexture::RGB888: this->m_out << "RGB888"; break;
case ITexture::RGB565: this->m_out << "RGB565"; break;
case ITexture::DXT5: this->m_out << "DXT5"; break;
case ITexture::DXT3: this->m_out << "DXT3"; break;
case ITexture::DXT1: this->m_out << "DXT1"; break;
case ITexture::RG88: this->m_out << "RG88"; break;
case ITexture::R8: this->m_out << "R8"; break;
case ITexture::RG1616f: this->m_out << "RG1616f"; break;
case ITexture::R16f: this->m_out << "R16f"; break;
case ITexture::BC7: this->m_out << "BC7"; break;
case ITexture::RGBa1010102: this->m_out << "RGBa1010102"; break;
case ITexture::RGBA16161616f: this->m_out << "RGBA16161616f"; break;
case ITexture::RGB161616f: this->m_out << "RGB161616f"; break;
}
}
void CPrettyPrinter::printTextureFlags (ITexture::TextureFlags flags) {
if (flags & ITexture::NoInterpolation) {
this->m_out << "No interpolation";
}
if (flags & ITexture::ClampUVs) {
this->m_out << "Clamp UVs ";
}
if (flags & ITexture::IsGif) {
this->m_out << "Is gif ";
}
if (flags & ITexture::ClampUVsBorder) {
this->m_out << "ClampUVs border ";
}
if (flags == ITexture::NoFlags) {
this->m_out << "No flags";
}
}
void CPrettyPrinter::indentation () {
this->m_out << std::string(this->m_level, '\t');
}
void CPrettyPrinter::lineEnd () {
this->m_out << '\n';
this->indentation ();
}
void CPrettyPrinter::increaseIndentation () {
this->m_level ++;
this->lineEnd ();
}
void CPrettyPrinter::decreaseIndentation () {
this->m_level --;
this->lineEnd ();
}
std::string CPrettyPrinter::str () {
return this->m_buffer.str ();
}

View File

@ -1,108 +0,0 @@
#pragma once
#include <sstream>
#include "WallpaperEngine/Render/Objects/CImage.h"
using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Render::Objects;
using namespace WallpaperEngine::Render::Objects::Effects;
namespace WallpaperEngine::PrettyPrinter {
/**
* Provides insights on the actual data that is being used to render the wallpaper
* to the screens
*/
class CPrettyPrinter {
public:
CPrettyPrinter ();
~CPrettyPrinter () = default;
/**
* Prints the information of the given wallpaper
*
* @param wallpaper
*/
void printWallpaper (const CWallpaper& wallpaper);
/**
* Prints the information of the given image
* @param image
*/
void printImage (const CImage& image);
/**
* Prints the information of the given effect
*
* @param effect
* @param effectId The effect ID to show on the output if required
*/
void printEffect (const CEffect& effect, int effectId = 0);
/**
* Prints the information of the given FBO
*
* @param fbo
*/
void printFBO (const CFBO& fbo);
/**
* Prints the information of the given material
*
* @param material
*/
void printMaterial (const CMaterial& material);
/**
* Prints the information of the given material's pass
*
* @param pass
*/
void printPass (const CPass& pass, int passId = 0);
/**
* @return The contents of the pretty printer buffer
*/
std::string str ();
private:
/**
* Prints the current indentation level in tabs
*/
void indentation ();
/**
* Prints an end of line and indentates the next line to the aproppiate level
*/
void lineEnd ();
/**
* Increases the indentation level and prints a new line up to the specified level
*/
void increaseIndentation ();
/**
* Decreases the indentation level and prints a new line up to the specified level
*/
void decreaseIndentation ();
/**
* Prints a texture's format as string in-place
*
* @param format
*/
void printTextureFormat (ITexture::TextureFormat format);
/**
* Prints a texture's flags as string in-place
*
* @param flags
*/
void printTextureFlags (ITexture::TextureFlags flags);
/**
* Prints information about a given ITexture in-place
*
* @param texture
*/
void printTextureInfo (const ITexture& texture);
int m_level = 0;
std::stringbuf m_buffer = {};
std::ostream m_out;
};
}

View File

@ -6,9 +6,11 @@
using namespace WallpaperEngine; using namespace WallpaperEngine;
using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render;
CCamera::CCamera (Wallpapers::CScene* scene, const Core::Scenes::CCamera* camera) : CCamera::CCamera (Wallpapers::CScene& scene, const SceneData::Camera& camera) :
m_camera (camera), m_camera (camera),
m_scene (scene) { m_scene (scene),
m_width (0),
m_height (0) {
// get the lookat position // get the lookat position
// TODO: ENSURE THIS IS ONLY USED WHEN NOT DOING AN ORTOGRAPHIC CAMERA AS IT THROWS OFF POINTS // TODO: ENSURE THIS IS ONLY USED WHEN NOT DOING AN ORTOGRAPHIC CAMERA AS IT THROWS OFF POINTS
this->m_lookat = glm::lookAt (this->getEye (), this->getCenter (), this->getUp ()); this->m_lookat = glm::lookAt (this->getEye (), this->getCenter (), this->getUp ());
@ -17,15 +19,15 @@ CCamera::CCamera (Wallpapers::CScene* scene, const Core::Scenes::CCamera* camera
CCamera::~CCamera () = default; CCamera::~CCamera () = default;
const glm::vec3& CCamera::getCenter () const { const glm::vec3& CCamera::getCenter () const {
return this->m_camera->getCenter (); return this->m_camera.configuration.center;
} }
const glm::vec3& CCamera::getEye () const { const glm::vec3& CCamera::getEye () const {
return this->m_camera->getEye (); return this->m_camera.configuration.eye;
} }
const glm::vec3& CCamera::getUp () const { const glm::vec3& CCamera::getUp () const {
return this->m_camera->getUp (); return this->m_camera.configuration.up;
} }
const glm::mat4& CCamera::getProjection () const { const glm::mat4& CCamera::getProjection () const {
@ -40,11 +42,22 @@ bool CCamera::isOrthogonal () const {
return this->m_isOrthogonal; return this->m_isOrthogonal;
} }
Wallpapers::CScene* CCamera::getScene () const { Wallpapers::CScene& CCamera::getScene () const {
return this->m_scene; return this->m_scene;
} }
float CCamera::getWidth () const {
return this->m_width;
}
float CCamera::getHeight () const {
return this->m_height;
}
void CCamera::setOrthogonalProjection (float width, float height) { void CCamera::setOrthogonalProjection (float width, float height) {
this->m_width = width;
this->m_height = height;
// TODO: GET THE ZNEAR AND ZFAR FROM THE BACKGROUND (IF AVAILABLE) // TODO: GET THE ZNEAR AND ZFAR FROM THE BACKGROUND (IF AVAILABLE)
// get the orthogonal projection (the float is there to ensure the values are casted to float, so maths do work) // get the orthogonal projection (the float is there to ensure the values are casted to float, so maths do work)
this->m_projection = glm::ortho<float> (-width / 2.0, width / 2.0, -height / 2.0, height / 2.0, 0, 1000); this->m_projection = glm::ortho<float> (-width / 2.0, width / 2.0, -height / 2.0, height / 2.0, 0, 1000);

View File

@ -5,16 +5,18 @@
#include <glm/vec2.hpp> #include <glm/vec2.hpp>
#include <glm/vec3.hpp> #include <glm/vec3.hpp>
#include "WallpaperEngine/Core/Scenes/CCamera.h" #include "WallpaperEngine/Data/Model/Wallpaper.h"
namespace WallpaperEngine::Render::Wallpapers { namespace WallpaperEngine::Render::Wallpapers {
class CScene; class CScene;
} }
namespace WallpaperEngine::Render { namespace WallpaperEngine::Render {
using namespace WallpaperEngine::Data::Model;
class CCamera { class CCamera {
public: public:
CCamera (Wallpapers::CScene* scene, const Core::Scenes::CCamera* camera); CCamera (Wallpapers::CScene& scene, const SceneData::Camera& camera);
~CCamera (); ~CCamera ();
void setOrthogonalProjection (float width, float height); void setOrthogonalProjection (float width, float height);
@ -24,14 +26,18 @@ class CCamera {
[[nodiscard]] const glm::vec3& getUp () const; [[nodiscard]] const glm::vec3& getUp () const;
[[nodiscard]] const glm::mat4& getProjection () const; [[nodiscard]] const glm::mat4& getProjection () const;
[[nodiscard]] const glm::mat4& getLookAt () const; [[nodiscard]] const glm::mat4& getLookAt () const;
[[nodiscard]] Wallpapers::CScene* getScene () const; [[nodiscard]] Wallpapers::CScene& getScene () const;
[[nodiscard]] bool isOrthogonal () const; [[nodiscard]] bool isOrthogonal () const;
[[nodiscard]] float getWidth () const;
[[nodiscard]] float getHeight () const;
private: private:
float m_width;
float m_height;
bool m_isOrthogonal = false; bool m_isOrthogonal = false;
glm::mat4 m_projection = {}; glm::mat4 m_projection = {};
glm::mat4 m_lookat = {}; glm::mat4 m_lookat = {};
const Core::Scenes::CCamera* m_camera; const SceneData::Camera& m_camera;
Wallpapers::CScene* m_scene = nullptr; Wallpapers::CScene& m_scene;
}; };
} // namespace WallpaperEngine::Render } // namespace WallpaperEngine::Render

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <string>
#include "WallpaperEngine/Assets/ITexture.h" #include "WallpaperEngine/Assets/ITexture.h"
#include "WallpaperEngine/Core/Objects/CImage.h"
#include "WallpaperEngine/Core/Objects/Effects/CFBO.h"
using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Assets;

View File

@ -0,0 +1,57 @@
#include "CFBOProvider.h"
#include <gmpxx.h>
using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Data::Model;
CFBOProvider::CFBOProvider (const CFBOProvider* parent) :
m_parent (parent) {}
std::shared_ptr<CFBO> CFBOProvider::create(const FBO& base, ITexture::TextureFlags flags, glm::vec2 size) {
return this->m_fbos[base.name] = std::make_shared <CFBO> (
base.name,
// TODO: PROPERLY DETERMINE FBO FORMAT BASED ON THE STRING
ITexture::TextureFormat::ARGB8888,
flags,
base.scale,
size.x / base.scale,
size.y / base.scale,
size.x / base.scale,
size.y / base.scale
);
}
std::shared_ptr<CFBO> CFBOProvider::create (
const std::string& name, ITexture::TextureFormat format, ITexture::TextureFlags flags, float scale,
glm::vec2 realSize, glm::vec2 textureSize
) {
return this->m_fbos[name] = std::make_shared <CFBO> (
name,
ITexture::TextureFormat::ARGB8888,
flags,
scale,
realSize.x,
realSize.y,
textureSize.x,
textureSize.y
);
}
std::shared_ptr<CFBO> CFBOProvider::alias (const std::string& newName, const std::string& original) {
return this->m_fbos[newName] = this->m_fbos[original];
}
std::shared_ptr<CFBO> CFBOProvider::find (const std::string& name) const {
const auto it = this->m_fbos.find (name);
if (it != this->m_fbos.end ())
return it->second;
if (this->m_parent == nullptr) {
return nullptr;
}
return this->m_parent->find (name);
}

View File

@ -0,0 +1,24 @@
#pragma once
#include "CFBO.h"
#include "WallpaperEngine/Data/Model/Effect.h"
namespace WallpaperEngine::Render {
using namespace WallpaperEngine::Data::Model;
class CFBOProvider {
public:
CFBOProvider (const CFBOProvider* parent);
std::shared_ptr<CFBO> create (const FBO& base, ITexture::TextureFlags flags, glm::vec2 size);
std::shared_ptr<CFBO> create (
const std::string& name, ITexture::TextureFormat format, ITexture::TextureFlags flags, float scale,
glm::vec2 realSize, glm::vec2 textureSize);
std::shared_ptr<CFBO> alias (const std::string& newName, const std::string& original);
[[nodiscard]] std::shared_ptr<CFBO> find (const std::string& name) const;
private:
const CFBOProvider* m_parent;
std::map <std::string, std::shared_ptr<CFBO>> m_fbos = {};
};
}

View File

@ -6,19 +6,19 @@ using namespace WallpaperEngine;
using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Render::Wallpapers; using namespace WallpaperEngine::Render::Wallpapers;
CObject::CObject (Wallpapers::CScene* scene, const Core::CObject* object) : CObject::CObject (Wallpapers::CScene& scene, const Object& object) :
Helpers::CContextAware (scene), Helpers::CContextAware (scene),
m_scene (scene), m_scene (scene),
m_object (object) {} m_object (object) {}
Wallpapers::CScene* CObject::getScene () const { Wallpapers::CScene& CObject::getScene () const {
return this->m_scene; return this->m_scene;
} }
std::shared_ptr<const CContainer> CObject::getContainer () const { const CContainer& CObject::getContainer () const {
return this->getScene ()->getContainer (); return this->getScene ().getContainer ();
} }
int CObject::getId () const { int CObject::getId () const {
return this->m_object->getId (); return this->m_object.id;
} }

View File

@ -2,7 +2,6 @@
#include <string> #include <string>
#include "WallpaperEngine/Core/CObject.h"
#include "WallpaperEngine/Render/Helpers/CContextAware.h" #include "WallpaperEngine/Render/Helpers/CContextAware.h"
#include "WallpaperEngine/Render/Wallpapers/CScene.h" #include "WallpaperEngine/Render/Wallpapers/CScene.h"
@ -36,16 +35,16 @@ class CObject : public Helpers::CContextAware {
virtual void render () = 0; virtual void render () = 0;
[[nodiscard]] Wallpapers::CScene* getScene () const; [[nodiscard]] Wallpapers::CScene& getScene () const;
[[nodiscard]] std::shared_ptr<const CContainer> getContainer () const; [[nodiscard]] const CContainer& getContainer () const;
[[nodiscard]] int getId () const; [[nodiscard]] int getId () const;
protected: protected:
CObject (Wallpapers::CScene* scene, const Core::CObject* object); CObject (Wallpapers::CScene& scene, const Object& object);
virtual ~CObject () override = default; virtual ~CObject () override = default;
private: private:
Wallpapers::CScene* m_scene = nullptr; Wallpapers::CScene& m_scene;
const Core::CObject* m_object; const Object& m_object;
}; };
} // namespace WallpaperEngine::Render } // namespace WallpaperEngine::Render

View File

@ -5,6 +5,8 @@
#include "CRenderContext.h" #include "CRenderContext.h"
#include "CWallpaper.h" #include "CWallpaper.h"
#include "WallpaperEngine/Data/Model/Project.h"
namespace WallpaperEngine::Render { namespace WallpaperEngine::Render {
CRenderContext::CRenderContext (Drivers::CVideoDriver& driver, CWallpaperApplication& app) : CRenderContext::CRenderContext (Drivers::CVideoDriver& driver, CWallpaperApplication& app) :
m_driver (driver), m_driver (driver),

View File

@ -3,6 +3,8 @@
#include "WallpaperEngine/Assets/CAssetLoadException.h" #include "WallpaperEngine/Assets/CAssetLoadException.h"
#include "WallpaperEngine/Render/Helpers/CContextAware.h" #include "WallpaperEngine/Render/Helpers/CContextAware.h"
#include "WallpaperEngine/Data/Model/Project.h"
using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Assets;
@ -15,9 +17,9 @@ std::shared_ptr<const ITexture> CTextureCache::resolve (const std::string& filen
return found->second; return found->second;
// search for the texture in all the different containers just in case // search for the texture in all the different containers just in case
for (const auto& it : this->getContext ().getApp ().getBackgrounds ()) { for (const auto& [name, project] : this->getContext ().getApp ().getBackgrounds ()) {
try { try {
std::shared_ptr<const ITexture> texture = it.second->getContainer ()->readTexture (filename); std::shared_ptr<const ITexture> texture = project->container->readTexture (filename);
this->store (filename, texture); this->store (filename, texture);

View File

@ -4,17 +4,21 @@
#include "WallpaperEngine/Render/Wallpapers/CVideo.h" #include "WallpaperEngine/Render/Wallpapers/CVideo.h"
#include "WallpaperEngine/Render/Wallpapers/CWeb.h" #include "WallpaperEngine/Render/Wallpapers/CWeb.h"
#include "WallpaperEngine/Data/Model/Wallpaper.h"
#include "WallpaperEngine/Data/Model/Project.h"
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render;
CWallpaper::CWallpaper ( CWallpaper::CWallpaper (
std::shared_ptr <const Core::CWallpaper> wallpaperData, CRenderContext& context,CAudioContext& audioContext, const Wallpaper& wallpaperData, CRenderContext& context,CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode
) : ) :
CContextAware (context), CContextAware (context),
CFBOProvider (nullptr),
m_wallpaperData (wallpaperData), m_wallpaperData (wallpaperData),
m_audioContext (audioContext), m_audioContext (audioContext),
m_state (scalingMode, clampMode) { m_state (scalingMode, clampMode) {
@ -41,11 +45,11 @@ CWallpaper::CWallpaper (
CWallpaper::~CWallpaper () = default; CWallpaper::~CWallpaper () = default;
std::shared_ptr<const CContainer> CWallpaper::getContainer () const { const CContainer& CWallpaper::getContainer () const {
return this->m_wallpaperData->getProject ()->getContainer (); return *this->m_wallpaperData.project.container;
} }
std::shared_ptr <const WallpaperEngine::Core::CWallpaper> CWallpaper::getWallpaperData () const { const Wallpaper& CWallpaper::getWallpaperData () const {
return this->m_wallpaperData; return this->m_wallpaperData;
} }
@ -186,7 +190,14 @@ void CWallpaper::updateUVs (const glm::ivec4& viewport, const bool vflip) {
} }
void CWallpaper::render (glm::ivec4 viewport, bool vflip) { void CWallpaper::render (glm::ivec4 viewport, bool vflip) {
#if !NDEBUG
glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Rendering scene");
#endif /* !NDEBUG */
this->renderFrame (viewport); this->renderFrame (viewport);
#if !NDEBUG
glPopDebugGroup ();
glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Rendering scene to output");
#endif /* !NDEBUG */
// Update UVs coordinates according to scaling mode of this wallpaper // Update UVs coordinates according to scaling mode of this wallpaper
updateUVs (viewport, vflip); updateUVs (viewport, vflip);
auto [ustart, uend, vstart, vend] = this->m_state.getTextureUVs (); auto [ustart, uend, vstart, vend] = this->m_state.getTextureUVs ();
@ -203,6 +214,7 @@ void CWallpaper::render (glm::ivec4 viewport, bool vflip) {
glDisable (GL_BLEND); glDisable (GL_BLEND);
glDisable (GL_DEPTH_TEST); glDisable (GL_DEPTH_TEST);
glDisable (GL_CULL_FACE);
// do not use any shader // do not use any shader
glUseProgram (this->m_shader); glUseProgram (this->m_shader);
// activate scene texture // activate scene texture
@ -222,6 +234,10 @@ void CWallpaper::render (glm::ivec4 viewport, bool vflip) {
// write the framebuffer as is to the screen // write the framebuffer as is to the screen
glBindBuffer (GL_ARRAY_BUFFER, this->m_texCoordBuffer); glBindBuffer (GL_ARRAY_BUFFER, this->m_texCoordBuffer);
glDrawArrays (GL_TRIANGLES, 0, 6); glDrawArrays (GL_TRIANGLES, 0, 6);
#if !NDEBUG
glPopDebugGroup ();
#endif /* !NDEBUG */
} }
void CWallpaper::setPause (bool newState) {} void CWallpaper::setPause (bool newState) {}
@ -232,62 +248,43 @@ void CWallpaper::setupFramebuffers () {
const ITexture::TextureFlags clamp = this->m_state.getClampingMode (); const ITexture::TextureFlags clamp = this->m_state.getClampingMode ();
// create framebuffer for the scene // create framebuffer for the scene
this->m_sceneFBO = this->createFBO ( this->m_sceneFBO = this->create (
"_rt_FullFrameBuffer", ITexture::TextureFormat::ARGB8888, clamp, 1.0, width, "_rt_FullFrameBuffer", ITexture::TextureFormat::ARGB8888, clamp, 1.0, {width,
height, width, height); height}, {width, height});
this->aliasFBO ("_rt_MipMappedFrameBuffer", this->m_sceneFBO); this->alias ("_rt_MipMappedFrameBuffer", "_rt_FullFrameBuffer");
} }
CAudioContext& CWallpaper::getAudioContext () { CAudioContext& CWallpaper::getAudioContext () {
return this->m_audioContext; return this->m_audioContext;
} }
std::shared_ptr<const CFBO> CWallpaper::createFBO (
const std::string& name, ITexture::TextureFormat format, ITexture::TextureFlags flags, float scale,
uint32_t realWidth, uint32_t realHeight, uint32_t textureWidth, uint32_t textureHeight
) {
std::shared_ptr<const CFBO> fbo = std::make_shared <CFBO> (name, format, flags, scale, realWidth, realHeight, textureWidth, textureHeight);
this->m_fbos.emplace (name, fbo);
return fbo;
}
void CWallpaper::aliasFBO (const std::string& alias, const std::shared_ptr<const CFBO>& original) {
this->m_fbos.emplace (alias, original);
}
const std::map<std::string, std::shared_ptr<const CFBO>>& CWallpaper::getFBOs () const {
return this->m_fbos;
}
std::shared_ptr<const CFBO> CWallpaper::findFBO (const std::string& name) const { std::shared_ptr<const CFBO> CWallpaper::findFBO (const std::string& name) const {
const auto it = this->m_fbos.find (name); const auto fbo = this->find (name);
if (it == this->m_fbos.end ()) if (fbo == nullptr)
sLog.exception ("Cannot find FBO ", name); sLog.exception ("Cannot find FBO ", name);
return it->second; return fbo;
} }
std::shared_ptr<const CFBO> CWallpaper::getFBO () const { std::shared_ptr<const CFBO> CWallpaper::getFBO () const {
return this->m_sceneFBO; return this->m_sceneFBO;
} }
std::shared_ptr<CWallpaper> CWallpaper::fromWallpaper ( std::unique_ptr<CWallpaper> CWallpaper::fromWallpaper (
std::shared_ptr<const Core::CWallpaper> wallpaper, CRenderContext& context, CAudioContext& audioContext, const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
WebBrowser::CWebBrowserContext* browserContext, const CWallpaperState::TextureUVsScaling& scalingMode, WebBrowser::CWebBrowserContext* browserContext, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode
) { ) {
if (wallpaper->is<Core::Wallpapers::CScene> ()) { if (wallpaper.is<Scene> ()) {
return std::make_shared <WallpaperEngine::Render::Wallpapers::CScene> ( return std::make_unique <WallpaperEngine::Render::Wallpapers::CScene> (
wallpaper, context, audioContext, scalingMode, clampMode); wallpaper, context, audioContext, scalingMode, clampMode);
} else if (wallpaper->is<Core::Wallpapers::CVideo> ()) { } else if (wallpaper.is<Video> ()) {
return std::make_shared<WallpaperEngine::Render::Wallpapers::CVideo> ( return std::make_unique<WallpaperEngine::Render::Wallpapers::CVideo> (
wallpaper, context, audioContext, scalingMode, clampMode); wallpaper, context, audioContext, scalingMode, clampMode);
} else if (wallpaper->is<Core::Wallpapers::CWeb> ()) { } else if (wallpaper.is<Web> ()) {
return std::make_shared<WallpaperEngine::Render::Wallpapers::CWeb> ( return std::make_unique<WallpaperEngine::Render::Wallpapers::CWeb> (
wallpaper, context, audioContext, *browserContext, scalingMode, clampMode); wallpaper, context, audioContext, *browserContext, scalingMode, clampMode);
} else } else
sLog.exception ("Unsupported wallpaper type"); sLog.exception ("Unsupported wallpaper type");

View File

@ -6,18 +6,14 @@
#include "WallpaperEngine/Assets/CContainer.h" #include "WallpaperEngine/Assets/CContainer.h"
#include "WallpaperEngine/Audio/CAudioContext.h" #include "WallpaperEngine/Audio/CAudioContext.h"
#include "WallpaperEngine/Core/CWallpaper.h"
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
#include "WallpaperEngine/Core/Wallpapers/CVideo.h"
#include "WallpaperEngine/Render/CFBO.h" #include "WallpaperEngine/Render/CFBO.h"
#include "WallpaperEngine/Render/CRenderContext.h" #include "WallpaperEngine/Render/CRenderContext.h"
#include "WallpaperEngine/Render/Helpers/CContextAware.h" #include "WallpaperEngine/Render/Helpers/CContextAware.h"
#include "CWallpaperState.h" #include "WallpaperEngine/Data/Model/Wallpaper.h"
using namespace WallpaperEngine::Assets; #include "CFBOProvider.h"
using namespace WallpaperEngine::Audio; #include "CWallpaperState.h"
namespace WallpaperEngine::WebBrowser { namespace WallpaperEngine::WebBrowser {
class CWebBrowserContext; class CWebBrowserContext;
@ -28,7 +24,11 @@ namespace Helpers {
class CContextAware; class CContextAware;
} }
class CWallpaper : public Helpers::CContextAware { using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Audio;
using namespace WallpaperEngine::Data::Model;
class CWallpaper : public Helpers::CContextAware, public CFBOProvider {
public: public:
template <class T> [[nodiscard]] const T* as () const { template <class T> [[nodiscard]] const T* as () const {
if (is <T> ()) { if (is <T> ()) {
@ -65,7 +65,7 @@ class CWallpaper : public Helpers::CContextAware {
/** /**
* @return The container to resolve files for this wallpaper * @return The container to resolve files for this wallpaper
*/ */
[[nodiscard]] std::shared_ptr<const CContainer> getContainer () const; [[nodiscard]] const CContainer& getContainer () const;
/** /**
* @return The current audio context for this wallpaper * @return The current audio context for this wallpaper
@ -80,34 +80,6 @@ class CWallpaper : public Helpers::CContextAware {
* @return The scene's texture * @return The scene's texture
*/ */
[[nodiscard]] virtual GLuint getWallpaperTexture () const; [[nodiscard]] virtual GLuint getWallpaperTexture () const;
/**
* Creates a new FBO for this wallpaper
*
* @param name The name of the FBO
* @param format
* @param flags
* @param scale
* @param realWidth
* @param realHeight
* @param textureWidth
* @param textureHeight
* @return
*/
std::shared_ptr<const CFBO> createFBO (
const std::string& name, ITexture::TextureFormat format, ITexture::TextureFlags flags, float scale,
uint32_t realWidth, uint32_t realHeight, uint32_t textureWidth, uint32_t textureHeight);
/**
* Creates an alias of an existing fbo
* @param alias
* @param original
*/
void aliasFBO (const std::string& alias, const std::shared_ptr<const CFBO>& original);
/**
* @return The full FBO list to work with
*/
[[nodiscard]] const std::map<std::string, std::shared_ptr<const CFBO>>& getFBOs () const;
/** /**
* Searches the FBO list for the given FBO * Searches the FBO list for the given FBO
* *
@ -153,14 +125,14 @@ class CWallpaper : public Helpers::CContextAware {
* *
* @return * @return
*/ */
static std::shared_ptr<CWallpaper> fromWallpaper ( static std::unique_ptr<CWallpaper> fromWallpaper (
std::shared_ptr<const Core::CWallpaper> wallpaper, CRenderContext& context, CAudioContext& audioContext, const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
WebBrowser::CWebBrowserContext* browserContext, const CWallpaperState::TextureUVsScaling& scalingMode, WebBrowser::CWebBrowserContext* browserContext, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode); const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode);
protected: protected:
CWallpaper ( CWallpaper (
std::shared_ptr <const WallpaperEngine::Core::CWallpaper> wallpaperData, CRenderContext& context, const Wallpaper& wallpaperData, CRenderContext& context,
CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode, CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode); const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode);
@ -174,9 +146,9 @@ class CWallpaper : public Helpers::CContextAware {
*/ */
void setupFramebuffers (); void setupFramebuffers ();
std::shared_ptr <const WallpaperEngine::Core::CWallpaper> m_wallpaperData; const Wallpaper& m_wallpaperData;
[[nodiscard]] std::shared_ptr <const WallpaperEngine::Core::CWallpaper> getWallpaperData () const; [[nodiscard]] const Wallpaper& getWallpaperData () const;
/** The FBO used for scene output */ /** The FBO used for scene output */
std::shared_ptr<const CFBO> m_sceneFBO = nullptr; std::shared_ptr<const CFBO> m_sceneFBO = nullptr;

View File

@ -1,60 +0,0 @@
#include "CEffect.h"
using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Render::Objects;
CEffect::CEffect (CImage* image, const Core::Objects::CEffect* effect) :
m_image (image),
m_effect (effect) {
this->generateFBOs ();
this->generatePasses ();
}
CImage* CEffect::getImage () const {
return this->m_image;
}
const std::vector<Effects::CMaterial*>& CEffect::getMaterials () const {
return this->m_materials;
}
std::shared_ptr<const CFBO> CEffect::findFBO (const std::string& name) const {
const auto fbo = this->m_fbos.find (name);
if (fbo == this->m_fbos.end ()) {
return nullptr;
}
return fbo->second;
}
void CEffect::generatePasses () {
for (const auto& cur : this->m_effect->getMaterials ())
this->m_materials.emplace_back (new Effects::CMaterial (this, cur));
}
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.emplace (
cur->getName(),
new CFBO (
// TODO: SET PROPER FLAGS AND FORMAT
cur->getName (), ITexture::TextureFormat::ARGB8888,
this->m_image->getTexture ()->getFlags (), cur->getScale (),
this->m_image->getSize ().x / cur->getScale (),
this->m_image->getSize ().y / cur->getScale (),
this->m_image->getSize ().x / cur->getScale (),
this->m_image->getSize ().y / cur->getScale ()
)
);
}
}
const std::map<std::string, std::shared_ptr<const CFBO>>& CEffect::getFBOs () const {
return this->m_fbos;
}
bool CEffect::isVisible () const {
return this->m_effect->isVisible ();
}

View File

@ -1,47 +0,0 @@
#pragma once
#include "WallpaperEngine/Render/CFBO.h"
#include "WallpaperEngine/Render/Objects/CImage.h"
#include "WallpaperEngine/Render/Objects/Effects/CMaterial.h"
#include "WallpaperEngine/Render/Objects/Effects/CPass.h"
#include "WallpaperEngine/PrettyPrinter/CPrettyPrinter.h"
namespace WallpaperEngine::PrettyPrinter {
class CPrettyPrinter;
}
namespace WallpaperEngine::Render::Objects::Effects {
class CMaterial;
}
namespace WallpaperEngine::Render::Objects {
class CImage;
class CEffect {
public:
CEffect (CImage* image, const Core::Objects::CEffect* effect);
[[nodiscard]] CImage* getImage () const;
[[nodiscard]] const std::vector<Effects::CMaterial*>& getMaterials () const;
[[nodiscard]] std::shared_ptr<const CFBO> findFBO (const std::string& name) const;
[[nodiscard]] bool isVisible () const;
protected:
friend class WallpaperEngine::PrettyPrinter::CPrettyPrinter;
[[nodiscard]] const std::map<std::string, std::shared_ptr<const CFBO>>& getFBOs () const;
private:
void generatePasses ();
void generateFBOs ();
CImage* m_image = nullptr;
const Core::Objects::CEffect* m_effect;
std::map<std::string, std::shared_ptr<const CFBO>> m_fbos = {};
std::vector<Effects::CMaterial*> m_materials = {};
};
} // namespace WallpaperEngine::Render::Objects

View File

@ -1,11 +1,21 @@
#include "CImage.h" #include "CImage.h"
#include <sstream> #include <sstream>
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Data/Parsers/MaterialParser.h"
#include "WallpaperEngine/Data/Builders/UserSettingBuilder.h"
#include "WallpaperEngine/Data/Model/Object.h"
#include "WallpaperEngine/Data/Model/Material.h"
using namespace WallpaperEngine; using namespace WallpaperEngine;
using namespace WallpaperEngine::Render::Objects; using namespace WallpaperEngine::Render::Objects;
using namespace WallpaperEngine::Render::Objects::Effects;
using namespace WallpaperEngine::Data::Parsers;
using namespace WallpaperEngine::Data::Builders;
CImage::CImage (Wallpapers::CScene* scene, const Core::Objects::CImage* image) : CImage::CImage (Wallpapers::CScene& scene, const Image& image) :
Render::CObject (scene, image), Render::CObject (scene, image),
Render::CFBOProvider (&scene),
m_texture (nullptr), m_texture (nullptr),
m_sceneSpacePosition (GL_NONE), m_sceneSpacePosition (GL_NONE),
m_copySpacePosition (GL_NONE), m_copySpacePosition (GL_NONE),
@ -26,19 +36,19 @@ CImage::CImage (Wallpapers::CScene* scene, const Core::Objects::CImage* image) :
m_pos (), m_pos (),
m_animationTime (0.0), m_animationTime (0.0),
m_initialized (false) { m_initialized (false) {
auto projection = this->getScene ()->getScene ()->getOrthogonalProjection ();
// get scene width and height to calculate positions // get scene width and height to calculate positions
auto scene_width = static_cast<float> (projection->getWidth ()); auto scene_width = static_cast<float> (scene.getWidth ());
auto scene_height = static_cast<float> (projection->getHeight ()); auto scene_height = static_cast<float> (scene.getHeight ());
glm::vec3 origin = this->getImage ()->getOrigin (); // TODO: MAKE USE OF THE USER PROPERTIES POINTER HERE TOO! SO EVERYTHING IS UPDATED ACCORDINGLY
glm::vec3 origin = this->getImage ().origin->value->getVec3 ();
glm::vec2 size = this->getSize (); glm::vec2 size = this->getSize ();
glm::vec3 scale = this->getImage ()->getScale (); glm::vec3 scale = this->getImage ().scale->value->getVec3 ();
// fullscreen layers should use the whole projection's size // fullscreen layers should use the whole projection's size
// TODO: WHAT SHOULD AUTOSIZE DO? // TODO: WHAT SHOULD AUTOSIZE DO?
if (this->getImage ()->isFullscreen ()) { if (this->getImage ().model->fullscreen) {
size = {scene_width, scene_height}; size = {scene_width, scene_height};
origin = {scene_width / 2, scene_height / 2, 0}; origin = {scene_width / 2, scene_height / 2, 0};
@ -53,18 +63,18 @@ CImage::CImage (Wallpapers::CScene* scene, const Core::Objects::CImage* image) :
this->m_pos.z = origin.x + (scaledSize.x / 2); this->m_pos.z = origin.x + (scaledSize.x / 2);
this->m_pos.y = origin.y - (scaledSize.y / 2); this->m_pos.y = origin.y - (scaledSize.y / 2);
if (this->getImage ()->getAlignment ().find ("top") != std::string::npos) { if (this->getImage ().alignment.find ("top") != std::string::npos) {
this->m_pos.y -= scaledSize.y / 2; this->m_pos.y -= scaledSize.y / 2;
this->m_pos.w -= scaledSize.y / 2; this->m_pos.w -= scaledSize.y / 2;
} else if (this->getImage ()->getAlignment ().find ("bottom") != std::string::npos) { } else if (this->getImage ().alignment.find ("bottom") != std::string::npos) {
this->m_pos.y += scaledSize.y / 2; this->m_pos.y += scaledSize.y / 2;
this->m_pos.w += scaledSize.y / 2; this->m_pos.w += scaledSize.y / 2;
} }
if (this->getImage ()->getAlignment ().find ("left") != std::string::npos) { if (this->getImage ().alignment.find ("left") != std::string::npos) {
this->m_pos.x += scaledSize.x / 2; this->m_pos.x += scaledSize.x / 2;
this->m_pos.z += scaledSize.x / 2; this->m_pos.z += scaledSize.x / 2;
} else if (this->getImage ()->getAlignment ().find ("right") != std::string::npos) { } else if (this->getImage ().alignment.find ("right") != std::string::npos) {
this->m_pos.x -= scaledSize.x / 2; this->m_pos.x -= scaledSize.x / 2;
this->m_pos.z -= scaledSize.x / 2; this->m_pos.z -= scaledSize.x / 2;
} }
@ -76,19 +86,19 @@ CImage::CImage (Wallpapers::CScene* scene, const Core::Objects::CImage* image) :
this->m_pos.w = scene_height / 2 - this->m_pos.w; this->m_pos.w = scene_height / 2 - this->m_pos.w;
// detect texture (if any) // detect texture (if any)
auto textures = (*this->m_image->getMaterial ()->getPasses ().begin ())->getTextures (); auto textures = (*this->m_image.model->material->passes.begin ())->textures;
if (!textures.empty ()) { if (!textures.empty ()) {
std::string textureName = textures.begin ()->second; std::string textureName = textures.begin ()->second;
if (textureName.find ("_rt_") == 0) { if (textureName.find ("_rt_") == 0) {
this->m_texture = this->getScene ()->findFBO (textureName); this->m_texture = this->getScene ().findFBO (textureName);
} else { } else {
// get the first texture on the first pass (this one represents the image assigned to this object) // get the first texture on the first pass (this one represents the image assigned to this object)
this->m_texture = this->getContext ().resolveTexture (textureName); this->m_texture = this->getContext ().resolveTexture (textureName);
} }
} else { } else {
if (this->m_image->getMaterial ()->isSolidLayer()) { if (this->m_image.model->solidlayer) {
size.x = scene_width; size.x = scene_width;
size.y = scene_height; size.y = scene_height;
} }
@ -105,15 +115,15 @@ CImage::CImage (Wallpapers::CScene* scene, const Core::Objects::CImage* image) :
std::ostringstream nameA, nameB; 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"; nameA << "_rt_imageLayerComposite_" << this->getImage ().id << "_a";
nameB << "_rt_imageLayerComposite_" << this->getImage ()->getId () << "_b"; nameB << "_rt_imageLayerComposite_" << this->getImage ().id << "_b";
this->m_currentMainFBO = this->m_mainFBO = this->m_currentMainFBO = this->m_mainFBO =
scene->createFBO (nameA.str (), ITexture::TextureFormat::ARGB8888, this->m_texture->getFlags (), 1, scene.create (nameA.str (), ITexture::TextureFormat::ARGB8888, this->m_texture->getFlags (), 1,
size.x, size.y, size.x, size.y); {size.x, size.y}, {size.x, size.y});
this->m_currentSubFBO = this->m_subFBO = this->m_currentSubFBO = this->m_subFBO =
scene->createFBO (nameB.str (), ITexture::TextureFormat::ARGB8888, this->m_texture->getFlags (), 1, scene.create (nameB.str (), ITexture::TextureFormat::ARGB8888, this->m_texture->getFlags (), 1,
size.x, size.y, size.x, size.y); {size.x, size.y}, {size.x, size.y});
// build a list of vertices, these might need some change later (or maybe invert the camera) // build a list of vertices, these might need some change later (or maybe invert the camera)
GLfloat sceneSpacePosition [] = {this->m_pos.x, this->m_pos.y, 0.0f, this->m_pos.x, this->m_pos.w, 0.0f, GLfloat sceneSpacePosition [] = {this->m_pos.x, this->m_pos.y, 0.0f, this->m_pos.x, this->m_pos.w, 0.0f,
@ -163,13 +173,13 @@ CImage::CImage (Wallpapers::CScene* scene, const Core::Objects::CImage* image) :
GLfloat realX = 0.0; GLfloat realX = 0.0;
GLfloat realY = 0.0; GLfloat realY = 0.0;
if (this->getImage ()->isPassthrough ()) { if (this->getImage ().model->passthrough) {
x = -((this->m_pos.x + (scene_width / 2)) / size.x); x = -((this->m_pos.x + (scene_width / 2)) / size.x);
y = -((this->m_pos.w + (scene_height / 2)) / size.y); y = -((this->m_pos.w + (scene_height / 2)) / size.y);
height = (this->m_pos.y + (scene_height / 2)) / size.y; height = (this->m_pos.y + (scene_height / 2)) / size.y;
width = (this->m_pos.z + (scene_width / 2)) / size.x; width = (this->m_pos.z + (scene_width / 2)) / size.x;
if (this->getImage ()->isFullscreen ()) { if (this->getImage ().model->fullscreen) {
realX = -1.0; realX = -1.0;
realY = -1.0; realY = -1.0;
realWidth = 1.0; realWidth = 1.0;
@ -210,7 +220,7 @@ CImage::CImage (Wallpapers::CScene* scene, const Core::Objects::CImage* image) :
glBufferData (GL_ARRAY_BUFFER, sizeof (texcoordPass), texcoordPass, GL_STATIC_DRAW); glBufferData (GL_ARRAY_BUFFER, sizeof (texcoordPass), texcoordPass, GL_STATIC_DRAW);
this->m_modelViewProjectionScreen = this->m_modelViewProjectionScreen =
this->getScene ()->getCamera ()->getProjection () * this->getScene ()->getCamera ()->getLookAt (); this->getScene ().getCamera ().getProjection () * this->getScene ().getCamera ().getLookAt ();
this->m_modelViewProjectionScreenInverse = glm::inverse (this->m_modelViewProjectionScreen); this->m_modelViewProjectionScreenInverse = glm::inverse (this->m_modelViewProjectionScreen);
@ -226,62 +236,79 @@ void CImage::setup () {
return; return;
// TODO: SUPPORT PASSTHROUGH (IT'S A SHADER) // TODO: SUPPORT PASSTHROUGH (IT'S A SHADER)
// passthrough images without effects are bad, do not draw them // passthrough images without effects are bad, do not draw them
if (this->getImage ()->isPassthrough () && this->getImage ()->getEffects ().empty ()) if (this->m_image.model->passthrough && this->m_image.effects.empty ())
return; return;
// generate the main material used to render the image
this->m_material = new Effects::CMaterial (
new CEffect (
this,
new Core::Objects::CEffect (
"", "", "", "", this->m_image->getProject (),
Core::UserSettings::CUserSettingBoolean::fromScalar (true),
{}, {}, {})),
this->m_image->getMaterial ()
);
// add blendmode to the combos // add blendmode to the combos
for (const auto& cur : this->m_material->getPasses ()) for (const auto& cur : this->getImage ().model->material->passes)
this->m_passes.push_back (cur); this->m_passes.push_back (
new CPass (*this, std::make_shared<CFBOProvider>(this), *cur, std::nullopt, std::nullopt, std::nullopt)
);
// TODO: MAYBE GET RID OF THE WHOLE EFFECT CLASS AND PROCESS THE EFFECTS DIRECTLY TO SIMPLIFY RENDERING CODE?
// prepare the passes list // prepare the passes list
if (!this->getImage ()->getEffects ().empty ()) { if (!this->getImage ().effects.empty ()) {
// generate the effects used by this material // generate the effects used by this material
for (const auto& cur : this->getImage ()->getEffects ()) { for (const auto& cur : this->m_image.effects) {
auto effect = new CEffect (this, cur); auto fboProvider = std::make_shared<CFBOProvider> (this);
for (const auto& material : effect->getMaterials ()) // create all the fbos for this effect
for (const auto& pass : material->getPasses ()) for (const auto& fbo : cur->effect->fbos) {
this->m_passes.push_back (pass); fboProvider->create (*fbo, this->m_texture->getFlags (), this->getSize ());
}
this->m_effects.push_back (effect); // TODO: MAKE USE OF ZIP OPERATOR IN BOOST? WAY OVERKILL JUST FOR THIS...
auto curEffect = cur->effect->passes.begin ();
auto endEffect = cur->effect->passes.end ();
auto curOverride = cur->passOverrides.begin ();
auto endOverride = cur->passOverrides.end ();
for (; curEffect != endEffect; curEffect++) {
auto curPass = (*curEffect)->material->passes.begin ();
auto endPass = (*curEffect)->material->passes.end ();
const auto override = curOverride != endOverride
? **curOverride
: std::optional<std::reference_wrapper<const ImageEffectPassOverride>> (std::nullopt);
const auto target = (*curEffect)->target.has_value ()
? *(*curEffect)->target
: std::optional<std::reference_wrapper<std::string>> (std::nullopt);
this->m_passes.push_back (
new CPass (
*this, fboProvider, **curPass, override, (*curEffect)->binds, target)
);
if (curOverride != endOverride) {
curOverride ++;
}
}
} }
} }
if (this->m_image->getColorBlendMode () > 0) { if (this->m_image.colorBlendMode > 0) {
Core::Objects::Images::CMaterial::OverrideInfo overrides; this->m_materials.colorBlending.material = MaterialParser::load (this->getScene ().getScene ().project, "materials/util/effectpassthrough.json");
this->m_materials.colorBlending.override = std::make_unique<ImageEffectPassOverride> (ImageEffectPassOverride {
.id = -1,
.combos = {
{"BLENDMODE", this->m_image.colorBlendMode},
},
.constants = {},
.textures = {},
});
overrides.combos.emplace ("BLENDMODE", this->m_image->getColorBlendMode ()); this->m_passes.push_back (
const auto material = new CPass (
Core::Objects::Images::CMaterial::fromFile ("materials/util/effectpassthrough.json", this->getContainer (), false, {}, &overrides); *this,
std::make_shared <CFBOProvider>(this),
// generate the main material used to render the image **this->m_materials.colorBlending.material->passes.begin (),
this->m_colorBlendMaterial = new Effects::CMaterial ( *this->m_materials.colorBlending.override,
new CEffect ( std::nullopt,
this, std::nullopt
new Core::Objects::CEffect ( )
"", "", "", "", this->m_image->getProject (),
Core::UserSettings::CUserSettingBoolean::fromScalar (true), {}, {}, {}
)
),
material
); );
// add blendmode to the combos
for (const auto& cur : this->m_colorBlendMaterial->getPasses ())
this->m_passes.push_back (cur);
} }
// if there's more than one pass the blendmode has to be moved from the beginning to the end // if there's more than one pass the blendmode has to be moved from the beginning to the end
@ -327,22 +354,24 @@ void CImage::setupPasses () {
pass->setViewProjectionMatrix (&this->m_viewProjectionMatrix); pass->setViewProjectionMatrix (&this->m_viewProjectionMatrix);
// set viewport and target texture if needed // set viewport and target texture if needed
if (pass->getMaterial ()->getMaterial ()->hasTarget ()) { if (pass->getTarget ().has_value ()) {
// setup target texture // setup target texture
std::string target = pass->getMaterial ()->getMaterial ()->getTarget (); std::string target = pass->getTarget ().value ();
drawTo = pass->getMaterial ()->getEffect ()->findFBO (target); drawTo = pass->getFBOProvider ()->find (target);
// spacePosition = this->getPassSpacePosition (); // spacePosition = this->getPassSpacePosition ();
// not a local fbo, try to find a scene fbo with the same name // not a local fbo, try to find a scene fbo with the same name
if (drawTo == nullptr) if (drawTo == nullptr) {
// this one throws if no fbo was found // this one throws if no fbo was found
drawTo = this->getScene ()->findFBO (target); 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 IF THIS IS ALL THAT'S NEEDED
else if (std::next (cur) == end && this->getImage ().visible->value->getBool ()) {
// TODO: PROPERLY CHECK EFFECT'S VISIBILITY AND TAKE IT INTO ACCOUNT // TODO: PROPERLY CHECK EFFECT'S VISIBILITY AND TAKE IT INTO ACCOUNT
spacePosition = this->getSceneSpacePosition (); spacePosition = this->getSceneSpacePosition ();
drawTo = this->getScene ()->getFBO (); drawTo = this->getScene ().getFBO ();
projection = &this->m_modelViewProjectionScreen; projection = &this->m_modelViewProjectionScreen;
inverseProjection = &this->m_modelViewProjectionScreenInverse; inverseProjection = &this->m_modelViewProjectionScreenInverse;
} }
@ -357,7 +386,7 @@ void CImage::setupPasses () {
texcoord = this->getTexCoordPass (); texcoord = this->getTexCoordPass ();
drawTo = prevDrawTo; drawTo = prevDrawTo;
if (!pass->getMaterial ()->getMaterial ()->hasTarget ()) if (!pass->getTarget ().has_value ())
this->pinpongFramebuffer (&drawTo, &asInput); this->pinpongFramebuffer (&drawTo, &asInput);
} }
} }
@ -387,17 +416,17 @@ void CImage::render () {
// update the position if required // update the position if required
// TODO: There's more images that are not affected by parallax, autosize or fullscreen are not affected // TODO: There's more images that are not affected by parallax, autosize or fullscreen are not affected
if (this->getScene ()->getScene ()->isCameraParallax () && !this->getImage ()->isFullscreen ()) if (this->getScene ().getScene ().camera.parallax.enabled && !this->getImage ().model->fullscreen)
this->updateScreenSpacePosition (); this->updateScreenSpacePosition ();
#if !NDEBUG #if !NDEBUG
std::string str = "Rendering "; std::string str = "Rendering ";
if (this->getScene ()->getScene ()->isBloom () && this->getId () == -1) if (this->getScene ().getScene ().camera.bloom.enabled->value->getBool () && this->getId () == -1)
str += "bloom"; str += "bloom";
else { else {
str += this->getImage ()->getName () + " (" + std::to_string (this->getId ()) + ", " + str += this->getImage ().name + " (" + std::to_string (this->getId ()) + ", " +
this->getImage ()->getMaterial ()->getName () + ")"; this->getImage ().model->material->filename + ")";
} }
glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ()); glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ());
@ -421,20 +450,21 @@ void CImage::render () {
void CImage::updateScreenSpacePosition () { void CImage::updateScreenSpacePosition () {
// do not perform any changes to the image based on the parallax if it was explicitly disabled // do not perform any changes to the image based on the parallax if it was explicitly disabled
if (this->getScene ()->getContext ().getApp ().getContext ().settings.mouse.disableparallax) { if (this->getScene ().getContext ().getApp ().getContext ().settings.mouse.disableparallax) {
return; return;
} }
const double parallaxAmount = this->getScene ()->getScene ()->getCameraParallaxAmount (); const double parallaxAmount = this->getScene ().getScene ().camera.parallax.amount;
const glm::vec2 depth = this->getImage ()->getParallaxDepth (); const glm::vec2 depth = this->getImage ().parallaxDepth;
const glm::vec2* displacement = this->getScene ()->getParallaxDisplacement (); const glm::vec2* displacement = this->getScene ().getParallaxDisplacement ();
float x = (depth.x + parallaxAmount) * displacement->x * this->getSize ().x; float x = (depth.x + parallaxAmount) * displacement->x * this->getSize ().x;
float y = (depth.y + parallaxAmount) * displacement->y * this->getSize ().x; float y = (depth.y + parallaxAmount) * displacement->y * this->getSize ().x;
this->m_modelViewProjectionScreen = glm::translate (this->getScene ()->getCamera ()->getProjection () * this->m_modelViewProjectionScreen = glm::translate (
this->getScene ()->getCamera ()->getLookAt (), this->getScene ().getCamera ().getProjection () * this->getScene ().getCamera ().getLookAt (),
{x, y, 0.0f}); {x, y, 0.0f}
);
} }
std::shared_ptr<const ITexture> CImage::getTexture () const { std::shared_ptr<const ITexture> CImage::getTexture () const {
@ -445,7 +475,7 @@ double CImage::getAnimationTime () const {
return this->m_animationTime; return this->m_animationTime;
} }
const Core::Objects::CImage* CImage::getImage () const { const Image& CImage::getImage () const {
return this->m_image; return this->m_image;
} }
@ -459,7 +489,7 @@ const Effects::CMaterial* CImage::getMaterial () const {
glm::vec2 CImage::getSize () const { glm::vec2 CImage::getSize () const {
if (this->m_texture == nullptr) if (this->m_texture == nullptr)
return this->getImage ()->getSize (); return this->getImage ().size;
return {this->m_texture->getRealWidth (), this->m_texture->getRealHeight ()}; return {this->m_texture->getRealWidth (), this->m_texture->getRealHeight ()};
} }

View File

@ -1,10 +1,6 @@
#pragma once #pragma once
#include "WallpaperEngine/Core/Objects/CImage.h"
#include "WallpaperEngine/Render/CObject.h" #include "WallpaperEngine/Render/CObject.h"
#include "WallpaperEngine/Render/Objects/CEffect.h"
#include "WallpaperEngine/Render/Objects/Effects/CMaterial.h"
#include "WallpaperEngine/Render/Objects/Effects/CPass.h" #include "WallpaperEngine/Render/Objects/Effects/CPass.h"
#include "WallpaperEngine/Render/Wallpapers/CScene.h" #include "WallpaperEngine/Render/Wallpapers/CScene.h"
@ -25,16 +21,16 @@ class CPass;
namespace WallpaperEngine::Render::Objects { namespace WallpaperEngine::Render::Objects {
class CEffect; class CEffect;
class CImage final : public CObject { class CImage final : public CObject, public CFBOProvider {
friend CObject; friend CObject;
public: public:
CImage (Wallpapers::CScene* scene, const Core::Objects::CImage* image); CImage (Wallpapers::CScene& scene, const Image& image);
void setup (); void setup ();
void render () override; void render () override;
[[nodiscard]] const Core::Objects::CImage* getImage () const; [[nodiscard]] const Image& getImage () const;
[[nodiscard]] const std::vector<CEffect*>& getEffects () const; [[nodiscard]] const std::vector<CEffect*>& getEffects () const;
[[nodiscard]] const Effects::CMaterial* getMaterial () const; [[nodiscard]] const Effects::CMaterial* getMaterial () const;
[[nodiscard]] glm::vec2 getSize () const; [[nodiscard]] glm::vec2 getSize () const;
@ -83,7 +79,7 @@ class CImage final : public CObject {
std::shared_ptr<const CFBO> m_currentMainFBO = nullptr; std::shared_ptr<const CFBO> m_currentMainFBO = nullptr;
std::shared_ptr<const CFBO> m_currentSubFBO = nullptr; std::shared_ptr<const CFBO> m_currentSubFBO = nullptr;
const Core::Objects::CImage* m_image; const Image& m_image;
std::vector<CEffect*> m_effects = {}; std::vector<CEffect*> m_effects = {};
Effects::CMaterial* m_material = nullptr; Effects::CMaterial* m_material = nullptr;
@ -95,5 +91,12 @@ class CImage final : public CObject {
double m_animationTime = 0.0; double m_animationTime = 0.0;
bool m_initialized = false; bool m_initialized = false;
struct {
struct {
MaterialUniquePtr material;
ImageEffectPassOverrideUniquePtr override;
} colorBlending;
} m_materials;
}; };
} // namespace WallpaperEngine::Render::Objects } // namespace WallpaperEngine::Render::Objects

View File

@ -4,7 +4,7 @@
using namespace WallpaperEngine::Render::Objects; using namespace WallpaperEngine::Render::Objects;
CSound::CSound (Wallpapers::CScene* scene, const Core::Objects::CSound* sound) : CSound::CSound (Wallpapers::CScene& scene, const Sound& sound) :
CObject (scene, sound), CObject (scene, sound),
m_sound (sound) { m_sound (sound) {
if (this->getContext ().getApp ().getContext ().settings.audio.enabled) if (this->getContext ().getApp ().getContext ().settings.audio.enabled)
@ -21,19 +21,19 @@ CSound::~CSound() {
} }
void CSound::load () { void CSound::load () {
for (const auto& cur : this->m_sound->getSounds ()) { for (const auto& cur : this->m_sound.sounds) {
uint32_t filesize = 0; uint32_t filesize = 0;
std::shared_ptr<const uint8_t[]> filebuffer = this->getContainer ()->readFile (cur, &filesize); std::shared_ptr<const uint8_t[]> filebuffer = this->getContainer ().readFile (cur, &filesize);
auto stream = new Audio::CAudioStream (this->getScene ()->getAudioContext (), filebuffer, filesize); auto stream = new Audio::CAudioStream (this->getScene ().getAudioContext (), filebuffer, filesize);
stream->setRepeat (this->m_sound->isRepeat ()); stream->setRepeat (this->m_sound.playbackmode.has_value() && this->m_sound.playbackmode == "loop");
this->m_audioStreams.push_back (stream); this->m_audioStreams.push_back (stream);
this->m_soundBuffer.push_back (filebuffer); this->m_soundBuffer.push_back (filebuffer);
// add the stream to the context so it can be played // add the stream to the context so it can be played
this->getScene ()->getAudioContext ().addStream (stream); this->getScene ().getAudioContext ().addStream (stream);
} }
} }

View File

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "WallpaperEngine/Core/Objects/CSound.h"
#include "WallpaperEngine/Audio/CAudioStream.h" #include "WallpaperEngine/Audio/CAudioStream.h"
#include "WallpaperEngine/Render/CObject.h" #include "WallpaperEngine/Render/CObject.h"
@ -12,9 +10,11 @@ class CScene;
} }
namespace WallpaperEngine::Render::Objects { namespace WallpaperEngine::Render::Objects {
using namespace WallpaperEngine::Data::Model;
class CSound final : public CObject { class CSound final : public CObject {
public: public:
CSound (Wallpapers::CScene* scene, const Core::Objects::CSound* sound); CSound (Wallpapers::CScene& scene, const Sound& sound);
~CSound () override; ~CSound () override;
void render () override; void render () override;
@ -26,6 +26,6 @@ class CSound final : public CObject {
std::vector<std::shared_ptr<const uint8_t[]>> m_soundBuffer = {}; std::vector<std::shared_ptr<const uint8_t[]>> m_soundBuffer = {};
std::vector<Audio::CAudioStream*> m_audioStreams = {}; std::vector<Audio::CAudioStream*> m_audioStreams = {};
const Core::Objects::CSound* m_sound; const Sound& m_sound;
}; };
} // namespace WallpaperEngine::Render::Objects } // namespace WallpaperEngine::Render::Objects

View File

@ -1,34 +0,0 @@
#include "CMaterial.h"
using namespace WallpaperEngine::Render::Objects;
using namespace WallpaperEngine::Render::Objects::Effects;
CMaterial::CMaterial (const Render::Objects::CEffect* effect, const Core::Objects::Images::CMaterial* material) :
Helpers::CContextAware (effect->getImage ()),
m_effect (effect),
m_material (material) {
this->generatePasses ();
}
const std::vector<CPass*>& CMaterial::getPasses () const {
return this->m_passes;
}
CImage* CMaterial::getImage () const {
return this->m_effect->getImage ();
}
void CMaterial::generatePasses () {
// these are simple now, just create the entries and done
for (const auto& cur : this->m_material->getPasses ())
this->m_passes.emplace_back (new CPass (this, cur));
}
const Core::Objects::Images::CMaterial* CMaterial::getMaterial () const {
return this->m_material;
}
const CEffect* CMaterial::getEffect () const {
return this->m_effect;
}

View File

@ -1,42 +0,0 @@
#pragma once
#include "WallpaperEngine/Core/Objects/CEffect.h"
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
#include "WallpaperEngine/Render/Objects/CEffect.h"
#include "WallpaperEngine/Render/Objects/Effects/CPass.h"
#include "WallpaperEngine/Render/Helpers/CContextAware.h"
#include "CPass.h"
using namespace WallpaperEngine;
namespace WallpaperEngine::Render::Objects {
class CEffect;
class CImage;
} // namespace WallpaperEngine::Render::Objects
namespace WallpaperEngine::Render::Objects::Effects {
class CPass;
class CMaterial final : public Helpers::CContextAware {
friend class CPass;
public:
CMaterial (const Render::Objects::CEffect* effect, const Core::Objects::Images::CMaterial* material);
[[nodiscard]] const std::vector<CPass*>& getPasses () const;
[[nodiscard]] CImage* getImage () const;
[[nodiscard]] const Core::Objects::Images::CMaterial* getMaterial () const;
[[nodiscard]] const CEffect* getEffect () const;
private:
void generatePasses ();
const Render::Objects::CEffect* m_effect;
const Core::Objects::Images::CMaterial* m_material;
std::vector<CPass*> m_passes = {};
};
} // namespace WallpaperEngine::Render::Objects::Effects

View File

@ -1,8 +1,15 @@
#include "CPass.h" #include "CPass.h"
#include "WallpaperEngine/Render/CFBO.h"
#include <sstream> #include <sstream>
#include <utility> #include <utility>
#include "WallpaperEngine/Render/Helpers/CContextAware.h"
#include "WallpaperEngine/Data/Model/Effect.h"
#include "WallpaperEngine/Data/Model/Material.h"
#include "WallpaperEngine/Render/Objects/CImage.h"
#include "WallpaperEngine/Render/CFBO.h"
#include "WallpaperEngine/Core/Projects/CProperty.h" #include "WallpaperEngine/Core/Projects/CProperty.h"
#include "WallpaperEngine/Core/Projects/CPropertyColor.h" #include "WallpaperEngine/Core/Projects/CPropertyColor.h"
#include "WallpaperEngine/Core/Projects/CPropertyCombo.h" #include "WallpaperEngine/Core/Projects/CPropertyCombo.h"
@ -25,19 +32,35 @@
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantProperty.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantProperty.h"
#include "WallpaperEngine/Logging/CLog.h" #include "WallpaperEngine/Logging/CLog.h"
using namespace WallpaperEngine::Core::Objects::Effects::Constants; using namespace WallpaperEngine;
using namespace WallpaperEngine::Render::Shaders::Variables; using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Render::Objects;
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
using namespace WallpaperEngine::Render::Shaders::Variables;
using namespace WallpaperEngine::Render::Objects::Effects; using namespace WallpaperEngine::Render::Objects::Effects;
extern float g_Time; extern float g_Time;
extern float g_Daytime; extern float g_Daytime;
CPass::CPass (CMaterial* material, const Core::Objects::Images::Materials::CPass* pass) : const TextureMap DEFAULT_BINDS = {};
Helpers::CContextAware (material), const ImageEffectPassOverride DEFAULT_OVERRIDE = {};
m_material (material),
CPass::CPass (
CImage& image, std::shared_ptr<const CFBOProvider> fboProvider, const MaterialPass& pass,
std::optional<std::reference_wrapper<const ImageEffectPassOverride>> override,
std::optional<std::reference_wrapper<const TextureMap>> binds,
std::optional<std::reference_wrapper<std::string>> target
) :
Helpers::CContextAware (image),
m_image (image),
m_pass (pass), m_pass (pass),
m_blendingmode (pass->getBlendingMode ()) { m_blendingmode (pass.blending),
m_binds (binds.has_value () ? binds.value ().get () : DEFAULT_BINDS),
m_override (override.has_value () ? override.value ().get () : DEFAULT_OVERRIDE),
m_fboProvider (fboProvider),
m_target (target) {
this->setupShaders (); this->setupShaders ();
this->setupShaderVariables (); this->setupShaderVariables ();
} }
@ -51,25 +74,21 @@ std::shared_ptr<const ITexture> CPass::resolveTexture (std::shared_ptr<const ITe
} }
// first check in the binds and replace it if necessary // first check in the binds and replace it if necessary
const auto it = this->m_material->getMaterial ()->getTextureBinds ().find (index); const auto it = this->m_binds.find (index);
if (it == this->m_material->getMaterial ()->getTextureBinds ().end ()) if (it == this->m_binds.end ())
return expected; return expected;
// a bind named "previous" is just another way of telling it to use whatever texture there was already // a bind named "previous" is just another way of telling it to use whatever texture there was already
if (it->second->getName () == "previous") if (it->second == "previous")
return previous ?: expected; return previous ?: expected;
// the bind actually has a name, search the FBO in the effect and return it // the bind actually has a name, search the FBO in the effect and return it
return this->resolveFBO (it->second->getName ()); return this->resolveFBO (it->second);
} }
std::shared_ptr<const CFBO> CPass::resolveFBO (const std::string& name) const { std::shared_ptr<const CFBO> CPass::resolveFBO (const std::string& name) const {
auto fbo = this->m_material->getEffect()->findFBO (name); auto fbo = this->m_fboProvider->find (name);
if (fbo == nullptr) {
fbo = this->m_material->getImage ()->getScene ()->findFBO (name);
}
if (fbo == nullptr) { if (fbo == nullptr) {
sLog.exception ("Tried to resolve and FBO without any luck: ", name); sLog.exception ("Tried to resolve and FBO without any luck: ", name);
@ -100,19 +119,19 @@ void CPass::setupRenderFramebuffer () {
} }
// set depth testing // set depth testing
if (this->m_pass->getDepthTest () == "disabled") { if (this->m_pass.depthtest == "disabled") {
glDisable (GL_DEPTH_TEST); glDisable (GL_DEPTH_TEST);
} else { } else {
glEnable (GL_DEPTH_TEST); glEnable (GL_DEPTH_TEST);
} }
if (this->m_pass->getCullingMode () == "nocull") { if (this->m_pass.cullmode == "nocull") {
glDisable (GL_CULL_FACE); glDisable (GL_CULL_FACE);
} else { } else {
glEnable (GL_CULL_FACE); glEnable (GL_CULL_FACE);
} }
if (this->m_pass->getDepthWrite () == "disabled") { if (this->m_pass.depthwrite == "disabled") {
glDepthMask (false); glDepthMask (false);
} else { } else {
glDepthMask (true); glDepthMask (true);
@ -133,7 +152,7 @@ void CPass::setupRenderTexture () {
if (texture->isAnimated ()) { if (texture->isAnimated ()) {
// calculate current texture and frame // calculate current texture and frame
double currentRenderTime = fmod (static_cast<double> (this->getContext ().getDriver ().getRenderTime ()), double currentRenderTime = fmod (static_cast<double> (this->getContext ().getDriver ().getRenderTime ()),
this->m_material->getImage ()->getAnimationTime ()); this->m_image.getAnimationTime ());
for (const auto& frameCur : texture->getFrames ()) { for (const auto& frameCur : texture->getFrames ()) {
currentRenderTime -= frameCur->frametime; currentRenderTime -= frameCur->frametime;
@ -246,8 +265,8 @@ void CPass::setupRenderAttributes () {
#if !NDEBUG #if !NDEBUG
glObjectLabel (GL_BUFFER, *cur->value, -1, glObjectLabel (GL_BUFFER, *cur->value, -1,
("Image " + std::to_string (this->getMaterial ()->getImage ()->getId ()) + " Pass " + ("Image " + std::to_string (this->m_image.getId ()) + " Pass " +
this->m_pass->getShader () + " " + cur->name) this->m_pass.shader + " " + cur->name)
.c_str ()); .c_str ());
#endif /* DEBUG */ #endif /* DEBUG */
} }
@ -287,8 +306,12 @@ void CPass::render () {
this->cleanupRenderSetup (); this->cleanupRenderSetup ();
} }
const CMaterial* CPass::getMaterial () const { std::shared_ptr<const CFBOProvider> CPass::getFBOProvider () const {
return this->m_material; return this->m_fboProvider;
}
const CImage& CPass::getImage () const {
return this->m_image;
} }
void CPass::setDestination (std::shared_ptr<const CFBO> drawTo) { void CPass::setDestination (std::shared_ptr<const CFBO> drawTo) {
@ -331,10 +354,14 @@ void CPass::setPosition (GLuint position) {
this->a_Position = position; this->a_Position = position;
} }
const Core::Objects::Images::Materials::CPass* CPass::getPass () const { const MaterialPass& CPass::getPass () const {
return this->m_pass; return this->m_pass;
} }
const std::optional<std::reference_wrapper<std::string>> CPass::getTarget () const {
return this->m_target;
}
Render::Shaders::CShader* CPass::getShader () const { Render::Shaders::CShader* CPass::getShader () const {
return this->m_shader; return this->m_shader;
} }
@ -379,10 +406,10 @@ GLuint CPass::compileShader (const char* shader, GLuint type) {
void CPass::setupShaders () { void CPass::setupShaders () {
// ensure the constants are defined // ensure the constants are defined
std::shared_ptr<const ITexture> texture0 = this->m_material->getImage ()->getTexture (); std::shared_ptr<const ITexture> texture0 = this->m_image.getTexture ();
// copy the combos from the pass // copy the combos from the pass
this->m_combos.insert (this->m_pass->getCombos ().begin (), this->m_pass->getCombos ().end ()); this->m_combos.insert (this->m_pass.combos.begin (), this->m_pass.combos.end ());
// TODO: THE VALUES ARE THE SAME AS THE ENUMERATION, SO MAYBE IT HAS TO BE SPECIFIED FOR THE TEXTURE 0 OF ALL // TODO: THE VALUES ARE THE SAME AS THE ENUMERATION, SO MAYBE IT HAS TO BE SPECIFIED FOR THE TEXTURE 0 OF ALL
// ELEMENTS? // ELEMENTS?
@ -398,8 +425,8 @@ void CPass::setupShaders () {
// TODO: USED TO BUILD THE TEXTURES LATER // TODO: USED TO BUILD THE TEXTURES LATER
// use the combos copied from the pass so it includes the texture format // use the combos copied from the pass so it includes the texture format
this->m_shader = new Render::Shaders::CShader ( this->m_shader = new Render::Shaders::CShader (
this->getMaterial ()->getImage ()->getContainer (), this->m_pass->getShader (), this->m_combos, this->m_image.getContainer (), this->m_pass.shader, this->m_combos,
this->m_pass->getTextures (), this->m_pass->getConstants () this->m_pass.textures, this->m_override.constants
); );
const auto shaders = Shaders::CGLSLContext::get ().toGlsl ( const auto shaders = Shaders::CGLSLContext::get ().toGlsl (
@ -441,9 +468,9 @@ void CPass::setupShaders () {
} }
#if !NDEBUG #if !NDEBUG
glObjectLabel (GL_PROGRAM, this->m_programID, -1, this->m_pass->getShader ().c_str ()); glObjectLabel (GL_PROGRAM, this->m_programID, -1, this->m_pass.shader.c_str ());
glObjectLabel (GL_SHADER, vertexShaderID, -1, (this->m_pass->getShader () + ".vert").c_str ()); glObjectLabel (GL_SHADER, vertexShaderID, -1, (this->m_pass.shader + ".vert").c_str ());
glObjectLabel (GL_SHADER, fragmentShaderID, -1, (this->m_pass->getShader () + ".frag").c_str ()); glObjectLabel (GL_SHADER, fragmentShaderID, -1, (this->m_pass.shader + ".frag").c_str ());
#endif /* DEBUG */ #endif /* DEBUG */
// after being liked shaders can be dettached and deleted // after being liked shaders can be dettached and deleted
@ -507,7 +534,7 @@ void CPass::setupTextureUniforms () {
} }
} }
for (const auto& [index, textureName] : this->m_pass->getTextures ()) { for (const auto& [index, textureName] : this->m_pass.textures) {
// ignore first texture as that'll be the input of the previous pass (or the image if it's the first pass) // ignore first texture as that'll be the input of the previous pass (or the image if it's the first pass)
if (index == 0) { if (index == 0) {
continue; continue;
@ -516,23 +543,23 @@ void CPass::setupTextureUniforms () {
if (textureName.find ("_rt_") == 0) { if (textureName.find ("_rt_") == 0) {
this->m_textures[index] = this->resolveFBO (textureName); this->m_textures[index] = this->resolveFBO (textureName);
} else if (!textureName.empty ()) { } else if (!textureName.empty ()) {
this->m_textures[index] = this->m_material->getImage ()->getContext ().resolveTexture (textureName); this->m_textures[index] = this->m_image.getContext ().resolveTexture (textureName);
} }
} }
// binds are set last as they're the most important to be set // binds are set last as they're the most important to be set
for (const auto& [index, bind] : this->m_material->getMaterial ()->getTextureBinds ()) { for (const auto& [index, bind] : this->m_binds) {
if (bind->getName () == "previous") { if (bind == "previous") {
// use nullptr as indication for "previous" texture // use nullptr as indication for "previous" texture
this->m_textures [index] = nullptr; this->m_textures [index] = nullptr;
} else { } else {
// a normal bind, search for the corresponding FBO and set it // a normal bind, search for the corresponding FBO and set it
this->m_textures [index] = this->resolveFBO (bind->getName ()); this->m_textures [index] = this->resolveFBO (bind);
} }
} }
// resolve the main texture // resolve the main texture
std::shared_ptr<const ITexture> texture = this->resolveTexture (this->m_material->getImage ()->getTexture (), 0); std::shared_ptr<const ITexture> texture = this->resolveTexture (this->m_image.getTexture (), 0);
// register all the texture uniforms with correct values // register all the texture uniforms with correct values
this->addUniform ("g_Texture0", 0); this->addUniform ("g_Texture0", 0);
this->addUniform ("g_Texture1", 1); this->addUniform ("g_Texture1", 1);
@ -557,21 +584,22 @@ void CPass::setupTextureUniforms () {
void CPass::setupUniforms () { void CPass::setupUniforms () {
this->setupTextureUniforms (); this->setupTextureUniforms ();
const auto projection = this->getMaterial ()->getImage ()->getScene ()->getScene ()->getOrthogonalProjection (); const auto& image = this->m_image.getImage ();
const auto& scene = this->m_image.getScene ();
const auto& sceneData = this->m_image.getScene ().getScene ();
const auto& recorder = this->m_image.getScene ().getAudioContext ().getRecorder ();
// lighting variables // lighting variables
this->addUniform ("g_LightAmbientColor", this->addUniform ("g_LightAmbientColor", sceneData.colors.ambient);
this->m_material->getImage ()->getScene ()->getScene ()->getAmbientColor ()); this->addUniform ("g_LightSkylightColor", sceneData.colors.skylight);
this->addUniform ("g_LightSkylightColor",
this->m_material->getImage ()->getScene ()->getScene ()->getSkylightColor ());
// register variables like brightness and alpha with some default value // register variables like brightness and alpha with some default value
this->addUniform ("g_Brightness", this->m_material->getImage ()->getImage ()->getBrightness ()); this->addUniform ("g_Brightness", image.brightness);
this->addUniform ("g_UserAlpha", this->m_material->getImage ()->getImage ()->getAlpha ()); this->addUniform ("g_UserAlpha", image.alpha->value->getFloat ());
this->addUniform ("g_Alpha", this->m_material->getImage ()->getImage ()->getAlpha ()); this->addUniform ("g_Alpha", image.alpha->value->getFloat ());
this->addUniform ("g_Color", this->m_material->getImage ()->getImage ()->getColor ()); this->addUniform ("g_Color", image.color->value->getVec3 ());
this->addUniform ("g_Color4", glm::vec4 (this->m_material->getImage ()->getImage ()->getColor (), 1)); this->addUniform ("g_Color4", image.color->value->getVec4());
// TODO: VALIDATE THAT G_COMPOSITECOLOR REALLY COMES FROM THIS ONE // TODO: VALIDATE THAT G_COMPOSITECOLOR REALLY COMES FROM THIS ONE
this->addUniform ("g_CompositeColor", this->m_material->getImage ()->getImage ()->getColor ()); this->addUniform ("g_CompositeColor", image.color->value->getVec3 ());
// add some external variables // add some external variables
this->addUniform ("g_Time", &g_Time); this->addUniform ("g_Time", &g_Time);
this->addUniform ("g_Daytime", &g_Daytime); this->addUniform ("g_Daytime", &g_Daytime);
@ -581,24 +609,18 @@ void CPass::setupUniforms () {
this->addUniform ("g_ModelMatrix", &this->m_modelMatrix); this->addUniform ("g_ModelMatrix", &this->m_modelMatrix);
this->addUniform ("g_NormalModelMatrix", glm::identity<glm::mat3> ()); this->addUniform ("g_NormalModelMatrix", glm::identity<glm::mat3> ());
this->addUniform ("g_ViewProjectionMatrix", &this->m_viewProjectionMatrix); this->addUniform ("g_ViewProjectionMatrix", &this->m_viewProjectionMatrix);
this->addUniform ("g_PointerPosition", this->m_material->getImage ()->getScene ()->getMousePosition ()); this->addUniform ("g_PointerPosition", scene.getMousePosition ());
this->addUniform ("g_PointerPositionLast", this->m_material->getImage ()->getScene ()->getMousePositionLast ()); this->addUniform ("g_PointerPositionLast", scene.getMousePositionLast ());
this->addUniform ("g_EffectTextureProjectionMatrix", glm::mat4 (1.0)); this->addUniform ("g_EffectTextureProjectionMatrix", glm::mat4 (1.0));
this->addUniform ("g_EffectTextureProjectionMatrixInverse", glm::mat4 (1.0)); this->addUniform ("g_EffectTextureProjectionMatrixInverse", glm::mat4 (1.0));
this->addUniform ("g_TexelSize", glm::vec2 (1.0 / projection->getWidth (), 1.0 / projection->getHeight ())); this->addUniform ("g_TexelSize", glm::vec2 (1.0 / scene.getWidth (), 1.0 / scene.getHeight ()));
this->addUniform ("g_TexelSizeHalf", glm::vec2 (0.5 / projection->getWidth (), 0.5 / projection->getHeight ())); this->addUniform ("g_TexelSizeHalf", glm::vec2 (0.5 / scene.getWidth (), 0.5 / scene.getHeight ()));
this->addUniform ("g_AudioSpectrum16Left", this->addUniform ("g_AudioSpectrum16Left", recorder.audio16, 16);
this->getMaterial ()->getImage ()->getScene ()->getAudioContext ().getRecorder ().audio16, 16); this->addUniform ("g_AudioSpectrum16Right", recorder.audio16, 16);
this->addUniform ("g_AudioSpectrum16Right", this->addUniform ("g_AudioSpectrum32Left", recorder.audio32, 32);
this->getMaterial ()->getImage ()->getScene ()->getAudioContext ().getRecorder ().audio16, 16); this->addUniform ("g_AudioSpectrum32Right", recorder.audio32, 32);
this->addUniform ("g_AudioSpectrum32Left", this->addUniform ("g_AudioSpectrum64Left", recorder.audio64, 64);
this->getMaterial ()->getImage ()->getScene ()->getAudioContext ().getRecorder ().audio32, 32); this->addUniform ("g_AudioSpectrum64Right", recorder.audio64, 64);
this->addUniform ("g_AudioSpectrum32Right",
this->getMaterial ()->getImage ()->getScene ()->getAudioContext ().getRecorder ().audio32, 32);
this->addUniform ("g_AudioSpectrum64Left",
this->getMaterial ()->getImage ()->getScene ()->getAudioContext ().getRecorder ().audio64, 64);
this->addUniform ("g_AudioSpectrum64Right",
this->getMaterial ()->getImage ()->getScene ()->getAudioContext ().getRecorder ().audio64, 64);
} }
void CPass::addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value) { void CPass::addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value) {
@ -680,7 +702,7 @@ void CPass::setupShaderVariables () {
this->addUniform (cur); this->addUniform (cur);
// find variables in the shaders and set the value with the constants if possible // find variables in the shaders and set the value with the constants if possible
for (const auto& [name, value] : this->m_pass->getConstants ()) { for (const auto& [name, value] : this->m_override.constants) {
const auto parameters = this->m_shader->findParameter (name); const auto parameters = this->m_shader->findParameter (name);
// variable not found, can be ignored // variable not found, can be ignored
@ -692,7 +714,7 @@ void CPass::setupShaderVariables () {
// this takes care of all possible casts, even invalid ones, which will use whatever default behaviour // this takes care of all possible casts, even invalid ones, which will use whatever default behaviour
// of the underlying CDynamicValue used for the value // of the underlying CDynamicValue used for the value
this->addUniform (var, value); this->addUniform (var, value.get ());
} }
} }

View File

@ -5,25 +5,31 @@
#include "WallpaperEngine/Assets/ITexture.h" #include "WallpaperEngine/Assets/ITexture.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h" #include "WallpaperEngine/Core/UserSettings/CUserSettingValue.h"
#include "WallpaperEngine/Render/CFBO.h" #include "WallpaperEngine/Render/CFBO.h"
#include "WallpaperEngine/Render/Objects/Effects/CMaterial.h" #include "WallpaperEngine/Render/CFBOProvider.h"
#include "WallpaperEngine/Render/Helpers/CContextAware.h"
#include "WallpaperEngine/Render/Shaders/CShader.h" #include "WallpaperEngine/Render/Shaders/CShader.h"
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingValue.h"
#include "WallpaperEngine/Render/Helpers/CContextAware.h" namespace WallpaperEngine::Render::Objects {
class CImage;
}
namespace WallpaperEngine::Render::Objects::Effects { namespace WallpaperEngine::Render::Objects::Effects {
using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Render::Shaders::Variables; using namespace WallpaperEngine::Render::Shaders::Variables;
using namespace WallpaperEngine::Core::Projects; using namespace WallpaperEngine::Core::Projects;
using namespace WallpaperEngine::Core::Objects::Effects::Constants; using namespace WallpaperEngine::Core::Objects::Effects::Constants;
using namespace WallpaperEngine::Data::Model;
class CMaterial;
class CPass final : public Helpers::CContextAware { class CPass final : public Helpers::CContextAware {
public: public:
CPass (CMaterial* material, const Core::Objects::Images::Materials::CPass* pass); CPass (
CImage& image, std::shared_ptr<const CFBOProvider> fboProvider, const MaterialPass& pass,
std::optional<std::reference_wrapper<const ImageEffectPassOverride>> override,
std::optional<std::reference_wrapper<const TextureMap>> binds,
std::optional<std::reference_wrapper<std::string>> target);
void render (); void render ();
@ -39,8 +45,10 @@ class CPass final : public Helpers::CContextAware {
[[nodiscard]] const std::string& getBlendingMode () const; [[nodiscard]] const std::string& getBlendingMode () const;
[[nodiscard]] std::shared_ptr<const CFBO> resolveFBO (const std::string& name) const; [[nodiscard]] std::shared_ptr<const CFBO> resolveFBO (const std::string& name) const;
[[nodiscard]] const CMaterial* getMaterial () const; [[nodiscard]] std::shared_ptr<const CFBOProvider> getFBOProvider () const;
[[nodiscard]] const Core::Objects::Images::Materials::CPass* getPass () const; [[nodiscard]] const CImage& getImage () const;
[[nodiscard]] const MaterialPass& getPass () const;
[[nodiscard]] const std::optional<std::reference_wrapper<std::string>> getTarget () const;
[[nodiscard]] Render::Shaders::CShader* getShader () const; [[nodiscard]] Render::Shaders::CShader* getShader () const;
private: private:
@ -148,8 +156,12 @@ class CPass final : public Helpers::CContextAware {
std::shared_ptr<const ITexture> resolveTexture (std::shared_ptr<const ITexture> expected, int index, std::shared_ptr<const ITexture> previous = nullptr); std::shared_ptr<const ITexture> resolveTexture (std::shared_ptr<const ITexture> expected, int index, std::shared_ptr<const ITexture> previous = nullptr);
CMaterial* m_material = nullptr; CImage& m_image;
const Core::Objects::Images::Materials::CPass* m_pass; std::shared_ptr<const CFBOProvider> m_fboProvider;
const MaterialPass& m_pass;
const TextureMap& m_binds;
const ImageEffectPassOverride& m_override;
std::optional<std::reference_wrapper<std::string>> m_target;
std::map<int, std::shared_ptr<const CFBO>> m_fbos = {}; std::map<int, std::shared_ptr<const CFBO>> m_fbos = {};
std::map<std::string, int> m_combos = {}; std::map<std::string, int> m_combos = {};
std::vector<AttribEntry*> m_attribs = {}; std::vector<AttribEntry*> m_attribs = {};

View File

@ -18,17 +18,18 @@ using namespace WallpaperEngine::Assets;
namespace WallpaperEngine::Render::Shaders { namespace WallpaperEngine::Render::Shaders {
CShader::CShader ( CShader::CShader (
std::shared_ptr<const CContainer> container, std::string filename, const std::map<std::string, int>& combos, const CContainer& container, std::string filename,
const std::map<int, std::string>& textures, const std::map<std::string, const CShaderConstant*>& constants const ComboMap& combos, const TextureMap& textures,
const ShaderConstantMap& constants
) : ) :
m_file (std::move (filename)), m_file (std::move (filename)),
m_combos (combos), m_combos (combos),
m_passTextures (textures), m_passTextures (textures),
m_vertex ( m_vertex (
CGLSLContext::UnitType_Vertex, filename, container->readVertexShader (filename), CGLSLContext::UnitType_Vertex, filename, container.readVertexShader (filename),
container, constants, textures, combos), container, constants, textures, combos),
m_fragment ( m_fragment (
CGLSLContext::UnitType_Fragment, filename, container->readFragmentShader (filename), CGLSLContext::UnitType_Fragment, filename, container.readFragmentShader (filename),
container, constants, textures, combos) { container, constants, textures, combos) {
// link shaders between them // link shaders between them
this->m_vertex.linkToUnit (&this->m_fragment); this->m_vertex.linkToUnit (&this->m_fragment);

View File

@ -13,10 +13,13 @@
#include "CShaderUnit.h" #include "CShaderUnit.h"
#include "CGLSLContext.h" #include "CGLSLContext.h"
#include "WallpaperEngine/Data/Model/Types.h"
namespace WallpaperEngine::Render::Shaders { namespace WallpaperEngine::Render::Shaders {
using json = nlohmann::json; using json = nlohmann::json;
using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Core::Objects::Effects::Constants; using namespace WallpaperEngine::Core::Objects::Effects::Constants;
using namespace WallpaperEngine::Data::Model;
/** /**
* A basic shader loader that adds basic function definitions to every loaded shader * A basic shader loader that adds basic function definitions to every loaded shader
@ -42,9 +45,9 @@ class CShader {
* @param recursive Whether the compiler should add base definitions or not * @param recursive Whether the compiler should add base definitions or not
*/ */
CShader ( CShader (
std::shared_ptr<const CContainer> container, std::string filename, const CContainer& container, std::string filename,
const std::map<std::string, int>& combos, const std::map<int, std::string>& textures, const ComboMap& combos, const TextureMap& textures,
const std::map<std::string, const CShaderConstant*>& constants); const ShaderConstantMap& constants);
/** /**
* @return The vertex's shader coude for OpenGL to use * @return The vertex's shader coude for OpenGL to use
*/ */
@ -93,10 +96,10 @@ class CShader {
/** /**
* The combos the shader should be generated with * The combos the shader should be generated with
*/ */
const std::map<std::string, int>& m_combos; const ComboMap& m_combos;
/** /**
* The list of textures the pass knows about * The list of textures the pass knows about
*/ */
const std::map<int, std::string> m_passTextures; const TextureMap m_passTextures;
}; };
} // namespace WallpaperEngine::Render::Shaders } // namespace WallpaperEngine::Render::Shaders

View File

@ -56,13 +56,12 @@ using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Render::Shaders; using namespace WallpaperEngine::Render::Shaders;
CShaderUnit::CShaderUnit ( CShaderUnit::CShaderUnit (
CGLSLContext::UnitType type, std::string file, std::string content, std::shared_ptr<const CContainer> container, CGLSLContext::UnitType type, std::string file, std::string content, const CContainer& container,
const std::map<std::string, const CShaderConstant*>& constants, const std::map<int, std::string>& passTextures, const ShaderConstantMap& constants, const TextureMap& passTextures, const ComboMap& combos
const std::map<std::string, int>& combos
) : ) :
m_type (type), m_type (type),
m_link (nullptr), m_link (nullptr),
m_container (std::move(container)), m_container (container),
m_file (std::move (file)), m_file (std::move (file)),
m_constants (constants), m_constants (constants),
m_content (std::move(content)), m_content (std::move(content)),
@ -155,7 +154,7 @@ void CShaderUnit::preprocessIncludes () {
content += "// begin of include from file "; content += "// begin of include from file ";
content += filename; content += filename;
content += "\n"; content += "\n";
content += this->m_container->readIncludeShader (filename); content += this->m_container.readIncludeShader (filename);
content += "\n// end of included from file "; content += "\n// end of included from file ";
content += filename; content += filename;
content += "\n"; content += "\n";
@ -194,7 +193,7 @@ void CShaderUnit::preprocessIncludes () {
content = "// begin of include from file "; content = "// begin of include from file ";
content += filename; content += filename;
content += "\n"; content += "\n";
content += this->m_container->readIncludeShader (filename); content += this->m_container.readIncludeShader (filename);
content += "\n// end of included from file "; content += "\n// end of included from file ";
content += filename; content += filename;
content += "\n"; content += "\n";
@ -382,6 +381,7 @@ void CShaderUnit::parseParameterConfiguration (
// TODO: SUPPORT VALUES FOR ALL THESE TYPES // TODO: SUPPORT VALUES FOR ALL THESE TYPES
// TODO: MAYBE EVEN CONNECT THESE TO THE CORRESPONDING PROPERTY SO THINGS ARE UPDATED AS THE ORIGIN VALUES CHANGE? // TODO: MAYBE EVEN CONNECT THESE TO THE CORRESPONDING PROPERTY SO THINGS ARE UPDATED AS THE ORIGIN VALUES CHANGE?
// TODO: MAKE USE OF PARSERS INSTEAD OF CORE
if (type == "vec4") { if (type == "vec4") {
parameter = new Variables::CShaderVariableVector4 (WallpaperEngine::Core::aToVector4 (*defvalue)); parameter = new Variables::CShaderVariableVector4 (WallpaperEngine::Core::aToVector4 (*defvalue));
} else if (type == "vec3") { } else if (type == "vec3") {
@ -500,11 +500,11 @@ void CShaderUnit::parseParameterConfiguration (
} }
} }
const std::map<std::string, int>& CShaderUnit::getCombos () const { const ComboMap& CShaderUnit::getCombos () const {
return this->m_combos; return this->m_combos;
} }
const std::map<std::string, int>& CShaderUnit::getDiscoveredCombos () const { const ComboMap& CShaderUnit::getDiscoveredCombos () const {
return this->m_discoveredCombos; return this->m_discoveredCombos;
} }
@ -565,6 +565,6 @@ const std::string& CShaderUnit::compile () {
const std::vector<Variables::CShaderVariable*>& CShaderUnit::getParameters () const { const std::vector<Variables::CShaderVariable*>& CShaderUnit::getParameters () const {
return this->m_parameters; return this->m_parameters;
} }
const std::map<int, std::string>& CShaderUnit::getTextures () const { const TextureMap& CShaderUnit::getTextures () const {
return this->m_defaultTextures; return this->m_defaultTextures;
} }

View File

@ -11,19 +11,23 @@
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
#include "WallpaperEngine/Data/Model/Types.h"
namespace WallpaperEngine::Render::Shaders { namespace WallpaperEngine::Render::Shaders {
using json = nlohmann::json; using json = nlohmann::json;
using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Core::Objects::Effects::Constants; using namespace WallpaperEngine::Core::Objects::Effects::Constants;
using namespace WallpaperEngine::Data::Model;
/** /**
* Represents a whole shader unit * Represents a whole shader unit
*/ */
class CShaderUnit { class CShaderUnit {
public: public:
CShaderUnit ( CShaderUnit (
CGLSLContext::UnitType type, std::string file, std::string content, std::shared_ptr<const CContainer> container, CGLSLContext::UnitType type, std::string file, std::string content, const CContainer& container,
const std::map<std::string, const CShaderConstant*>& constants, const std::map<int, std::string>& passTextures, const ShaderConstantMap& constants, const TextureMap& passTextures,
const std::map<std::string, int>& combos); const ComboMap& combos);
~CShaderUnit () = default; ~CShaderUnit () = default;
/** /**
@ -49,15 +53,15 @@ class CShaderUnit {
/** /**
* @return The textures this shader unit requires * @return The textures this shader unit requires
*/ */
[[nodiscard]] const std::map<int, std::string>& getTextures () const; [[nodiscard]] const TextureMap& getTextures () const;
/** /**
* @return The combos set for this shader unit by the configuration * @return The combos set for this shader unit by the configuration
*/ */
[[nodiscard]] const std::map<std::string, int>& getCombos () const; [[nodiscard]] const ComboMap& getCombos () const;
/** /**
* @return Other combos detected by this shader unit during the preprocess * @return Other combos detected by this shader unit during the preprocess
*/ */
[[nodiscard]] const std::map<std::string, int>& getDiscoveredCombos () const; [[nodiscard]] const ComboMap& getDiscoveredCombos () const;
protected: protected:
/** /**
@ -127,11 +131,11 @@ class CShaderUnit {
/** /**
* Pre-defined values for the combos * Pre-defined values for the combos
*/ */
const std::map<std::string, int>& m_combos; const ComboMap& m_combos;
/** /**
* The combos discovered in the pre-processing step that were not in the combos list * The combos discovered in the pre-processing step that were not in the combos list
*/ */
std::map<std::string, int> m_discoveredCombos = {}; ComboMap m_discoveredCombos = {};
/** /**
* The combos used by this unit that should be added * The combos used by this unit that should be added
*/ */
@ -139,11 +143,11 @@ class CShaderUnit {
/** /**
* The constants defined for this unit * The constants defined for this unit
*/ */
const std::map<std::string, const CShaderConstant*>& m_constants; const ShaderConstantMap& m_constants;
/** The textures that are already applied to this shader */ /** The textures that are already applied to this shader */
const std::map<int, std::string> m_passTextures; const TextureMap m_passTextures = {};
/** The default textures to use when a texture is not applied in a given slot */ /** The default textures to use when a texture is not applied in a given slot */
std::map<int, std::string> m_defaultTextures = {}; TextureMap m_defaultTextures = {};
/** /**
* The shader unit this unit is linked to * The shader unit this unit is linked to
*/ */
@ -151,6 +155,6 @@ class CShaderUnit {
/** /**
* The container to source files from * The container to source files from
*/ */
const std::shared_ptr<const CContainer> m_container; const CContainer& m_container;
}; };
} }

View File

@ -1,6 +1,3 @@
#include "WallpaperEngine/Core/Objects/CImage.h"
#include "WallpaperEngine/Core/Objects/CSound.h"
#include "WallpaperEngine/Render/Objects/CImage.h" #include "WallpaperEngine/Render/Objects/CImage.h"
#include "WallpaperEngine/Render/Objects/CSound.h" #include "WallpaperEngine/Render/Objects/CSound.h"
@ -9,58 +6,59 @@
#include "CScene.h" #include "CScene.h"
#include "WallpaperEngine/Logging/CLog.h" #include "WallpaperEngine/Logging/CLog.h"
#include "WallpaperEngine/Data/Model/Wallpaper.h"
#include "WallpaperEngine/Data/Parsers/ObjectParser.h"
extern float g_Time; extern float g_Time;
extern float g_TimeLast; extern float g_TimeLast;
using namespace WallpaperEngine; using namespace WallpaperEngine;
using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Data::Model;
using namespace WallpaperEngine::Data::Parsers;
using namespace WallpaperEngine::Render::Wallpapers; using namespace WallpaperEngine::Render::Wallpapers;
CScene::CScene ( CScene::CScene (
std::shared_ptr<const Core::CWallpaper> wallpaper, CRenderContext& context, CAudioContext& audioContext, const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode
) : ) :
CWallpaper (wallpaper, context, audioContext, scalingMode, clampMode) { CWallpaper (wallpaper, context, audioContext, scalingMode, clampMode) {
// caller should check this, if not a std::bad_cast is good to throw // caller should check this, if not a std::bad_cast is good to throw
const auto& scene = wallpaper->as <Core::Wallpapers::CScene> (); auto scene = wallpaper.as <Scene> ();
// setup the scene camera // setup the scene camera
this->m_camera = new CCamera (this, scene->getCamera ()); this->m_camera = std::make_unique<CCamera> (*this, scene->camera);
float width = scene->camera.projection.width;
float height = scene->camera.projection.height;
// detect size if the orthogonal project is auto // detect size if the orthogonal project is auto
if (scene->getOrthogonalProjection ()->isAuto ()) { if (scene->camera.projection.isAuto) {
// calculate the size of the projection based on the size of everything // TODO: CALCULATE ORTHOGONAL PROJECTION BASED ON CONTENT'S SIZE HERE
for (const auto& [id, sceneObject] : scene->getObjects ()) {
if (!sceneObject->is<Core::Objects::CImage> ())
continue;
const glm::vec2 size = sceneObject->as<Core::Objects::CImage> ()->getSize ();
scene->getOrthogonalProjection ()->setWidth (size.x);
scene->getOrthogonalProjection ()->setHeight (size.y);
}
} }
this->m_parallaxDisplacement = {0, 0}; this->m_parallaxDisplacement = {0, 0};
this->m_camera->setOrthogonalProjection (scene->getOrthogonalProjection ()->getWidth (), // TODO: CONVERSION
scene->getOrthogonalProjection ()->getHeight ()); this->m_camera->setOrthogonalProjection (width, height);
// setup framebuffers here as they're required for the scene setup // setup framebuffers here as they're required for the scene setup
this->setupFramebuffers (); this->setupFramebuffers ();
// set clear color // set clear color
const glm::vec3 clearColor = this->getScene ()->getClearColor (); // TODO: MAKE USE OF THE REFERENCE POSSIBILITIES?!
const glm::vec3 clearColor = scene->colors.clear->value->getVec3 ();
glClearColor (clearColor.r, clearColor.g, clearColor.b, 1.0f); glClearColor (clearColor.r, clearColor.g, clearColor.b, 1.0f);
// create all objects based off their dependencies // create all objects based off their dependencies
for (const auto& [id, sceneObject] : scene->getObjects ()) for (const auto& object : scene->objects)
this->createObject (sceneObject); this->createObject (*object);
// copy over objects by render order // copy over objects by render order
for (const auto& cur : scene->getObjectsByRenderOrder ()) { for (const auto& cur : scene->objects) {
auto obj = this->m_objects.find (cur->getId ()); auto obj = this->m_objects.find (cur->id);
// ignores not created objects like particle systems // ignores not created objects like particle systems
if (obj == this->m_objects.end ()) if (obj == this->m_objects.end ())
@ -69,18 +67,18 @@ CScene::CScene (
this->m_objectsByRenderOrder.emplace_back (obj->second); this->m_objectsByRenderOrder.emplace_back (obj->second);
} }
const uint32_t sceneWidth = scene->getOrthogonalProjection ()->getWidth (); const uint32_t sceneWidth = this->m_camera->getWidth ();
const uint32_t sceneHeight = scene->getOrthogonalProjection ()->getHeight (); const uint32_t sceneHeight = this->m_camera->getHeight ();
// create extra framebuffers for the bloom effect // create extra framebuffers for the bloom effect
this->_rt_4FrameBuffer = this->_rt_4FrameBuffer =
this->createFBO ("_rt_4FrameBuffer", ITexture::TextureFormat::ARGB8888, ITexture::TextureFlags::ClampUVs, 1.0, this->create ("_rt_4FrameBuffer", ITexture::TextureFormat::ARGB8888, ITexture::TextureFlags::ClampUVs, 1.0,
sceneWidth / 4, sceneHeight / 4, sceneWidth / 4, sceneHeight / 4); {sceneWidth / 4, sceneHeight / 4}, {sceneWidth / 4, sceneHeight / 4});
this->_rt_8FrameBuffer = this->_rt_8FrameBuffer =
this->createFBO ("_rt_8FrameBuffer", ITexture::TextureFormat::ARGB8888, ITexture::TextureFlags::ClampUVs, 1.0, this->create ("_rt_8FrameBuffer", ITexture::TextureFormat::ARGB8888, ITexture::TextureFlags::ClampUVs, 1.0,
sceneWidth / 8, sceneHeight / 8, sceneWidth / 8, sceneHeight / 8); {sceneWidth / 8, sceneHeight / 8}, {sceneWidth / 8, sceneHeight / 8});
this->_rt_Bloom = this->createFBO ("_rt_Bloom", ITexture::TextureFormat::ARGB8888, ITexture::TextureFlags::ClampUVs, this->_rt_Bloom = this->create ("_rt_Bloom", ITexture::TextureFormat::ARGB8888, ITexture::TextureFlags::ClampUVs,
1.0, sceneWidth / 8, sceneHeight / 8, sceneWidth / 8, sceneHeight / 8); 1.0, {sceneWidth / 8, sceneHeight / 8}, {sceneWidth / 8, sceneHeight / 8});
// //
// Had to get a little creative with the effects to achieve the same bloom effect without any custom code // Had to get a little creative with the effects to achieve the same bloom effect without any custom code
@ -89,6 +87,7 @@ CScene::CScene (
// (it renders directly to the screen, whereas here we never do that from a scene) // (it renders directly to the screen, whereas here we never do that from a scene)
// //
// TODO: TAKE THIS OUT OF HERE AND INTO THE GENERAL WALLPAPER APPLICATION?!
const std::string imagejson = "{" const std::string imagejson = "{"
"\t\"image\": \"models/wpenginelinux.json\"," "\t\"image\": \"models/wpenginelinux.json\","
"\t\"name\": \"bloomimagewpenginelinux\"," "\t\"name\": \"bloomimagewpenginelinux\","
@ -112,30 +111,30 @@ CScene::CScene (
"\t\t\t\t\t\"constantshadervalues\":" "\t\t\t\t\t\"constantshadervalues\":"
"\t\t\t\t\t{" "\t\t\t\t\t{"
"\t\t\t\t\t\t\"bloomstrength\": " + "\t\t\t\t\t\t\"bloomstrength\": " +
std::to_string (this->getScene ()->getBloomStrength ()) + std::to_string (this->getScene ().camera.bloom.strength->value->getFloat ()) +
"," ","
"\t\t\t\t\t\t\"bloomthreshold\": " + "\t\t\t\t\t\t\"bloomthreshold\": " +
std::to_string (this->getScene ()->getBloomThreshold ()) + std::to_string (this->getScene ().camera.bloom.threshold->value->getFloat ()) +
"\t\t\t\t\t}" "\t\t\t\t\t}"
"\t\t\t\t}," "\t\t\t\t},"
"\t\t\t\t{" "\t\t\t\t{"
"\t\t\t\t\t\"constantshadervalues\":" "\t\t\t\t\t\"constantshadervalues\":"
"\t\t\t\t\t{" "\t\t\t\t\t{"
"\t\t\t\t\t\t\"bloomstrength\": " + "\t\t\t\t\t\t\"bloomstrength\": " +
std::to_string (this->getScene ()->getBloomStrength ()) + std::to_string (this->getScene ().camera.bloom.strength->value->getFloat ()) +
"," ","
"\t\t\t\t\t\t\"bloomthreshold\": " + "\t\t\t\t\t\t\"bloomthreshold\": " +
std::to_string (this->getScene ()->getBloomThreshold ()) + std::to_string (this->getScene ().camera.bloom.threshold->value->getFloat ()) +
"\t\t\t\t\t}" "\t\t\t\t\t}"
"\t\t\t\t}," "\t\t\t\t},"
"\t\t\t\t{" "\t\t\t\t{"
"\t\t\t\t\t\"constantshadervalues\":" "\t\t\t\t\t\"constantshadervalues\":"
"\t\t\t\t\t{" "\t\t\t\t\t{"
"\t\t\t\t\t\t\"bloomstrength\": " + "\t\t\t\t\t\t\"bloomstrength\": " +
std::to_string (this->getScene ()->getBloomStrength ()) + std::to_string (this->getScene ().camera.bloom.strength->value->getFloat ()) +
"," ","
"\t\t\t\t\t\t\"bloomthreshold\": " + "\t\t\t\t\t\t\"bloomthreshold\": " +
std::to_string (this->getScene ()->getBloomThreshold ()) + std::to_string (this->getScene ().camera.bloom.strength->value->getFloat ()) +
"\t\t\t\t\t}" "\t\t\t\t\t}"
"\t\t\t\t}" "\t\t\t\t}"
"\t\t\t]" "\t\t\t]"
@ -148,48 +147,54 @@ CScene::CScene (
const auto json = nlohmann::json::parse (imagejson); const auto json = nlohmann::json::parse (imagejson);
// create image for bloom passes // create image for bloom passes
if (this->getScene ()->isBloom ()) { if (scene->camera.bloom.enabled->value->getBool ()) {
this->m_bloomObject = this->createObject ( this->m_bloomObjectData = ObjectParser::parse (json, scene->project);
WallpaperEngine::Core::CObject::fromJSON (json, scene->getProject (), this->getContainer ())); this->m_bloomObject = this->createObject (*this->m_bloomObjectData);
this->m_objectsByRenderOrder.push_back (this->m_bloomObject); this->m_objectsByRenderOrder.push_back (this->m_bloomObject);
} }
} }
Render::CObject* CScene::createObject (const Core::CObject* object) { Render::CObject* CScene::createObject (const Object& object) {
Render::CObject* renderObject = nullptr; Render::CObject* renderObject = nullptr;
// ensure the item is not loaded already // ensure the item is not loaded already
const auto current = this->m_objects.find (object->getId ()); const auto current = this->m_objects.find (object.id);
if (current != this->m_objects.end ()) if (current != this->m_objects.end ())
return current->second; return current->second;
// check dependencies too! // check dependencies too!
for (const auto& cur : object->getDependencies ()) { for (const auto& cur : object.dependencies) {
// self-dependency is a possibility... // self-dependency is a possibility...
if (cur == object->getId ()) if (cur == object.id)
continue; continue;
auto dep = this->getScene ()->getObjects ().find (cur); const auto dep = std::find_if (
this->getScene ().objects.begin (),
this->getScene ().objects.end (),
[&cur] (const auto& o) {
return o->id == cur;
}
);
if (dep != this->getScene ()->getObjects ().end ()) if (dep != this->getScene ().objects.end ())
this->createObject (dep->second); this->createObject (**dep);
} }
if (object->is<Core::Objects::CImage> ()) { if (object.is<Image> ()) {
auto* image = new Objects::CImage (this, object->as<Core::Objects::CImage> ()); auto* image = new Objects::CImage (*this, *object.as<Image> ());
try { try {
image->setup (); image->setup ();
} catch (std::runtime_error&) { } catch (std::runtime_error&) {
// this error message is already printed, so just show extra info about it // this error message is already printed, so just show extra info about it
sLog.error ("Cannot setup image ", image->getImage ()->getName ()); sLog.error ("Cannot setup image ", image->getImage ().name);
} }
renderObject = image; renderObject = image;
} else if (object->is<Core::Objects::CSound> ()) { } else if (object.is<Sound> ()) {
renderObject = new Objects::CSound (this, object->as<Core::Objects::CSound> ()); renderObject = new Objects::CSound (*this, *object.as<Sound> ());
} }
if (renderObject != nullptr) if (renderObject != nullptr)
@ -198,8 +203,8 @@ Render::CObject* CScene::createObject (const Core::CObject* object) {
return renderObject; return renderObject;
} }
CCamera* CScene::getCamera () const { CCamera& CScene::getCamera () const {
return this->m_camera; return *this->m_camera;
} }
void CScene::renderFrame (glm::ivec4 viewport) { void CScene::renderFrame (glm::ivec4 viewport) {
@ -207,11 +212,11 @@ void CScene::renderFrame (glm::ivec4 viewport) {
this->updateMouse (viewport); this->updateMouse (viewport);
// update the parallax position if required // update the parallax position if required
if (this->getScene ()->isCameraParallax () && !this->getContext ().getApp ().getContext ().settings.mouse.disableparallax) { if (this->getScene ().camera.parallax.enabled && !this->getContext ().getApp ().getContext ().settings.mouse.disableparallax) {
const float influence = this->getScene ()->getCameraParallaxMouseInfluence (); const float influence = this->getScene ().camera.parallax.mouseInfluence;
const float amount = this->getScene ()->getCameraParallaxAmount (); const float amount = this->getScene ().camera.parallax.amount;
const float delay = const float delay =
glm::min (static_cast<float> (this->getScene ()->getCameraParallaxDelay ()), g_Time - g_TimeLast); glm::min (static_cast<float> (this->getScene ().camera.parallax.delay), g_Time - g_TimeLast);
this->m_parallaxDisplacement = this->m_parallaxDisplacement =
glm::mix (this->m_parallaxDisplacement, (this->m_mousePosition * amount) * influence, delay); glm::mix (this->m_parallaxDisplacement, (this->m_mousePosition * amount) * influence, delay);
@ -243,27 +248,27 @@ void CScene::updateMouse (glm::ivec4 viewport) {
// screen-space positions have to be transposed to what the screen will actually show // screen-space positions have to be transposed to what the screen will actually show
} }
const Core::Wallpapers::CScene* CScene::getScene () const { const Scene& CScene::getScene () const {
return this->getWallpaperData ()->as<Core::Wallpapers::CScene> (); return *this->getWallpaperData ().as<Scene> ();
} }
int CScene::getWidth () const { int CScene::getWidth () const {
return this->getScene ()->getOrthogonalProjection ()->getWidth (); return this->m_camera->getWidth ();
} }
int CScene::getHeight () const { int CScene::getHeight () const {
return this->getScene ()->getOrthogonalProjection ()->getHeight (); return this->m_camera->getHeight ();
} }
glm::vec2* CScene::getMousePosition () { const glm::vec2* CScene::getMousePosition () const {
return &this->m_mousePosition; return &this->m_mousePosition;
} }
glm::vec2* CScene::getMousePositionLast () { const glm::vec2* CScene::getMousePositionLast () const {
return &this->m_mousePositionLast; return &this->m_mousePositionLast;
} }
glm::vec2* CScene::getParallaxDisplacement () { const glm::vec2* CScene::getParallaxDisplacement () const {
return &this->m_parallaxDisplacement; return &this->m_parallaxDisplacement;
} }

View File

@ -2,8 +2,6 @@
#include "WallpaperEngine/Render/CCamera.h" #include "WallpaperEngine/Render/CCamera.h"
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
#include "WallpaperEngine/Render/CWallpaper.h" #include "WallpaperEngine/Render/CWallpaper.h"
namespace WallpaperEngine::Render { namespace WallpaperEngine::Render {
@ -12,23 +10,25 @@ class CObject;
} }
namespace WallpaperEngine::Render::Wallpapers { namespace WallpaperEngine::Render::Wallpapers {
using namespace WallpaperEngine::Data::Model;
class CScene final : public CWallpaper { class CScene final : public CWallpaper {
public: public:
CScene ( CScene (
std::shared_ptr<const Core::CWallpaper> wallpaper, CRenderContext& context, CAudioContext& audioContext, const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode); const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode);
[[nodiscard]] CCamera* getCamera () const; [[nodiscard]] CCamera& getCamera () const;
[[nodiscard]] const Core::Wallpapers::CScene* getScene () const; [[nodiscard]] const Scene& getScene () const;
[[nodiscard]] int getWidth () const override; [[nodiscard]] int getWidth () const override;
[[nodiscard]] int getHeight () const override; [[nodiscard]] int getHeight () const override;
glm::vec2* getMousePosition (); const glm::vec2* getMousePosition () const;
glm::vec2* getMousePositionLast (); const glm::vec2* getMousePositionLast () const;
glm::vec2* getParallaxDisplacement (); const glm::vec2* getParallaxDisplacement () const;
[[nodiscard]] const std::vector<CObject*>& getObjectsByRenderOrder () const; [[nodiscard]] const std::vector<CObject*>& getObjectsByRenderOrder () const;
@ -39,9 +39,10 @@ class CScene final : public CWallpaper {
friend class CWallpaper; friend class CWallpaper;
private: private:
Render::CObject* createObject (const Core::CObject* object); Render::CObject* createObject (const Object& object);
CCamera* m_camera = nullptr; std::unique_ptr<CCamera> m_camera;
ObjectUniquePtr m_bloomObjectData;
CObject* m_bloomObject = nullptr; CObject* m_bloomObject = nullptr;
std::map<int, CObject*> m_objects = {}; std::map<int, CObject*> m_objects = {};
std::vector<CObject*> m_objectsByRenderOrder = {}; std::vector<CObject*> m_objectsByRenderOrder = {};

View File

@ -3,6 +3,9 @@
#include <GL/glew.h> #include <GL/glew.h>
#include "WallpaperEngine/Data/Model/Wallpaper.h"
#include "WallpaperEngine/Data/Model/Project.h"
using namespace WallpaperEngine; using namespace WallpaperEngine;
using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Render::Wallpapers; using namespace WallpaperEngine::Render::Wallpapers;
@ -12,7 +15,7 @@ void* get_proc_address (void* ctx, const char* name) {
} }
CVideo::CVideo ( CVideo::CVideo (
std::shared_ptr<const Core::CWallpaper> wallpaper, CRenderContext& context, CAudioContext& audioContext, const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode
) : ) :
@ -54,7 +57,7 @@ CVideo::CVideo (
sLog.exception ("Failed to initialize MPV's GL context"); sLog.exception ("Failed to initialize MPV's GL context");
const std::filesystem::path videopath = const std::filesystem::path videopath =
this->getVideo ()->getProject ()->getContainer ()->resolveRealFile (this->getVideo ()->getFilename ()); this->getVideo ().project.container->resolveRealFile (this->getVideo ().filename);
// build the path to the video file // build the path to the video file
const char* command [] = {"loadfile", videopath.c_str (), nullptr}; const char* command [] = {"loadfile", videopath.c_str (), nullptr};
@ -118,8 +121,8 @@ void CVideo::renderFrame (glm::ivec4 viewport) {
mpv_render_context_render (this->m_mpvGl, params); mpv_render_context_render (this->m_mpvGl, params);
} }
const Core::Wallpapers::CVideo* CVideo::getVideo () const { const Video& CVideo::getVideo () const {
return this->getWallpaperData ()->as<Core::Wallpapers::CVideo> (); return *this->getWallpaperData ().as<Video>();
} }
void CVideo::setPause (bool newState) { void CVideo::setPause (bool newState) {

View File

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "WallpaperEngine/Core/Wallpapers/CVideo.h"
#include "WallpaperEngine/Audio/CAudioStream.h" #include "WallpaperEngine/Audio/CAudioStream.h"
#include "WallpaperEngine/Render/CWallpaper.h" #include "WallpaperEngine/Render/CWallpaper.h"
#include <mpv/client.h> #include <mpv/client.h>
@ -11,11 +9,11 @@ namespace WallpaperEngine::Render::Wallpapers {
class CVideo final : public CWallpaper { class CVideo final : public CWallpaper {
public: public:
CVideo ( CVideo (
std::shared_ptr<const Core::CWallpaper> video, CRenderContext& context, CAudioContext& audioContext, const Wallpaper& video, CRenderContext& context, CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode); const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode);
const Core::Wallpapers::CVideo* getVideo () const; const Video& getVideo () const;
[[nodiscard]] int getWidth () const override; [[nodiscard]] int getWidth () const override;
[[nodiscard]] int getHeight () const override; [[nodiscard]] int getHeight () const override;

View File

@ -4,6 +4,9 @@
#include "CWeb.h" #include "CWeb.h"
#include "WallpaperEngine/WebBrowser/CEF/CWPSchemeHandlerFactory.h" #include "WallpaperEngine/WebBrowser/CEF/CWPSchemeHandlerFactory.h"
#include "WallpaperEngine/Data/Model/Wallpaper.h"
#include "WallpaperEngine/Data/Model/Project.h"
using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Render::Wallpapers; using namespace WallpaperEngine::Render::Wallpapers;
@ -11,7 +14,7 @@ using namespace WallpaperEngine::WebBrowser;
using namespace WallpaperEngine::WebBrowser::CEF; using namespace WallpaperEngine::WebBrowser::CEF;
CWeb::CWeb ( CWeb::CWeb (
std::shared_ptr<const Core::CWallpaper> wallpaper, CRenderContext& context, CAudioContext& audioContext, const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
CWebBrowserContext& browserContext, const CWallpaperState::TextureUVsScaling& scalingMode, CWebBrowserContext& browserContext, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode
) : ) :
@ -32,9 +35,9 @@ CWeb::CWeb (
this->m_client = new WebBrowser::CEF::CBrowserClient (m_renderHandler); this->m_client = new WebBrowser::CEF::CBrowserClient (m_renderHandler);
// use the custom scheme for the wallpaper's files // use the custom scheme for the wallpaper's files
const std::string htmlURL = const std::string htmlURL =
CWPSchemeHandlerFactory::generateSchemeName(this->getWeb ()->getProject ()->getWorkshopId ()) + CWPSchemeHandlerFactory::generateSchemeName(this->getWeb ().project.workshopId) +
"://root/" + "://root/" +
this->getWeb()->getFilename (); this->getWeb().filename;
this->m_browser = this->m_browser =
CefBrowserHost::CreateBrowserSync (window_info, this->m_client, htmlURL, browserSettings, nullptr, nullptr); CefBrowserHost::CreateBrowserSync (window_info, this->m_client, htmlURL, browserSettings, nullptr, nullptr);
} }

View File

@ -11,11 +11,12 @@
#include <algorithm> #include <algorithm>
#include "WallpaperEngine/Audio/CAudioStream.h" #include "WallpaperEngine/Audio/CAudioStream.h"
#include "WallpaperEngine/Core/Wallpapers/CWeb.h"
#include "WallpaperEngine/Render/CWallpaper.h" #include "WallpaperEngine/Render/CWallpaper.h"
#include "WallpaperEngine/WebBrowser/CEF/CBrowserClient.h" #include "WallpaperEngine/WebBrowser/CEF/CBrowserClient.h"
#include "WallpaperEngine/WebBrowser/CEF/CRenderHandler.h" #include "WallpaperEngine/WebBrowser/CEF/CRenderHandler.h"
#include "WallpaperEngine/Data/Model/Wallpaper.h"
namespace WallpaperEngine::WebBrowser::CEF { namespace WallpaperEngine::WebBrowser::CEF {
class CRenderHandler; class CRenderHandler;
} }
@ -25,7 +26,7 @@ class CWeb : public CWallpaper
{ {
public: public:
CWeb ( CWeb (
std::shared_ptr<const Core::CWallpaper> wallpaper, CRenderContext& context, CAudioContext& audioContext, const Wallpaper& wallpaper, CRenderContext& context, CAudioContext& audioContext,
WallpaperEngine::WebBrowser::CWebBrowserContext& browserContext, WallpaperEngine::WebBrowser::CWebBrowserContext& browserContext,
const CWallpaperState::TextureUVsScaling& scalingMode, const CWallpaperState::TextureUVsScaling& scalingMode,
const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode); const WallpaperEngine::Assets::ITexture::TextureFlags& clampMode);
@ -39,8 +40,8 @@ class CWeb : public CWallpaper
protected: protected:
void renderFrame (glm::ivec4 viewport) override; void renderFrame (glm::ivec4 viewport) override;
void updateMouse (glm::ivec4 viewport); void updateMouse (glm::ivec4 viewport);
const Core::Wallpapers::CWeb* getWeb () const { const Web& getWeb () const {
return this->getWallpaperData ()->as<Core::Wallpapers::CWeb> (); return *this->getWallpaperData ().as<Web> ();
} }
friend class CWallpaper; friend class CWallpaper;

View File

@ -1,12 +1,13 @@
#include "CSubprocessApp.h" #include "CSubprocessApp.h"
#include "CWPSchemeHandlerFactory.h" #include "CWPSchemeHandlerFactory.h"
#include "WallpaperEngine/Data/Model/Project.h"
using namespace WallpaperEngine::WebBrowser::CEF; using namespace WallpaperEngine::WebBrowser::CEF;
CSubprocessApp::CSubprocessApp (WallpaperEngine::Application::CWallpaperApplication& application) : CSubprocessApp::CSubprocessApp (WallpaperEngine::Application::CWallpaperApplication& application) :
m_application (application) { m_application (application) {
for (const auto& [_, info] : this->m_application.getBackgrounds()) { for (const auto& [_, info] : this->m_application.getBackgrounds()) {
this->m_handlerFactories [info->getWorkshopId ()] = new CWPSchemeHandlerFactory (info); this->m_handlerFactories [info->workshopId] = new CWPSchemeHandlerFactory (*info);
} }
} }

View File

@ -5,12 +5,14 @@
#include "MimeTypes.h" #include "MimeTypes.h"
#include "include/cef_parser.h" #include "include/cef_parser.h"
#include "WallpaperEngine/Data/Model/Project.h"
using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::WebBrowser::CEF; using namespace WallpaperEngine::WebBrowser::CEF;
CWPSchemeHandler::CWPSchemeHandler(std::shared_ptr<const Core::CProject> project) : CWPSchemeHandler::CWPSchemeHandler(const Project& project) :
m_project (project) { m_project (project),
this->m_container = this->m_project->getWallpaper ()->getProject ()->getContainer (); m_container (*this->m_project.container) {
} }
bool CWPSchemeHandler::Open(CefRefPtr<CefRequest> request, bool CWPSchemeHandler::Open(CefRefPtr<CefRequest> request,
@ -46,7 +48,7 @@ bool CWPSchemeHandler::Open(CefRefPtr<CefRequest> request,
this->m_mimeType = mime; this->m_mimeType = mime;
} }
this->m_contents = this->m_container->readFile (file, &this->m_filesize); this->m_contents = this->m_container.readFile (file, &this->m_filesize);
callback->Continue (); callback->Continue ();
} catch (CAssetLoadException&) { } catch (CAssetLoadException&) {
#if !NDEBUG #if !NDEBUG

View File

@ -2,7 +2,6 @@
#include <string> #include <string>
#include "WallpaperEngine/Core/CProject.h"
#include "include/cef_resource_handler.h" #include "include/cef_resource_handler.h"
#include "include/wrapper/cef_helpers.h" #include "include/wrapper/cef_helpers.h"
@ -10,13 +9,20 @@ namespace WallpaperEngine::Assets {
class CContainer; class CContainer;
} }
namespace WallpaperEngine::Data::Model {
class Project;
}
namespace WallpaperEngine::WebBrowser::CEF { namespace WallpaperEngine::WebBrowser::CEF {
using namespace WallpaperEngine::Data::Model;
/** /**
* wp{id}:// actual handler called by cef to access files * wp{id}:// actual handler called by cef to access files
*/ */
class CWPSchemeHandler : public CefResourceHandler { class CWPSchemeHandler : public CefResourceHandler {
public: public:
explicit CWPSchemeHandler(std::shared_ptr<const Core::CProject> project); explicit CWPSchemeHandler(const Project& project);
bool Open(CefRefPtr<CefRequest> request, bool Open(CefRefPtr<CefRequest> request,
bool& handle_request, bool& handle_request,
@ -32,9 +38,9 @@ class CWPSchemeHandler : public CefResourceHandler {
CefRefPtr<CefResourceReadCallback> callback) override; CefRefPtr<CefResourceReadCallback> callback) override;
private: private:
std::shared_ptr<const Core::CProject> m_project = nullptr; const Project& m_project;
std::shared_ptr<const Assets::CContainer> m_container = nullptr; const Assets::CContainer& m_container;
std::shared_ptr<const uint8_t[]> m_contents = nullptr; std::shared_ptr<const uint8_t[]> m_contents = nullptr;
uint32_t m_filesize = 0; uint32_t m_filesize = 0;
std::string m_mimeType = ""; std::string m_mimeType = "";

View File

@ -5,7 +5,7 @@
using namespace WallpaperEngine::WebBrowser::CEF; using namespace WallpaperEngine::WebBrowser::CEF;
CWPSchemeHandlerFactory::CWPSchemeHandlerFactory (const std::shared_ptr<const Core::CProject>& project) : CWPSchemeHandlerFactory::CWPSchemeHandlerFactory (const Project& project) :
m_project (project) {} m_project (project) {}
CefRefPtr<CefResourceHandler> CWPSchemeHandlerFactory::Create ( CefRefPtr<CefResourceHandler> CWPSchemeHandlerFactory::Create (

View File

@ -1,16 +1,21 @@
#pragma once #pragma once
#include <string> #include <string>
#include "WallpaperEngine/Core/CProject.h"
#include "include/cef_scheme.h" #include "include/cef_scheme.h"
namespace WallpaperEngine::Data::Model {
class Project;
}
namespace WallpaperEngine::WebBrowser::CEF { namespace WallpaperEngine::WebBrowser::CEF {
using namespace WallpaperEngine::Data::Model;
/** /**
* Simple factory that creates a scheme handler for wp when requested by Cef * Simple factory that creates a scheme handler for wp when requested by Cef
*/ */
class CWPSchemeHandlerFactory : public CefSchemeHandlerFactory { class CWPSchemeHandlerFactory : public CefSchemeHandlerFactory {
public: public:
explicit CWPSchemeHandlerFactory (const std::shared_ptr<const Core::CProject>& project); explicit CWPSchemeHandlerFactory (const Project& project);
CefRefPtr<CefResourceHandler> Create ( CefRefPtr<CefResourceHandler> Create (
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
@ -18,7 +23,7 @@ class CWPSchemeHandlerFactory : public CefSchemeHandlerFactory {
static std::string generateSchemeName (const std::string& workshopId); static std::string generateSchemeName (const std::string& workshopId);
private: private:
std::shared_ptr<const Core::CProject> m_project = nullptr; const Project& m_project;
IMPLEMENT_REFCOUNTING (CWPSchemeHandlerFactory); IMPLEMENT_REFCOUNTING (CWPSchemeHandlerFactory);
DISALLOW_COPY_AND_ASSIGN (CWPSchemeHandlerFactory); DISALLOW_COPY_AND_ASSIGN (CWPSchemeHandlerFactory);

Some files were not shown because too many files have changed in this diff Show More