Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate "Terrain Shading" quality setting #3465

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ivis_opengl/gfx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ namespace gfx_api
virtual void set_polygon_offset(const float& offset, const float& slope) = 0;
virtual void set_depth_range(const float& min, const float& max) = 0;
virtual int32_t get_context_value(const context_value property) = 0;
virtual uint64_t get_estimated_vram_mb() = 0;
virtual uint64_t get_estimated_vram_mb(bool dedicatedOnly) = 0;
static context& get();
static bool initialize(const gfx_api::backend_Impl_Factory& impl, int32_t antialiasing, swap_interval_mode mode, optional<float> mipLodBias, uint32_t depthMapResolution, gfx_api::backend_type backend);
static bool isInitialized();
Expand Down
17 changes: 14 additions & 3 deletions lib/ivis_opengl/gfx_api_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2721,7 +2721,7 @@ int32_t gl_context::get_context_value(const context_value property)
return value;
}

uint64_t gl_context::get_estimated_vram_mb()
uint64_t gl_context::get_estimated_vram_mb(bool dedicatedOnly)
{
if (GLAD_GL_NVX_gpu_memory_info)
{
Expand All @@ -2735,7 +2735,7 @@ uint64_t gl_context::get_estimated_vram_mb()
return static_cast<uint64_t>(total_graphics_mem_kb / 1024);
}
}
else if (GLAD_GL_ATI_meminfo)
else if (GLAD_GL_ATI_meminfo && !dedicatedOnly)
{
// For GL_ATI_meminfo, get the current free texture memory (stats_kb[0])
GLint stats_kb[4] = {0, 0, 0, 0};
Expand All @@ -2750,6 +2750,17 @@ uint64_t gl_context::get_estimated_vram_mb()
}
}

#if defined (__APPLE__)
WzString openGL_vendor = (const char*)wzSafeGlGetString(GL_VENDOR);
WzString openGL_renderer = (const char*)wzSafeGlGetString(GL_RENDERER);
if (openGL_vendor == "Apple" && openGL_renderer.startsWith("Apple"))
{
// For Apple GPUs, use system ("unified") RAM value
auto systemRAMinMiB = wzGetCurrentSystemRAM();
return systemRAMinMiB;
}
#endif

return 0;
}

Expand Down Expand Up @@ -3436,7 +3447,7 @@ bool gl_context::initGLContext()
debug(LOG_3D, " * (current) Max array texture layers is %d.", (int) glMaxArrayTextureLayers);
maxArrayTextureLayers = glMaxArrayTextureLayers;

uint32_t estimatedVRAMinMiB = get_estimated_vram_mb();
uint32_t estimatedVRAMinMiB = get_estimated_vram_mb(false);
if (estimatedVRAMinMiB > 0)
{
debug(LOG_3D, " * Estimated VRAM is %" PRIu32 " MiB", estimatedVRAMinMiB);
Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/gfx_api_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ struct gl_context final : public gfx_api::context
virtual void set_polygon_offset(const float& offset, const float& slope) override;
virtual void set_depth_range(const float& min, const float& max) override;
virtual int32_t get_context_value(const context_value property) override;
virtual uint64_t get_estimated_vram_mb() override;
virtual uint64_t get_estimated_vram_mb(bool dedicatedOnly) override;

virtual size_t numDepthPasses() override;
virtual bool setDepthPassProperties(size_t numDepthPasses, size_t depthBufferResolution) override;
Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/gfx_api_null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ int32_t null_context::get_context_value(const context_value property)
return 0;
}

uint64_t null_context::get_estimated_vram_mb()
uint64_t null_context::get_estimated_vram_mb(bool dedicatedOnly)
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/gfx_api_null.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct null_context final : public gfx_api::context
virtual void set_polygon_offset(const float& offset, const float& slope) override;
virtual void set_depth_range(const float& min, const float& max) override;
virtual int32_t get_context_value(const context_value property) override;
virtual uint64_t get_estimated_vram_mb() override;
virtual uint64_t get_estimated_vram_mb(bool dedicatedOnly) override;

virtual void beginRenderPass() override;
virtual void endRenderPass() override;
Expand Down
22 changes: 21 additions & 1 deletion lib/ivis_opengl/gfx_api_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5962,11 +5962,31 @@ int32_t VkRoot::get_context_value(const gfx_api::context::context_value property
return 0;
}

uint64_t VkRoot::get_estimated_vram_mb()
static bool shouldTreatAsDedicatedGPU(const vk::PhysicalDeviceProperties &physicalDeviceProperties)
{
if (physicalDeviceProperties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu)
{
return true;
}
else if (physicalDeviceProperties.vendorID == 4203) // Apple GPU
{
return true;
}

return false;
}

