mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
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:
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user