1
0
forked from 0ad/0ad
0ad/source/renderer/RenderingOptions.h
wraitii 66fbc23f2c De-singletonify CConfigDB, make hooks RAII.
CConfigDB is no longer a singleton, and its members are no longer
static.
This makes it possible to have several instances of it, useful for
testing of if we ever want to have different config profiles.

Also updates hooks to delete themselves on destruction, to fit a more
natural RAII pattern. Long-lived objects must take care to destroy hooks
before ConfigDB is reset.

Differential Revision: https://code.wildfiregames.com/D3866
This was SVN commit r25326.
2021-04-27 07:45:40 +00:00

126 lines
3.4 KiB
C++
Executable File

/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Keeps track of the settings used for rendering.
* Ideally this header file should remain very quick to parse,
* so avoid including other headers here unless absolutely necessary.
*
* Lifetime concerns: g_RenderingOptions always exists, but hooks are tied to the configDB's lifetime
* an the renderer may or may not actually exist.
*/
#ifndef INCLUDED_RENDERINGOPTIONS
#define INCLUDED_RENDERINGOPTIONS
class CConfigDB;
class CStr8;
class CRenderer;
enum RenderPath {
// If no rendering path is configured explicitly, the renderer
// will choose the path when Open() is called.
DEFAULT,
// Classic fixed function.
FIXED,
// Use new ARB/GLSL system
SHADER
};
struct RenderPathEnum
{
static RenderPath FromString(const CStr8& name);
static CStr8 ToString(RenderPath);
};
class CRenderingOptions
{
// 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.
friend class CRenderer;
public:
CRenderingOptions();
~CRenderingOptions();
void ReadConfigAndSetupHooks();
void ClearHooks();
#define OPTION_DEFAULT_SETTER(NAME, TYPE) \
public: void Set##NAME(TYPE value) { m_##NAME = value; }\
#define OPTION_CUSTOM_SETTER(NAME, TYPE) \
public: void Set##NAME(TYPE value);\
#define OPTION_GETTER(NAME, TYPE)\
public: TYPE Get##NAME() const { return m_##NAME; }\
#define OPTION_DEF(NAME, TYPE)\
private: TYPE m_##NAME;
#define OPTION(NAME, TYPE)\
OPTION_DEFAULT_SETTER(NAME, TYPE); OPTION_GETTER(NAME, TYPE); OPTION_DEF(NAME, TYPE);
#define OPTION_WITH_SIDE_EFFECT(NAME, TYPE)\
OPTION_CUSTOM_SETTER(NAME, TYPE); OPTION_GETTER(NAME, TYPE); OPTION_DEF(NAME, TYPE);
OPTION(NoVBO, bool);
OPTION_WITH_SIDE_EFFECT(Shadows, bool);
OPTION_WITH_SIDE_EFFECT(ShadowPCF, bool);
OPTION_WITH_SIDE_EFFECT(PreferGLSL, bool);
OPTION_WITH_SIDE_EFFECT(Fog, bool);
OPTION_WITH_SIDE_EFFECT(RenderPath, RenderPath);
OPTION(WaterEffects, bool);
OPTION(WaterFancyEffects, bool);
OPTION(WaterRealDepth, bool);
OPTION(WaterRefraction, bool);
OPTION(WaterReflection, bool);
OPTION(ShadowAlphaFix, bool);
OPTION(ARBProgramShadow, bool);
OPTION(Particles, bool);
OPTION(ForceAlphaTest, bool);
OPTION(GPUSkinning, bool);
OPTION(Silhouettes, bool);
OPTION(SmoothLOS, bool);
OPTION(PostProc, bool);
OPTION(DisplayFrustum, bool);
OPTION(DisplayShadowsFrustum, bool);
OPTION(RenderActors, bool);
#undef OPTION_DEFAULT_SETTER
#undef OPTION_CUSTOM_SETTER
#undef OPTION_GETTER
#undef OPTION_DEF
#undef OPTION
#undef OPTION_WITH_SIDE_EFFECT
private:
class ConfigHooks;
std::unique_ptr<ConfigHooks> m_ConfigHooks; // Hide this via PImpl to avoid including ConfigDB.h here.
};
extern CRenderingOptions g_RenderingOptions;
#endif // INCLUDED_RENDERINGOPTIONS