uint64_t VkRoot::get_estimated_vram_mb(bool dedicatedOnly)
{
optional<uint32_t> largestDeviceLocalMemoryHeap = getVKLargestDeviceLocalMemoryHeapIndex(memprops);
ASSERT_OR_RETURN(0, largestDeviceLocalMemoryHeap.has_value(), "Couldn't find the largest device local memory heap?");
auto largestDeviceLocalMemoryHeapSize = memprops.memoryHeaps[largestDeviceLocalMemoryHeap.value()].size;

if (dedicatedOnly && !shouldTreatAsDedicatedGPU(physDeviceProps))
{
return 0;
}

return static_cast<uint64_t>(largestDeviceLocalMemoryHeapSize / 1048576);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/gfx_api_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ struct VkRoot final : gfx_api::context

public:
virtual int32_t get_context_value(const gfx_api::context::context_value property) override;
virtual uint64_t get_estimated_vram_mb() override;
virtual uint64_t get_estimated_vram_mb(bool dedicatedOnly) override;
virtual void debugStringMarker(const char *str) override;
virtual void debugSceneBegin(const char *descr) override;
virtual void debugSceneEnd(const char *descr) override;
Expand Down
35 changes: 27 additions & 8 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ bool loadConfig()
setAutoratingUrl(iniGetString("autoratingUrlV2", WZ_DEFAULT_PUBLIC_RATING_LOOKUP_SERVICE_URL).value());
setAutoratingEnable(iniGetBool("autorating", false).value());
NETsetMasterserverName(iniGetString("masterserver_name", "lobby.wz2100.net").value().c_str());
mpSetServerName(iniGetString("server_name", "").value().c_str());
mpSetServerName(iniGetString("server_name", "").value());
// iV_font(ini.value("fontname", "DejaVu Sans").toString().toUtf8().constData(),
// ini.value("fontface", "Book").toString().toUtf8().constData(),
// ini.value("fontfacebold", "Bold").toString().toUtf8().constData());
Expand Down Expand Up @@ -591,7 +591,7 @@ bool loadConfig()
war_setMPopenSpectatorSlots(static_cast<uint16_t>(std::max<int>(0, std::min<int>(openSpecSlotsIntValue, MAX_SPECTATOR_SLOTS))));
war_setFogEnd(iniGetInteger("fogEnd", 8000).value());
war_setFogStart(iniGetInteger("fogStart", 4000).value());
if (auto value = iniGetIntegerOpt("terrainShaderQuality"))
if (auto value = iniGetIntegerOpt("terrainMode"))
{
auto intValue = value.value();
if (intValue >= 0 && intValue <= TerrainShaderQuality_MAX)
Expand All @@ -600,7 +600,15 @@ bool loadConfig()
}
else
{
debug(LOG_WARNING, "Unsupported / invalid terrainShaderQuality value: %d; using default", intValue);
debug(LOG_WARNING, "Unsupported / invalid terrainMode value: %d; using default", intValue);
}
}
if (auto value = iniGetIntegerOpt("terrainShadingQuality"))
{
auto intValue = value.value();
if (!setTerrainMappingTexturesMaxSize(intValue))
{
debug(LOG_WARNING, "Unsupported / invalid terrainShadingQuality value: %d; using default", intValue);
}
}
war_setShadowFilterSize(iniGetInteger("shadowFilterSize", (int)war_getShadowFilterSize()).value());
Expand Down Expand Up @@ -666,6 +674,16 @@ bool saveConfig()
auto iniSetString = [&iniGeneral](const std::string& key, const std::string& value) {
iniGeneral[key] = value;
};
auto iniSetFromCString = [&iniGeneral](const std::string& key, const char* value, size_t maxLength) {
std::string strVal;
if (value)
{
size_t len = strnlen(value, maxLength);
ASSERT(len < maxLength, "Input c-string value (for key: %s) appears to be missing null-terminator?", key.c_str());
strVal.assign(value, len);
}
iniGeneral[key] = strVal;
};

