Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/scripting/JSInterface_Renderer.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
historic_bruno: 2019 | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * 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/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "JSInterface_Renderer.h" | #include "JSInterface_Renderer.h" | ||||
#include "graphics/TextureManager.h" | #include "graphics/TextureManager.h" | ||||
#include "ps/Profile.h" | #include "renderer/RenderingOptions.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/ShadowMap.h" | #include "renderer/ShadowMap.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#define IMPLEMENT_BOOLEAN_SCRIPT_SETTING(NAME, SCRIPTNAME) \ | #define IMPLEMENT_BOOLEAN_SCRIPT_SETTING(NAME) \ | ||||
bool JSI_Renderer::Get##SCRIPTNAME##Enabled(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) \ | bool JSI_Renderer::Get##NAME##Enabled(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) \ | ||||
{ \ | { \ | ||||
return g_Renderer.GetOptionBool(CRenderer::OPT_##NAME); \ | return g_RenderingOptions.Get##NAME(); \ | ||||
} \ | } \ | ||||
\ | \ | ||||
void JSI_Renderer::Set##SCRIPTNAME##Enabled(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool Enabled) \ | void JSI_Renderer::Set##NAME##Enabled(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool enabled) \ | ||||
{ \ | { \ | ||||
g_Renderer.SetOptionBool(CRenderer::OPT_##NAME, Enabled); \ | g_RenderingOptions.Set##NAME(enabled); \ | ||||
} | } | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(PARTICLES, Particles); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(Shadows); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(PREFERGLSL, PreferGLSL); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(ShadowPCF); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WATEREFFECTS, WaterEffects); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(Particles); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WATERFANCYEFFECTS, WaterFancyEffects); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(PreferGLSL); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(SHADOWPCF, ShadowPCF); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterEffects); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(SHADOWS, Shadows); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterFancyEffects); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WATERREALDEPTH, WaterRealDepth); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterRealDepth); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WATERREFLECTION, WaterReflection); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterReflection); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WATERREFRACTION, WaterRefraction); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterRefraction); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(SHADOWSONWATER, WaterShadows); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(WaterShadows); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(FOG, Fog); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(Fog); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(SILHOUETTES, Silhouettes); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(Silhouettes); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(SHOWSKY, ShowSky); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(ShowSky); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(SMOOTHLOS, SmoothLOS); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(SmoothLOS); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(POSTPROC, Postproc); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(PostProc); | ||||
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(DISPLAYFRUSTUM, DisplayFrustum); | IMPLEMENT_BOOLEAN_SCRIPT_SETTING(DisplayFrustum); | ||||
#undef IMPLEMENT_BOOLEAN_SCRIPT_SETTING | #undef IMPLEMENT_BOOLEAN_SCRIPT_SETTING | ||||
std::string JSI_Renderer::GetRenderPath(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | |||||
{ | |||||
return CRenderer::GetRenderPathName(g_Renderer.GetRenderPath()); | |||||
} | |||||
void JSI_Renderer::SetRenderPath(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& name) | |||||
{ | |||||
g_Renderer.SetRenderPath(CRenderer::GetRenderPathByName(name)); | |||||
} | |||||
void JSI_Renderer::RecreateShadowMap(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | |||||
{ | |||||
g_Renderer.GetShadowMap().RecreateTexture(); | |||||
} | |||||
bool JSI_Renderer::TextureExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& 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, &JSI_Renderer::Get##NAME##Enabled>("Renderer_Get" #NAME "Enabled"); \ | ||||
scriptInterface.RegisterFunction<void, bool, &JSI_Renderer::Set##NAME##Enabled>("Renderer_Set" #NAME "Enabled"); | scriptInterface.RegisterFunction<void, bool, &JSI_Renderer::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<void, std::string, &JSI_Renderer::SetRenderPath>("Renderer_SetRenderPath"); | |||||
scriptInterface.RegisterFunction<void, &JSI_Renderer::RecreateShadowMap>("Renderer_RecreateShadowMap"); | |||||
scriptInterface.RegisterFunction<bool, std::wstring, &JSI_Renderer::TextureExists>("TextureExists"); | |||||
REGISTER_BOOLEAN_SCRIPT_SETTING(Shadows); | REGISTER_BOOLEAN_SCRIPT_SETTING(Shadows); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(ShadowPCF); | REGISTER_BOOLEAN_SCRIPT_SETTING(ShadowPCF); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(Particles); | REGISTER_BOOLEAN_SCRIPT_SETTING(Particles); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(PreferGLSL); | REGISTER_BOOLEAN_SCRIPT_SETTING(PreferGLSL); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterEffects); | REGISTER_BOOLEAN_SCRIPT_SETTING(WaterEffects); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterFancyEffects); | REGISTER_BOOLEAN_SCRIPT_SETTING(WaterFancyEffects); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterRealDepth); | REGISTER_BOOLEAN_SCRIPT_SETTING(WaterRealDepth); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterReflection); | REGISTER_BOOLEAN_SCRIPT_SETTING(WaterReflection); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterRefraction); | REGISTER_BOOLEAN_SCRIPT_SETTING(WaterRefraction); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(WaterShadows); | REGISTER_BOOLEAN_SCRIPT_SETTING(WaterShadows); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(Fog); | REGISTER_BOOLEAN_SCRIPT_SETTING(Fog); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(Silhouettes); | REGISTER_BOOLEAN_SCRIPT_SETTING(Silhouettes); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(ShowSky); | REGISTER_BOOLEAN_SCRIPT_SETTING(ShowSky); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(SmoothLOS); | REGISTER_BOOLEAN_SCRIPT_SETTING(SmoothLOS); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(Postproc); | REGISTER_BOOLEAN_SCRIPT_SETTING(PostProc); | ||||
REGISTER_BOOLEAN_SCRIPT_SETTING(DisplayFrustum); | REGISTER_BOOLEAN_SCRIPT_SETTING(DisplayFrustum); | ||||
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<bool, std::wstring, &JSI_Renderer::TextureExists>("TextureExists"); | |||||
} | } | ||||
#undef REGISTER_BOOLEAN_SCRIPT_SETTING | #undef REGISTER_BOOLEAN_SCRIPT_SETTING | ||||
std::string JSI_Renderer::GetRenderPath(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | |||||
{ | |||||
return RenderPathEnum::ToString(g_RenderingOptions.GetRenderPath()); | |||||
} | |||||
Not Done Inline ActionsThese should go in RenderingOptions as a part of an OPTION_WITH_SIDE_EFFECT, right? If these functions get called elsewhere in the engine, we have the same problem. Looks like Actor Viewer does call SetShadows. (Would have to make sure this doesn't break any of the other call sites like InitRenderer, though) historic_bruno: These should go in RenderingOptions as a part of an OPTION_WITH_SIDE_EFFECT, right? If these… | |||||
Done Inline ActionsAr, you're quite right indeed, this should go in RenderingOptions::SetShadows directly. wraitii: Ar, you're quite right indeed, this should go in RenderingOptions::SetShadows directly. | |||||
Done Inline ActionsI actually completely forgot how my own patch worked there :P thanks for the notice. wraitii: I actually completely forgot how my own patch worked there :P thanks for the notice. | |||||
void JSI_Renderer::SetRenderPath(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& name) | |||||
{ | |||||
g_RenderingOptions.SetRenderPath(RenderPathEnum::FromString(name)); | |||||
} | |||||
void JSI_Renderer::RecreateShadowMap(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | |||||
{ | |||||
g_Renderer.GetShadowMap().RecreateTexture(); | |||||
} | |||||
bool JSI_Renderer::TextureExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename) | |||||
{ | |||||
return g_Renderer.GetTextureManager().TextureExists(filename); | |||||
} |
Wildfire Games · Phabricator
2019