Add t.graphics.lowpower = true/false love.conf option (defaults to false).

Add love.graphics.isLowPowerPreferred.

It's currently hooked up in the vulkan backend.
#2127
This commit is contained in:
Sasha Szpakowski
2024-12-20 21:02:20 -04:00
parent 285320ff75
commit da365e2ab9
6 changed files with 39 additions and 2 deletions
+11
View File
@@ -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<Renderer> &renderers)
_renderers = renderers;
}
void setLowPowerPreferred(bool preferred)
{
lowPowerPreferred = preferred;
}
bool isLowPowerPreferred()
{
return lowPowerPreferred;
}
Graphics *Graphics::createInstance()
{
Graphics *instance = Module::getInstance<Graphics>(M_GRAPHICS);
+3
View File
@@ -109,6 +109,9 @@ const std::vector<Renderer> &getDefaultRenderers();
const std::vector<Renderer> &getRenderers();
void setRenderers(const std::vector<Renderer> &renderers);
void setLowPowerPreferred(bool preferred);
bool isLowPowerPreferred();
class Graphics : public Module
{
public:
+2 -2
View File
@@ -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;
+7
View File
@@ -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 },
+5
View File
@@ -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
+11
View File
@@ -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");