// //////////////////////////
// voicevol, fxvol and cdvol
Expand Down Expand Up @@ -722,7 +740,7 @@ bool saveConfig()
iniSetBool("PauseOnFocusLoss", war_GetPauseOnFocusLoss());
iniSetString("autoratingUrlV2", getAutoratingUrl());
iniSetBool("autorating", getAutoratingEnable());
iniSetString("masterserver_name", NETgetMasterserverName());
iniSetFromCString("masterserver_name", NETgetMasterserverName(), 255);
iniSetInteger("masterserver_port", (int)NETgetMasterserverPort());
iniSetString("server_name", mpGetServerName());
if (!netGameserverPortOverride) // do not save the config port setting if there's a command-line override
Expand All @@ -744,7 +762,7 @@ bool saveConfig()
{
if (bMultiPlayer && NetPlay.bComms)
{
iniSetString("gameName", game.name); // last hosted game
iniSetFromCString("gameName", game.name, 128); // last hosted game
war_setMPInactivityMinutes(game.inactivityMinutes);
war_setMPGameTimeLimitMinutes(game.gameTimeLimitMinutes);
war_setMPPlayerLeaveMode(game.playerLeaveMode);
Expand All @@ -753,15 +771,15 @@ bool saveConfig()
auto currentSpectatorSlotInfo = SpectatorInfo::currentNetPlayState();
war_setMPopenSpectatorSlots(currentSpectatorSlotInfo.totalSpectatorSlots);
}
iniSetString("mapName", game.map); // map name
iniSetFromCString("mapName", game.map, 128); // map name
iniSetString("mapHash", game.hash.toString()); // map hash
iniSetInteger("maxPlayers", (int)game.maxPlayers); // maxPlayers
iniSetInteger("powerLevel", game.power); // power
iniSetInteger("base", game.base); // size of base
iniSetInteger("alliance", (int)game.alliance); // allow alliances
iniSetInteger("newScavengers", game.scavengers);
}
iniSetString("playerName", (char *)sPlayer); // player name
iniSetFromCString("playerName", (char *)sPlayer, 128); // player name
}
iniSetInteger("colourMP", war_getMPcolour());
iniSetInteger("inactivityMinutesMP", war_getMPInactivityMinutes());
Expand All @@ -782,7 +800,8 @@ bool saveConfig()
iniSetInteger("oldLogsLimit", war_getOldLogsLimit());
iniSetInteger("fogEnd", war_getFogEnd());
iniSetInteger("fogStart", war_getFogStart());
iniSetInteger("terrainShaderQuality", getTerrainShaderQuality());
iniSetInteger("terrainMode", getTerrainShaderQuality());
iniSetInteger("terrainShadingQuality", getTerrainMappingTexturesMaxSize());
iniSetInteger("shadowFilterSize", (int)war_getShadowFilterSize());
iniSetInteger("shadowMapResolution", (int)war_getShadowMapResolution());
iniSetInteger("configVersion", CURRCONFVERSION);
Expand Down
54 changes: 54 additions & 0 deletions src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,55 @@ static std::shared_ptr<WIDGET> makeTerrainQualityDropdown()
return Margin(0, 10).wrap(dropdown);
}

static std::shared_ptr<WIDGET> makeTerrainShadingQualityDropdown()
{
std::vector<std::tuple<WzString, int32_t>> dropDownChoices = {
{_("Medium Quality"), 512},
{_("High Quality"), 1024},
};

size_t currentSettingIdx = 0;
auto currValue = getTerrainMappingTexturesMaxSize();
auto it = std::find_if(dropDownChoices.begin(), dropDownChoices.end(), [currValue](const std::tuple<WzString, int32_t>& item) -> bool {
return std::get<1>(item) == currValue;
});
if (it != dropDownChoices.end())
{
currentSettingIdx = it - dropDownChoices.begin();
}

auto dropdown = std::make_shared<DropdownWidget>();
dropdown->id = FRONTEND_TERRAIN_SHADING_QUALITY_R;
dropdown->setListHeight(FRONTEND_BUTHEIGHT * std::min<uint32_t>(5, dropDownChoices.size()));
const auto paddingSize = 10;

for (const auto& option : dropDownChoices)
{
bool supportedMode = true;
auto item = makeTextButton(0, std::get<0>(option).toUtf8(), supportedMode ? 0 : WBUT_DISABLE);
if (!supportedMode)
{
item->setTip(_("Terrain quality mode not available."));
}
dropdown->addItem(Margin(0, paddingSize).wrap(item));
}

dropdown->setSelectedIndex(currentSettingIdx);

dropdown->setCanChange([dropDownChoices](DropdownWidget &widget, size_t newIndex, std::shared_ptr<WIDGET> newSelectedWidget) -> bool {
ASSERT_OR_RETURN(false, newIndex < dropDownChoices.size(), "Invalid index");
auto newMode = std::get<1>(dropDownChoices.at(newIndex));
if (!setTerrainMappingTexturesMaxSize(newMode))
{
debug(LOG_ERROR, "Failed to set terrain mapping texture quality: %d", newMode);
return false;
}
return true;
});

return Margin(0, 10).wrap(dropdown);
}

static std::shared_ptr<WIDGET> makeShadowMapResolutionDropdown()
{
std::vector<std::tuple<WzString, uint32_t>> dropDownChoices = {
Expand Down Expand Up @@ -1117,6 +1166,11 @@ void startGraphicsOptionsMenu()
grid->place({1, 1, false}, row, makeTerrainQualityDropdown());
row.start++;

// Terrain Shading Quality
grid->place({0}, row, addMargin(makeTextButton(FRONTEND_TERRAIN_SHADING_QUALITY, _("Terrain Shading"), WBUT_SECONDARY)));
grid->place({1, 1, false}, row, makeTerrainShadingQualityDropdown());
row.start++;

////////////
// Shadows
grid->place({0}, row, addMargin(makeTextButton(FRONTEND_SHADOWS, _("Shadows"), WBUT_SECONDARY)));
Expand Down
2 changes: 2 additions & 0 deletions src/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ enum
FRONTEND_SSHAKE_R,
FRONTEND_TERRAIN_QUALITY,
FRONTEND_TERRAIN_QUALITY_R,
FRONTEND_TERRAIN_SHADING_QUALITY,
FRONTEND_TERRAIN_SHADING_QUALITY_R,
FRONTEND_GROUPS,
FRONTEND_GROUPS_R,

Expand Down
Loading
Loading