forked from 0ad/0ad
Allow registering hooks that trigger on config changes.
Rendering options use this capability to simplify their implementation. This makes it easier to add new options. Comments by: vladislavbelov Differential Revision: https://code.wildfiregames.com/D2293 This was SVN commit r24228.
This commit is contained in:
parent
f6348b9617
commit
8a1b3d6769
@ -99,23 +99,20 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Prefer GLSL",
|
"label": "Prefer GLSL",
|
||||||
"tooltip": "Use OpenGL 2.0 shaders (recommended).",
|
"tooltip": "Use OpenGL 2.0 shaders (recommended).",
|
||||||
"config": "preferglsl",
|
"config": "preferglsl"
|
||||||
"function": "Renderer_SetPreferGLSLEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Fog",
|
"label": "Fog",
|
||||||
"tooltip": "Enable Fog.",
|
"tooltip": "Enable Fog.",
|
||||||
"dependencies": ["preferglsl"],
|
"dependencies": ["preferglsl"],
|
||||||
"config": "fog",
|
"config": "fog"
|
||||||
"function": "Renderer_SetFogEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Post-processing",
|
"label": "Post-processing",
|
||||||
"tooltip": "Use screen-space post-processing filters (HDR, Bloom, DOF, etc).",
|
"tooltip": "Use screen-space post-processing filters (HDR, Bloom, DOF, etc).",
|
||||||
"config": "postproc",
|
"config": "postproc"
|
||||||
"function": "Renderer_SetPostProcEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "dropdown",
|
"type": "dropdown",
|
||||||
@ -130,8 +127,7 @@
|
|||||||
{ "value": "msaa4", "label": "MSAA (x4)", "tooltip": "Slow, but high-quality anti-aliasing, uses 4 samples per pixel. Supported for GL3.3+." },
|
{ "value": "msaa4", "label": "MSAA (x4)", "tooltip": "Slow, but high-quality anti-aliasing, uses 4 samples per pixel. Supported for GL3.3+." },
|
||||||
{ "value": "msaa8", "label": "MSAA (x8)", "tooltip": "Slow, but high-quality anti-aliasing, uses 8 samples per pixel. Supported for GL3.3+." },
|
{ "value": "msaa8", "label": "MSAA (x8)", "tooltip": "Slow, but high-quality anti-aliasing, uses 8 samples per pixel. Supported for GL3.3+." },
|
||||||
{ "value": "msaa16", "label": "MSAA (x16)", "tooltip": "Slow, but high-quality anti-aliasing, uses 16 samples per pixel. Supported for GL3.3+." }
|
{ "value": "msaa16", "label": "MSAA (x16)", "tooltip": "Slow, but high-quality anti-aliasing, uses 16 samples per pixel. Supported for GL3.3+." }
|
||||||
],
|
]
|
||||||
"function": "Renderer_UpdateAntiAliasingTechnique"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "dropdown",
|
"type": "dropdown",
|
||||||
@ -142,8 +138,7 @@
|
|||||||
"list": [
|
"list": [
|
||||||
{ "value": "disabled", "label": "Disabled", "tooltip": "Do not use sharpening." },
|
{ "value": "disabled", "label": "Disabled", "tooltip": "Do not use sharpening." },
|
||||||
{ "value": "cas", "label": "FidelityFX CAS", "tooltip": "Contrast adaptive sharpening, a fast, contrast based sharpening pass." }
|
{ "value": "cas", "label": "FidelityFX CAS", "tooltip": "Contrast adaptive sharpening, a fast, contrast based sharpening pass." }
|
||||||
],
|
]
|
||||||
"function": "Renderer_UpdateSharpeningTechnique"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "slider",
|
"type": "slider",
|
||||||
@ -152,8 +147,7 @@
|
|||||||
"dependencies": ["postproc", "preferglsl"],
|
"dependencies": ["postproc", "preferglsl"],
|
||||||
"config": "sharpness",
|
"config": "sharpness",
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"max": 1,
|
"max": 1
|
||||||
"function": "Renderer_UpdateSharpnessFactor"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "slider",
|
"type": "slider",
|
||||||
@ -167,8 +161,7 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Shadows",
|
"label": "Shadows",
|
||||||
"tooltip": "Enable shadows.",
|
"tooltip": "Enable shadows.",
|
||||||
"config": "shadows",
|
"config": "shadows"
|
||||||
"function": "Renderer_SetShadowsEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "dropdown",
|
"type": "dropdown",
|
||||||
@ -176,7 +169,6 @@
|
|||||||
"tooltip": "Shadow map resolution. High values can crash the game when using a graphics card with low memory!",
|
"tooltip": "Shadow map resolution. High values can crash the game when using a graphics card with low memory!",
|
||||||
"dependencies": ["shadows"],
|
"dependencies": ["shadows"],
|
||||||
"config": "shadowquality",
|
"config": "shadowquality",
|
||||||
"function": "Renderer_RecreateShadowMap",
|
|
||||||
"list": [
|
"list": [
|
||||||
{ "value": -2, "label": "Very Low" },
|
{ "value": -2, "label": "Very Low" },
|
||||||
{ "value": -1, "label": "Low" },
|
{ "value": -1, "label": "Low" },
|
||||||
@ -190,83 +182,72 @@
|
|||||||
"label": "Shadow filtering",
|
"label": "Shadow filtering",
|
||||||
"tooltip": "Smooth shadows.",
|
"tooltip": "Smooth shadows.",
|
||||||
"dependencies": ["shadows"],
|
"dependencies": ["shadows"],
|
||||||
"config": "shadowpcf",
|
"config": "shadowpcf"
|
||||||
"function": "Renderer_SetShadowPCFEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Unit silhouettes",
|
"label": "Unit silhouettes",
|
||||||
"tooltip": "Show outlines of units behind structures.",
|
"tooltip": "Show outlines of units behind structures.",
|
||||||
"config": "silhouettes",
|
"config": "silhouettes"
|
||||||
"function": "Renderer_SetSilhouettesEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Particles",
|
"label": "Particles",
|
||||||
"tooltip": "Enable particles.",
|
"tooltip": "Enable particles.",
|
||||||
"config": "particles",
|
"config": "particles"
|
||||||
"function": "Renderer_SetParticlesEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Water effects",
|
"label": "Water effects",
|
||||||
"tooltip": "When OFF, use the lowest settings possible to render water. This makes other settings irrelevant.",
|
"tooltip": "When OFF, use the lowest settings possible to render water. This makes other settings irrelevant.",
|
||||||
"config": "watereffects",
|
"config": "watereffects"
|
||||||
"function": "Renderer_SetWaterEffectsEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "High-quality water effects",
|
"label": "High-quality water effects",
|
||||||
"tooltip": "Use higher-quality effects for water, rendering coastal waves, shore foam, and ships trails.",
|
"tooltip": "Use higher-quality effects for water, rendering coastal waves, shore foam, and ships trails.",
|
||||||
"dependencies": ["watereffects"],
|
"dependencies": ["watereffects"],
|
||||||
"config": "waterfancyeffects",
|
"config": "waterfancyeffects"
|
||||||
"function": "Renderer_SetWaterFancyEffectsEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Water reflections",
|
"label": "Water reflections",
|
||||||
"tooltip": "Allow water to reflect a mirror image.",
|
"tooltip": "Allow water to reflect a mirror image.",
|
||||||
"dependencies": ["watereffects"],
|
"dependencies": ["watereffects"],
|
||||||
"config": "waterreflection",
|
"config": "waterreflection"
|
||||||
"function": "Renderer_SetWaterReflectionEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Water refraction",
|
"label": "Water refraction",
|
||||||
"tooltip": "Use a real water refraction map and not transparency.",
|
"tooltip": "Use a real water refraction map and not transparency.",
|
||||||
"dependencies": ["watereffects"],
|
"dependencies": ["watereffects"],
|
||||||
"config": "waterrefraction",
|
"config": "waterrefraction"
|
||||||
"function": "Renderer_SetWaterRefractionEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Real water depth",
|
"label": "Real water depth",
|
||||||
"tooltip": "Use actual water depth in rendering calculations.",
|
"tooltip": "Use actual water depth in rendering calculations.",
|
||||||
"dependencies": ["watereffects", "waterrefraction"],
|
"dependencies": ["watereffects", "waterrefraction"],
|
||||||
"config": "waterrealdepth",
|
"config": "waterrealdepth"
|
||||||
"function": "Renderer_SetWaterRealDepthEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Shadows on water",
|
"label": "Shadows on water",
|
||||||
"tooltip": "Cast shadows on water.",
|
"tooltip": "Cast shadows on water.",
|
||||||
"dependencies": ["watereffects"],
|
"dependencies": ["watereffects"],
|
||||||
"config": "shadowsonwater",
|
"config": "shadowsonwater"
|
||||||
"function": "Renderer_SetWaterShadowsEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Smooth vision",
|
"label": "Smooth vision",
|
||||||
"tooltip": "Lift darkness and fog-of-war smoothly.",
|
"tooltip": "Lift darkness and fog-of-war smoothly.",
|
||||||
"config": "smoothlos",
|
"config": "smoothlos"
|
||||||
"function": "Renderer_SetSmoothLOSEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Show sky",
|
"label": "Show sky",
|
||||||
"tooltip": "Render Sky.",
|
"tooltip": "Render Sky.",
|
||||||
"config": "showsky",
|
"config": "showsky"
|
||||||
"function": "Renderer_SetShowSkyEnabled"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
@ -653,7 +653,7 @@ function updateCinemaPath()
|
|||||||
let isPlayingCinemaPath = GetSimState().cinemaPlaying && !g_Disconnected;
|
let isPlayingCinemaPath = GetSimState().cinemaPlaying && !g_Disconnected;
|
||||||
|
|
||||||
Engine.GetGUIObjectByName("session").hidden = !g_ShowGUI || isPlayingCinemaPath;
|
Engine.GetGUIObjectByName("session").hidden = !g_ShowGUI || isPlayingCinemaPath;
|
||||||
Engine.Renderer_SetSilhouettesEnabled(!isPlayingCinemaPath && Engine.ConfigDB_GetValue("user", "silhouettes") == "true");
|
Engine.ConfigDB_CreateValue("user", "silhouettes", !isPlayingCinemaPath && Engine.ConfigDB_GetValue("user", "silhouettes") == "true" ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use event subscription onSimulationUpdate, onEntitySelectionChange, onPlayerViewChange, ... instead
|
// TODO: Use event subscription onSimulationUpdate, onEntitySelectionChange, onPlayerViewChange, ... instead
|
||||||
|
@ -36,6 +36,13 @@ TConfigMap CConfigDB::m_Map[CFG_LAST];
|
|||||||
VfsPath CConfigDB::m_ConfigFile[CFG_LAST];
|
VfsPath CConfigDB::m_ConfigFile[CFG_LAST];
|
||||||
bool CConfigDB::m_HasChanges[CFG_LAST];
|
bool CConfigDB::m_HasChanges[CFG_LAST];
|
||||||
|
|
||||||
|
std::multimap<CStr, std::function<void()>> CConfigDB::m_Hooks;
|
||||||
|
|
||||||
|
void TriggerAllHooks(const std::multimap<CStr, std::function<void()>>& hooks, const CStr& name)
|
||||||
|
{
|
||||||
|
std::for_each(hooks.lower_bound(name), hooks.upper_bound(name), [](const std::pair<CStr, std::function<void()>>& hook) { hook.second(); });
|
||||||
|
}
|
||||||
|
|
||||||
static std::recursive_mutex cfgdb_mutex;
|
static std::recursive_mutex cfgdb_mutex;
|
||||||
|
|
||||||
// These entries will not be printed to logfiles, so that logfiles can be shared without leaking personal or sensitive data
|
// These entries will not be printed to logfiles, so that logfiles can be shared without leaking personal or sensitive data
|
||||||
@ -202,6 +209,8 @@ void CConfigDB::SetValueString(EConfigNamespace ns, const CStr& name, const CStr
|
|||||||
it = m_Map[ns].insert(m_Map[ns].begin(), make_pair(name, CConfigValueSet(1)));
|
it = m_Map[ns].insert(m_Map[ns].begin(), make_pair(name, CConfigValueSet(1)));
|
||||||
|
|
||||||
it->second[0] = value;
|
it->second[0] = value;
|
||||||
|
|
||||||
|
TriggerAllHooks(m_Hooks, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfigDB::SetValueBool(EConfigNamespace ns, const CStr& name, const bool value)
|
void CConfigDB::SetValueBool(EConfigNamespace ns, const CStr& name, const bool value)
|
||||||
@ -231,6 +240,8 @@ void CConfigDB::RemoveValue(EConfigNamespace ns, const CStr& name)
|
|||||||
if (it == m_Map[ns].end())
|
if (it == m_Map[ns].end())
|
||||||
return;
|
return;
|
||||||
m_Map[ns].erase(it);
|
m_Map[ns].erase(it);
|
||||||
|
|
||||||
|
TriggerAllHooks(m_Hooks, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfigDB::SetConfigFile(EConfigNamespace ns, const VfsPath& path)
|
void CConfigDB::SetConfigFile(EConfigNamespace ns, const VfsPath& path)
|
||||||
@ -464,4 +475,16 @@ bool CConfigDB::WriteValueToFile(EConfigNamespace ns, const CStr& name, const CS
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CConfigDB::hook_t CConfigDB::RegisterHookAndCall(const CStr& name, std::function<void()> hook)
|
||||||
|
{
|
||||||
|
hook();
|
||||||
|
return m_Hooks.emplace(name, hook);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CConfigDB::UnregisterHook(CConfigDB::hook_t&& hook)
|
||||||
|
{
|
||||||
|
if (hook.ptr != m_Hooks.end())
|
||||||
|
m_Hooks.erase(hook.ptr);
|
||||||
|
}
|
||||||
|
|
||||||
#undef CHECK_NS
|
#undef CHECK_NS
|
||||||
|
@ -51,7 +51,7 @@ enum EConfigNamespace
|
|||||||
CFG_LAST
|
CFG_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<CStr> CConfigValueSet;
|
using CConfigValueSet = std::vector<CStr>;
|
||||||
|
|
||||||
#define g_ConfigDB CConfigDB::GetSingleton()
|
#define g_ConfigDB CConfigDB::GetSingleton()
|
||||||
|
|
||||||
@ -167,8 +167,34 @@ public:
|
|||||||
|
|
||||||
bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value);
|
bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value);
|
||||||
|
|
||||||
|
|
||||||
|
// Opaque data type so that callers that hook into ConfigDB can delete their hooks.
|
||||||
|
class hook_t
|
||||||
|
{
|
||||||
|
friend class CConfigDB;
|
||||||
|
public:
|
||||||
|
// Point the moved-from hook to end, which is checked for in UnregisterHook,
|
||||||
|
// to avoid a double-erase error.
|
||||||
|
hook_t(hook_t&& h) { ptr = std::move(h.ptr); h.ptr = m_Hooks.end(); }
|
||||||
|
hook_t(const hook_t&) = delete;
|
||||||
|
private:
|
||||||
|
hook_t(std::multimap<CStr, std::function<void()>>::iterator p) : ptr(p) {};
|
||||||
|
|
||||||
|
std::multimap<CStr, std::function<void()>>::iterator ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a simple lambda that will be called anytime the value changes in any namespace
|
||||||
|
* This is simple on purpose, the hook is responsible for checking if it should do something.
|
||||||
|
* When RegisterHookAndCall is called, the hook is immediately triggered.
|
||||||
|
*/
|
||||||
|
hook_t RegisterHookAndCall(const CStr& name, std::function<void()> hook);
|
||||||
|
|
||||||
|
void UnregisterHook(hook_t&& hook);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::map<CStr, CConfigValueSet> m_Map[];
|
static std::map<CStr, CConfigValueSet> m_Map[];
|
||||||
|
static std::multimap<CStr, std::function<void()>> m_Hooks;
|
||||||
static VfsPath m_ConfigFile[];
|
static VfsPath m_ConfigFile[];
|
||||||
static bool m_HasChanges[];
|
static bool m_HasChanges[];
|
||||||
};
|
};
|
||||||
|
@ -304,7 +304,7 @@ protected:
|
|||||||
friend class ShaderInstancingModelRenderer;
|
friend class ShaderInstancingModelRenderer;
|
||||||
friend class TerrainRenderer;
|
friend class TerrainRenderer;
|
||||||
friend class WaterRenderer;
|
friend class WaterRenderer;
|
||||||
friend struct SRenderingOptions;
|
friend class CRenderingOptions;
|
||||||
|
|
||||||
//BEGIN: Implementation of SceneCollector
|
//BEGIN: Implementation of SceneCollector
|
||||||
void Submit(CPatch* patch);
|
void Submit(CPatch* patch);
|
||||||
|
@ -23,8 +23,20 @@
|
|||||||
#include "ps/ConfigDB.h"
|
#include "ps/ConfigDB.h"
|
||||||
#include "ps/CStr.h"
|
#include "ps/CStr.h"
|
||||||
#include "renderer/Renderer.h"
|
#include "renderer/Renderer.h"
|
||||||
|
#include "renderer/PostprocManager.h"
|
||||||
|
#include "renderer/ShadowMap.h"
|
||||||
|
|
||||||
SRenderingOptions g_RenderingOptions;
|
CRenderingOptions g_RenderingOptions;
|
||||||
|
|
||||||
|
class CRenderingOptions::ConfigHooks
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::vector<CConfigDB::hook_t>::iterator begin() { return hooks.begin(); }
|
||||||
|
std::vector<CConfigDB::hook_t>::iterator end() { return hooks.end(); }
|
||||||
|
void insert(CConfigDB::hook_t&& hook) { return hooks.emplace_back(std::move(hook)); }
|
||||||
|
private:
|
||||||
|
std::vector<CConfigDB::hook_t> hooks;
|
||||||
|
};
|
||||||
|
|
||||||
RenderPath RenderPathEnum::FromString(const CStr8& name)
|
RenderPath RenderPathEnum::FromString(const CStr8& name)
|
||||||
{
|
{
|
||||||
@ -53,7 +65,7 @@ CStr8 RenderPathEnum::ToString(RenderPath path)
|
|||||||
return "default"; // Silence warning about reaching end of non-void function.
|
return "default"; // Silence warning about reaching end of non-void function.
|
||||||
}
|
}
|
||||||
|
|
||||||
SRenderingOptions::SRenderingOptions()
|
CRenderingOptions::CRenderingOptions() : m_ConfigHooks(new ConfigHooks())
|
||||||
{
|
{
|
||||||
m_NoVBO = false;
|
m_NoVBO = false;
|
||||||
m_RenderPath = RenderPath::DEFAULT;
|
m_RenderPath = RenderPath::DEFAULT;
|
||||||
@ -81,64 +93,121 @@ SRenderingOptions::SRenderingOptions()
|
|||||||
m_RenderActors = true;
|
m_RenderActors = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SRenderingOptions::ReadConfig()
|
CRenderingOptions::~CRenderingOptions()
|
||||||
{
|
{
|
||||||
CFG_GET_VAL("shadows", m_Shadows);
|
// This is currently irrelevant since CConfigDB is deleted before CRenderingOptions
|
||||||
CFG_GET_VAL("shadowpcf", m_ShadowPCF);
|
// (as only the latter is a static variable), but the check is a good idea regardless.
|
||||||
|
if (!CConfigDB::IsInitialised())
|
||||||
CFG_GET_VAL("preferglsl", m_PreferGLSL);
|
return;
|
||||||
CFG_GET_VAL("postproc", m_PostProc);
|
for (CConfigDB::hook_t& hook : *m_ConfigHooks)
|
||||||
CFG_GET_VAL("smoothlos", m_SmoothLOS);
|
g_ConfigDB.UnregisterHook(std::move(hook));
|
||||||
|
|
||||||
CStr renderPath;
|
|
||||||
CFG_GET_VAL("renderpath", renderPath);
|
|
||||||
SetRenderPath(RenderPathEnum::FromString(renderPath));
|
|
||||||
|
|
||||||
CFG_GET_VAL("watereffects", m_WaterEffects);
|
|
||||||
CFG_GET_VAL("waterfancyeffects", m_WaterFancyEffects);
|
|
||||||
CFG_GET_VAL("waterrealdepth", m_WaterRealDepth);
|
|
||||||
CFG_GET_VAL("waterrefraction", m_WaterRefraction);
|
|
||||||
CFG_GET_VAL("waterreflection", m_WaterReflection);
|
|
||||||
CFG_GET_VAL("watershadows", m_WaterShadows);
|
|
||||||
|
|
||||||
CFG_GET_VAL("particles", m_Particles);
|
|
||||||
CFG_GET_VAL("fog", m_Fog);
|
|
||||||
CFG_GET_VAL("silhouettes", m_Silhouettes);
|
|
||||||
CFG_GET_VAL("showsky", m_ShowSky);
|
|
||||||
|
|
||||||
CFG_GET_VAL("novbo", m_NoVBO);
|
|
||||||
|
|
||||||
CFG_GET_VAL("forcealphatest", m_ForceAlphaTest);
|
|
||||||
CFG_GET_VAL("gpuskinning", m_GPUSkinning);
|
|
||||||
|
|
||||||
CFG_GET_VAL("renderactors", m_RenderActors);
|
|
||||||
|
|
||||||
if (m_GPUSkinning && !m_PreferGLSL)
|
|
||||||
{
|
|
||||||
LOGWARNING("GPUSkinning have been disabled, because it is not supported with PreferGLSL disabled.");
|
|
||||||
m_GPUSkinning = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SRenderingOptions::SetShadows(bool value)
|
template<typename T>
|
||||||
|
void CRenderingOptions::SetupConfig(CStr8 name, T& variable)
|
||||||
|
{
|
||||||
|
m_ConfigHooks->insert(g_ConfigDB.RegisterHookAndCall(name, [name, &variable]() { CFG_GET_VAL(name, variable); }));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRenderingOptions::SetupConfig(CStr8 name, std::function<void()> hook)
|
||||||
|
{
|
||||||
|
m_ConfigHooks->insert(g_ConfigDB.RegisterHookAndCall(name, hook));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRenderingOptions::ReadConfig()
|
||||||
|
{
|
||||||
|
SetupConfig("preferglsl", [this]() {
|
||||||
|
bool enabled;
|
||||||
|
CFG_GET_VAL("preferglsl", enabled);
|
||||||
|
SetPreferGLSL(enabled);
|
||||||
|
});
|
||||||
|
|
||||||
|
SetupConfig("shadowquality", []() {
|
||||||
|
g_Renderer.GetShadowMap().RecreateTexture();
|
||||||
|
});
|
||||||
|
|
||||||
|
SetupConfig("shadows", [this]() {
|
||||||
|
bool enabled;
|
||||||
|
CFG_GET_VAL("shadows", enabled);
|
||||||
|
SetShadows(enabled);
|
||||||
|
});
|
||||||
|
SetupConfig("shadowpcf", [this]() {
|
||||||
|
bool enabled;
|
||||||
|
CFG_GET_VAL("shadowpcf", enabled);
|
||||||
|
SetShadowPCF(enabled);
|
||||||
|
});
|
||||||
|
|
||||||
|
SetupConfig("antialiasing", []() {
|
||||||
|
g_Renderer.GetPostprocManager().UpdateAntiAliasingTechnique();
|
||||||
|
});
|
||||||
|
|
||||||
|
SetupConfig("sharpness", []() {
|
||||||
|
g_Renderer.GetPostprocManager().UpdateSharpnessFactor();
|
||||||
|
});
|
||||||
|
|
||||||
|
SetupConfig("sharpening", []() {
|
||||||
|
g_Renderer.GetPostprocManager().UpdateSharpeningTechnique();
|
||||||
|
});
|
||||||
|
|
||||||
|
SetupConfig("postproc", m_PostProc);
|
||||||
|
SetupConfig("smoothlos", m_SmoothLOS);
|
||||||
|
|
||||||
|
SetupConfig("renderpath", [this]() {
|
||||||
|
CStr renderPath;
|
||||||
|
CFG_GET_VAL("renderpath", renderPath);
|
||||||
|
SetRenderPath(RenderPathEnum::FromString(renderPath));
|
||||||
|
});
|
||||||
|
|
||||||
|
SetupConfig("watereffects", m_WaterEffects);
|
||||||
|
SetupConfig("waterfancyeffects", m_WaterFancyEffects);
|
||||||
|
SetupConfig("waterrealdepth", m_WaterRealDepth);
|
||||||
|
SetupConfig("waterrefraction", m_WaterRefraction);
|
||||||
|
SetupConfig("waterreflection", m_WaterReflection);
|
||||||
|
SetupConfig("watershadows", m_WaterShadows);
|
||||||
|
|
||||||
|
SetupConfig("particles", m_Particles);
|
||||||
|
SetupConfig("fog", [this]() {
|
||||||
|
bool enabled;
|
||||||
|
CFG_GET_VAL("fog", enabled);
|
||||||
|
SetFog(enabled);
|
||||||
|
});
|
||||||
|
SetupConfig("silhouettes", m_Silhouettes);
|
||||||
|
SetupConfig("showsky", m_ShowSky);
|
||||||
|
|
||||||
|
SetupConfig("novbo", m_NoVBO);
|
||||||
|
|
||||||
|
SetupConfig("forcealphatest", m_ForceAlphaTest);
|
||||||
|
SetupConfig("gpuskinning", [this]() {
|
||||||
|
bool enabled;
|
||||||
|
CFG_GET_VAL("gpuskinning", enabled);
|
||||||
|
if (enabled && !m_PreferGLSL)
|
||||||
|
LOGWARNING("GPUSkinning has been disabled, because it is not supported with PreferGLSL disabled.");
|
||||||
|
else if (enabled)
|
||||||
|
m_GPUSkinning = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
SetupConfig("renderactors", m_RenderActors);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRenderingOptions::SetShadows(bool value)
|
||||||
{
|
{
|
||||||
m_Shadows = value;
|
m_Shadows = value;
|
||||||
g_Renderer.MakeShadersDirty();
|
g_Renderer.MakeShadersDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SRenderingOptions::SetShadowPCF(bool value)
|
void CRenderingOptions::SetShadowPCF(bool value)
|
||||||
{
|
{
|
||||||
m_ShadowPCF = value;
|
m_ShadowPCF = value;
|
||||||
g_Renderer.MakeShadersDirty();
|
g_Renderer.MakeShadersDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SRenderingOptions::SetFog(bool value)
|
void CRenderingOptions::SetFog(bool value)
|
||||||
{
|
{
|
||||||
m_Fog = value;
|
m_Fog = value;
|
||||||
g_Renderer.MakeShadersDirty();
|
g_Renderer.MakeShadersDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SRenderingOptions::SetPreferGLSL(bool value)
|
void CRenderingOptions::SetPreferGLSL(bool value)
|
||||||
{
|
{
|
||||||
if (m_GPUSkinning && !value)
|
if (m_GPUSkinning && !value)
|
||||||
{
|
{
|
||||||
@ -154,7 +223,7 @@ void SRenderingOptions::SetPreferGLSL(bool value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SRenderingOptions::SetRenderPath(RenderPath value)
|
void CRenderingOptions::SetRenderPath(RenderPath value)
|
||||||
{
|
{
|
||||||
m_RenderPath = value;
|
m_RenderPath = value;
|
||||||
g_Renderer.SetRenderPath(m_RenderPath);
|
g_Renderer.SetRenderPath(m_RenderPath);
|
||||||
|
@ -45,13 +45,16 @@ struct RenderPathEnum
|
|||||||
static CStr8 ToString(RenderPath);
|
static CStr8 ToString(RenderPath);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SRenderingOptions
|
class CRenderingOptions
|
||||||
{
|
{
|
||||||
// The renderer needs access to our private variables directly because capabilities have not yet been extracted
|
// The renderer needs access to our private variables directly because capabilities have not yet been extracted
|
||||||
// and thus sometimes it needs to change the rendering options without the side-effects.
|
// and thus sometimes it needs to change the rendering options without the side-effects.
|
||||||
friend class CRenderer;
|
friend class CRenderer;
|
||||||
|
|
||||||
SRenderingOptions();
|
public:
|
||||||
|
CRenderingOptions();
|
||||||
|
~CRenderingOptions();
|
||||||
|
|
||||||
void ReadConfig();
|
void ReadConfig();
|
||||||
|
|
||||||
#define OPTION_DEFAULT_SETTER(NAME, TYPE) \
|
#define OPTION_DEFAULT_SETTER(NAME, TYPE) \
|
||||||
@ -108,8 +111,24 @@ OPTION_CUSTOM_SETTER(NAME, TYPE); OPTION_GETTER(NAME, TYPE); OPTION_DEF(NAME, TY
|
|||||||
#undef OPTION_DEF
|
#undef OPTION_DEF
|
||||||
#undef OPTION
|
#undef OPTION
|
||||||
#undef OPTION_WITH_SIDE_EFFECT
|
#undef OPTION_WITH_SIDE_EFFECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* Registers a config hook for config variable @name that updates @variable.
|
||||||
|
* Also immediately updates variable with the value of the config.
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void SetupConfig(CStr8 name, T& variable);
|
||||||
|
/**
|
||||||
|
* Registers a config hook for config variable @name.
|
||||||
|
* Also immediately triggers the hook.
|
||||||
|
*/
|
||||||
|
void SetupConfig(CStr8 name, std::function<void()> hook);
|
||||||
|
|
||||||
|
class ConfigHooks;
|
||||||
|
std::unique_ptr<ConfigHooks> m_ConfigHooks; // Hide this via PImpl to avoid including ConfigDB.h here.
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SRenderingOptions g_RenderingOptions;
|
extern CRenderingOptions g_RenderingOptions;
|
||||||
|
|
||||||
#endif // INCLUDED_RENDERINGOPTIONS
|
#endif // INCLUDED_RENDERINGOPTIONS
|
||||||
|
@ -20,38 +20,21 @@
|
|||||||
#include "JSInterface_Renderer.h"
|
#include "JSInterface_Renderer.h"
|
||||||
|
|
||||||
#include "graphics/TextureManager.h"
|
#include "graphics/TextureManager.h"
|
||||||
#include "renderer/PostprocManager.h"
|
|
||||||
#include "renderer/RenderingOptions.h"
|
#include "renderer/RenderingOptions.h"
|
||||||
#include "renderer/Renderer.h"
|
#include "renderer/Renderer.h"
|
||||||
#include "renderer/ShadowMap.h"
|
|
||||||
#include "scriptinterface/ScriptInterface.h"
|
#include "scriptinterface/ScriptInterface.h"
|
||||||
|
|
||||||
#define IMPLEMENT_BOOLEAN_SCRIPT_SETTING(NAME) \
|
#define IMPLEMENT_BOOLEAN_SCRIPT_SETTING(NAME) \
|
||||||
bool JSI_Renderer::Get##NAME##Enabled(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) \
|
bool Get##NAME##Enabled(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) \
|
||||||
{ \
|
{ \
|
||||||
return g_RenderingOptions.Get##NAME(); \
|
return g_RenderingOptions.Get##NAME(); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void JSI_Renderer::Set##NAME##Enabled(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), bool enabled) \
|
void Set##NAME##Enabled(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), bool enabled) \
|
||||||
{ \
|
{ \
|
||||||
g_RenderingOptions.Set##NAME(enabled); \
|
g_RenderingOptions.Set##NAME(enabled); \
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(Shadows);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(ShadowPCF);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(Particles);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(PreferGLSL);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterEffects);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterFancyEffects);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterRealDepth);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterReflection);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterRefraction);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterShadows);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(Fog);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(Silhouettes);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(ShowSky);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(SmoothLOS);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(PostProc);
|
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(DisplayFrustum);
|
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(DisplayFrustum);
|
||||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(DisplayShadowsFrustum);
|
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(DisplayShadowsFrustum);
|
||||||
|
|
||||||
@ -62,64 +45,19 @@ std::string JSI_Renderer::GetRenderPath(ScriptInterface::CmptPrivate* UNUSED(pCm
|
|||||||
return RenderPathEnum::ToString(g_RenderingOptions.GetRenderPath());
|
return RenderPathEnum::ToString(g_RenderingOptions.GetRenderPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSI_Renderer::SetRenderPath(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::string& name)
|
|
||||||
{
|
|
||||||
g_RenderingOptions.SetRenderPath(RenderPathEnum::FromString(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
void JSI_Renderer::UpdateAntiAliasingTechnique(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate))
|
|
||||||
{
|
|
||||||
g_Renderer.GetPostprocManager().UpdateAntiAliasingTechnique();
|
|
||||||
}
|
|
||||||
|
|
||||||
void JSI_Renderer::UpdateSharpeningTechnique(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate))
|
|
||||||
{
|
|
||||||
g_Renderer.GetPostprocManager().UpdateSharpeningTechnique();
|
|
||||||
}
|
|
||||||
|
|
||||||
void JSI_Renderer::UpdateSharpnessFactor(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate))
|
|
||||||
{
|
|
||||||
g_Renderer.GetPostprocManager().UpdateSharpnessFactor();
|
|
||||||
}
|
|
||||||
|
|
||||||
void JSI_Renderer::RecreateShadowMap(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate))
|
|
||||||
{
|
|
||||||
g_Renderer.GetShadowMap().RecreateTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool JSI_Renderer::TextureExists(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::wstring& filename)
|
bool JSI_Renderer::TextureExists(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::wstring& filename)
|
||||||
{
|
{
|
||||||
return g_Renderer.GetTextureManager().TextureExists(filename);
|
return g_Renderer.GetTextureManager().TextureExists(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define REGISTER_BOOLEAN_SCRIPT_SETTING(NAME) \
|
#define REGISTER_BOOLEAN_SCRIPT_SETTING(NAME) \
|
||||||
scriptInterface.RegisterFunction<bool, &JSI_Renderer::Get##NAME##Enabled>("Renderer_Get" #NAME "Enabled"); \
|
scriptInterface.RegisterFunction<bool, &Get##NAME##Enabled>("Renderer_Get" #NAME "Enabled"); \
|
||||||
scriptInterface.RegisterFunction<void, bool, &JSI_Renderer::Set##NAME##Enabled>("Renderer_Set" #NAME "Enabled");
|
scriptInterface.RegisterFunction<void, bool, &Set##NAME##Enabled>("Renderer_Set" #NAME "Enabled");
|
||||||
|
|
||||||
void JSI_Renderer::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
|
void JSI_Renderer::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
|
||||||
{
|
{
|
||||||
scriptInterface.RegisterFunction<std::string, &JSI_Renderer::GetRenderPath>("Renderer_GetRenderPath");
|
scriptInterface.RegisterFunction<std::string, &JSI_Renderer::GetRenderPath>("Renderer_GetRenderPath");
|
||||||
scriptInterface.RegisterFunction<void, std::string, &JSI_Renderer::SetRenderPath>("Renderer_SetRenderPath");
|
|
||||||
scriptInterface.RegisterFunction<void, &JSI_Renderer::RecreateShadowMap>("Renderer_RecreateShadowMap");
|
|
||||||
scriptInterface.RegisterFunction<void, &JSI_Renderer::UpdateAntiAliasingTechnique>("Renderer_UpdateAntiAliasingTechnique");
|
|
||||||
scriptInterface.RegisterFunction<void, &JSI_Renderer::UpdateSharpeningTechnique>("Renderer_UpdateSharpeningTechnique");
|
|
||||||
scriptInterface.RegisterFunction<void, &JSI_Renderer::UpdateSharpnessFactor>("Renderer_UpdateSharpnessFactor");
|
|
||||||
scriptInterface.RegisterFunction<bool, std::wstring, &JSI_Renderer::TextureExists>("TextureExists");
|
scriptInterface.RegisterFunction<bool, std::wstring, &JSI_Renderer::TextureExists>("TextureExists");
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(Shadows);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(ShadowPCF);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(Particles);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(PreferGLSL);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterEffects);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterFancyEffects);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterRealDepth);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterReflection);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterRefraction);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterShadows);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(Fog);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(Silhouettes);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(ShowSky);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(SmoothLOS);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(PostProc);
|
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(DisplayFrustum);
|
REGISTER_BOOLEAN_SCRIPT_SETTING(DisplayFrustum);
|
||||||
REGISTER_BOOLEAN_SCRIPT_SETTING(DisplayShadowsFrustum);
|
REGISTER_BOOLEAN_SCRIPT_SETTING(DisplayShadowsFrustum);
|
||||||
}
|
}
|
||||||
|
@ -20,38 +20,11 @@
|
|||||||
|
|
||||||
#include "scriptinterface/ScriptInterface.h"
|
#include "scriptinterface/ScriptInterface.h"
|
||||||
|
|
||||||
#define DECLARE_BOOLEAN_SCRIPT_SETTING(NAME) \
|
|
||||||
bool Get##NAME##Enabled(ScriptInterface::CmptPrivate* pCmptPrivate); \
|
|
||||||
void Set##NAME##Enabled(ScriptInterface::CmptPrivate* pCmptPrivate, bool Enabled);
|
|
||||||
|
|
||||||
namespace JSI_Renderer
|
namespace JSI_Renderer
|
||||||
{
|
{
|
||||||
std::string GetRenderPath(ScriptInterface::CmptPrivate* pCmptPrivate);
|
std::string GetRenderPath(ScriptInterface::CmptPrivate* pCmptPrivate);
|
||||||
void SetRenderPath(ScriptInterface::CmptPrivate* pCmptPrivate, const std::string& name);
|
|
||||||
void UpdateAntiAliasingTechnique(ScriptInterface::CmptPrivate* pCmptPrivate);
|
|
||||||
void UpdateSharpeningTechnique(ScriptInterface::CmptPrivate* pCmptPrivate);
|
|
||||||
void UpdateSharpnessFactor(ScriptInterface::CmptPrivate* pCmptPrivate);
|
|
||||||
void RecreateShadowMap(ScriptInterface::CmptPrivate* pCmptPrivate);
|
|
||||||
bool TextureExists(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& filename);
|
bool TextureExists(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& filename);
|
||||||
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(Shadows);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(ShadowPCF);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(Particles);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(PreferGLSL);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(WaterEffects);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(WaterFancyEffects);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(WaterRealDepth);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(WaterReflection);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(WaterRefraction);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(WaterShadows);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(Fog);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(Silhouettes);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(ShowSky);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(SmoothLOS);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(PostProc);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(DisplayFrustum);
|
|
||||||
DECLARE_BOOLEAN_SCRIPT_SETTING(DisplayShadowsFrustum);
|
|
||||||
|
|
||||||
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
|
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user