diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index f6a1667c9..30368f1ab 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -44,6 +44,7 @@ namespace graphics { static bool gammaCorrect = false; +static bool lowPowerPreferred = false; static bool debugMode = false; static bool debugModeQueried = false; @@ -149,6 +150,16 @@ void setRenderers(const std::vector &renderers) _renderers = renderers; } +void setLowPowerPreferred(bool preferred) +{ + lowPowerPreferred = preferred; +} + +bool isLowPowerPreferred() +{ + return lowPowerPreferred; +} + Graphics *Graphics::createInstance() { Graphics *instance = Module::getInstance(M_GRAPHICS); diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 8b28e6e38..3020bc7f4 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -109,6 +109,9 @@ const std::vector &getDefaultRenderers(); const std::vector &getRenderers(); void setRenderers(const std::vector &renderers); +void setLowPowerPreferred(bool preferred); +bool isLowPowerPreferred(); + class Graphics : public Module { public: diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index 69060e8aa..b9b185242 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -1605,9 +1605,9 @@ int Graphics::rateDeviceSuitability(VkPhysicalDevice device) // optional if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) - score += 1000; + score += isLowPowerPreferred() ? 100 : 1000; if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) - score += 100; + score += isLowPowerPreferred() ? 1000 : 100; if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU) score += 10; diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index 7ec650b09..34959cdab 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -198,6 +198,12 @@ int w_isGammaCorrect(lua_State *L) return 1; } +int w_isLowPowerPreferred(lua_State *L) +{ + luax_pushboolean(L, graphics::isLowPowerPreferred()); + return 1; +} + int w_getWidth(lua_State *L) { lua_pushinteger(L, instance()->getWidth()); @@ -4112,6 +4118,7 @@ static const luaL_Reg functions[] = { "isCreated", w_isCreated }, { "isActive", w_isActive }, { "isGammaCorrect", w_isGammaCorrect }, + { "isLowPowerPreferred", w_isLowPowerPreferred }, { "getWidth", w_getWidth }, { "getHeight", w_getHeight }, { "getDimensions", w_getDimensions }, diff --git a/src/modules/love/boot.lua b/src/modules/love/boot.lua index 4fc6a28df..adc7d4585 100644 --- a/src/modules/love/boot.lua +++ b/src/modules/love/boot.lua @@ -183,6 +183,7 @@ function love.init() }, graphics = { gammacorrect = false, + lowpower = false, renderers = nil, excluderenderers = nil, }, @@ -259,6 +260,10 @@ function love.init() love._setGammaCorrect(gammacorrect) end + if love._setLowPowerPreferred and type(c.graphics) == "table" then + love._setLowPowerPreferred(c.graphics.lowpower) + end + if love._setRenderers then local renderers = love._getDefaultRenderers() if type(c.renderers) == "table" then diff --git a/src/modules/love/love.cpp b/src/modules/love/love.cpp index 72cac9348..235dea72d 100644 --- a/src/modules/love/love.cpp +++ b/src/modules/love/love.cpp @@ -423,6 +423,14 @@ static int w__setRenderers(lua_State *L) return 0; } +static int w__setLowPowerPreferred(lua_State *L) +{ +#ifdef LOVE_ENABLE_GRAPHICS + love::graphics::setLowPowerPreferred(love::luax_checkboolean(L, 1)); +#endif + return 0; +} + static int w__setHighDPIAllowed(lua_State *L) { #ifdef LOVE_ENABLE_WINDOW @@ -556,6 +564,9 @@ int luaopen_love(lua_State *L) lua_pushcfunction(L, w__setRenderers); lua_setfield(L, -2, "_setRenderers"); + lua_pushcfunction(L, w__setLowPowerPreferred); + lua_setfield(L, -2, "_setLowPowerPreferred"); + lua_pushcfunction(L, w__setHighDPIAllowed); lua_setfield(L, -2, "_setHighDPIAllowed");