mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Merged default into minor
--HG-- branch : minor
This commit is contained in:
@@ -42,7 +42,7 @@ WindowSettings::WindowSettings()
|
||||
: fullscreen(false)
|
||||
, fstype(Window::FULLSCREEN_TYPE_NORMAL)
|
||||
, vsync(true)
|
||||
, fsaa(0)
|
||||
, msaa(0)
|
||||
, resizable(false)
|
||||
, minwidth(1)
|
||||
, minheight(1)
|
||||
@@ -89,7 +89,7 @@ StringMap<Window::Setting, Window::SETTING_MAX_ENUM>::Entry Window::settingEntri
|
||||
{"fullscreen", SETTING_FULLSCREEN},
|
||||
{"fullscreentype", SETTING_FULLSCREEN_TYPE},
|
||||
{"vsync", SETTING_VSYNC},
|
||||
{"fsaa", SETTING_FSAA},
|
||||
{"msaa", SETTING_MSAA},
|
||||
{"resizable", SETTING_RESIZABLE},
|
||||
{"minwidth", SETTING_MIN_WIDTH},
|
||||
{"minheight", SETTING_MIN_HEIGHT},
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
SETTING_FULLSCREEN,
|
||||
SETTING_FULLSCREEN_TYPE,
|
||||
SETTING_VSYNC,
|
||||
SETTING_FSAA,
|
||||
SETTING_MSAA,
|
||||
SETTING_RESIZABLE,
|
||||
SETTING_MIN_WIDTH,
|
||||
SETTING_MIN_HEIGHT,
|
||||
@@ -94,6 +94,8 @@ public:
|
||||
|
||||
virtual int getDisplayCount() const = 0;
|
||||
|
||||
virtual const char *getDisplayName(int displayindex) const = 0;
|
||||
|
||||
virtual std::vector<WindowSize> getFullscreenSizes(int displayindex) const = 0;
|
||||
|
||||
virtual void getDesktopDimensions(int displayindex, int &width, int &height) const = 0;
|
||||
@@ -163,7 +165,7 @@ struct WindowSettings
|
||||
bool fullscreen; // = false
|
||||
Window::FullscreenType fstype; // = FULLSCREEN_TYPE_NORMAL
|
||||
bool vsync; // = true
|
||||
int fsaa; // = 0
|
||||
int msaa; // = 0
|
||||
bool resizable; // = false
|
||||
int minwidth; // = 1
|
||||
int minheight; // = 1
|
||||
|
||||
@@ -139,7 +139,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
|
||||
wflags &= testflags;
|
||||
|
||||
if (sdlflags != wflags || width != curMode.width || height != curMode.height
|
||||
|| f.display != curdisplay || f.fsaa != curMode.settings.fsaa)
|
||||
|| f.display != curdisplay || f.msaa != curMode.settings.msaa)
|
||||
{
|
||||
SDL_DestroyWindow(window);
|
||||
window = 0;
|
||||
@@ -158,21 +158,21 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
|
||||
created = false;
|
||||
|
||||
// In Windows and Linux, some GL attributes are set on window creation.
|
||||
setWindowGLAttributes(f.fsaa, f.sRGB);
|
||||
setWindowGLAttributes(f.msaa, f.sRGB);
|
||||
|
||||
const char *title = windowTitle.c_str();
|
||||
int pos = f.centered ? centeredpos : uncenteredpos;
|
||||
|
||||
window = SDL_CreateWindow(title, pos, pos, width, height, sdlflags);
|
||||
|
||||
if (!window && f.fsaa > 0)
|
||||
if (!window && f.msaa > 0)
|
||||
{
|
||||
// FSAA might have caused the failure, disable it and try again.
|
||||
// MSAA might have caused the failure, disable it and try again.
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
|
||||
|
||||
window = SDL_CreateWindow(title, pos, pos, width, height, sdlflags);
|
||||
f.fsaa = 0;
|
||||
f.msaa = 0;
|
||||
}
|
||||
|
||||
// Make sure the window keeps any previously set icon.
|
||||
@@ -194,7 +194,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
|
||||
|
||||
SDL_RaiseWindow(window);
|
||||
|
||||
if (!setContext(f.fsaa, f.vsync, f.sRGB))
|
||||
if (!setContext(f.msaa, f.vsync, f.sRGB))
|
||||
return false;
|
||||
|
||||
created = true;
|
||||
@@ -231,9 +231,9 @@ bool Window::onWindowResize(int width, int height)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Window::setContext(int fsaa, bool vsync, bool sRGB)
|
||||
bool Window::setContext(int msaa, bool vsync, bool sRGB)
|
||||
{
|
||||
// We would normally only need to recreate the context if FSAA changes or
|
||||
// We would normally only need to recreate the context if MSAA changes or
|
||||
// SDL_GL_MakeCurrent is unsuccessful, but in Windows MakeCurrent can
|
||||
// sometimes claim success but the context will actually be trashed.
|
||||
if (context)
|
||||
@@ -243,13 +243,13 @@ bool Window::setContext(int fsaa, bool vsync, bool sRGB)
|
||||
}
|
||||
|
||||
// Make sure the proper attributes are set.
|
||||
setWindowGLAttributes(fsaa, sRGB);
|
||||
setWindowGLAttributes(msaa, sRGB);
|
||||
|
||||
context = SDL_GL_CreateContext(window);
|
||||
|
||||
if (!context && fsaa > 0)
|
||||
if (!context && msaa > 0)
|
||||
{
|
||||
// FSAA might have caused the failure, disable it and try again.
|
||||
// MSAA might have caused the failure, disable it and try again.
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
|
||||
context = SDL_GL_CreateContext(window);
|
||||
@@ -276,26 +276,26 @@ bool Window::setContext(int fsaa, bool vsync, bool sRGB)
|
||||
// Set vertical synchronization.
|
||||
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
|
||||
|
||||
// Verify FSAA setting.
|
||||
// Verify MSAA setting.
|
||||
int buffers;
|
||||
int samples;
|
||||
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buffers);
|
||||
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &samples);
|
||||
|
||||
// Don't fail because of this, but issue a warning.
|
||||
if ((!buffers && fsaa) || (samples != fsaa))
|
||||
if ((!buffers && msaa) || (samples != msaa))
|
||||
{
|
||||
std::cerr << "Warning, FSAA setting failed! (Result: buffers: " << buffers << ", samples: " << samples << ")" << std::endl;
|
||||
fsaa = (buffers > 0) ? samples : 0;
|
||||
std::cerr << "Warning, MSAA setting failed! (Result: buffers: " << buffers << ", samples: " << samples << ")" << std::endl;
|
||||
msaa = (buffers > 0) ? samples : 0;
|
||||
}
|
||||
|
||||
curMode.settings.fsaa = fsaa;
|
||||
curMode.settings.msaa = msaa;
|
||||
curMode.settings.vsync = SDL_GL_GetSwapInterval() != 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Window::setWindowGLAttributes(int fsaa, bool /* sRGB */) const
|
||||
void Window::setWindowGLAttributes(int msaa, bool /* sRGB */) const
|
||||
{
|
||||
// Set GL window attributes.
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
||||
@@ -306,9 +306,9 @@ void Window::setWindowGLAttributes(int fsaa, bool /* sRGB */) const
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
|
||||
|
||||
// FSAA.
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (fsaa > 0) ? 1 : 0);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, (fsaa > 0) ? fsaa : 0);
|
||||
// MSAA.
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (msaa > 0) ? 1 : 0);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, (msaa > 0) ? msaa : 0);
|
||||
|
||||
/* FIXME: Enable this code but make sure to try to re-create the window and
|
||||
* context with this disabled, if creation fails with it enabled.
|
||||
@@ -461,6 +461,16 @@ int Window::getDisplayCount() const
|
||||
return SDL_GetNumVideoDisplays();
|
||||
}
|
||||
|
||||
const char *Window::getDisplayName(int displayindex) const
|
||||
{
|
||||
const char *name = SDL_GetDisplayName(displayindex);
|
||||
|
||||
if (name == nullptr)
|
||||
throw love::Exception("Invalid display index: %d", displayindex + 1);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
typedef Window::WindowSize WindowSize;
|
||||
|
||||
std::vector<WindowSize> Window::getFullscreenSizes(int displayindex) const
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
|
||||
int getDisplayCount() const;
|
||||
|
||||
const char *getDisplayName(int displayindex) const;
|
||||
|
||||
std::vector<WindowSize> getFullscreenSizes(int displayindex) const;
|
||||
|
||||
void getDesktopDimensions(int displayindex, int &width, int &height) const;
|
||||
@@ -89,8 +91,8 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
bool setContext(int fsaa, bool vsync, bool sRGB);
|
||||
void setWindowGLAttributes(int fsaa, bool sRGB) const;
|
||||
bool setContext(int msaa, bool vsync, bool sRGB);
|
||||
void setWindowGLAttributes(int msaa, bool sRGB) const;
|
||||
|
||||
// Update the saved window settings based on the window's actual state.
|
||||
void updateSettings(const WindowSettings &newsettings);
|
||||
|
||||
@@ -34,6 +34,17 @@ int w_getDisplayCount(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getDisplayName(lua_State *L)
|
||||
{
|
||||
int index = luaL_checkint(L, 1) - 1;
|
||||
|
||||
const char *name = nullptr;
|
||||
luax_catchexcept(L, [&](){ name = instance->getDisplayName(index); });
|
||||
|
||||
lua_pushstring(L, name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *settingName(Window::Setting setting)
|
||||
{
|
||||
const char *name = nullptr;
|
||||
@@ -88,7 +99,7 @@ int w_setMode(lua_State *L)
|
||||
|
||||
settings.fullscreen = luax_boolflag(L, 3, settingName(Window::SETTING_FULLSCREEN), false);
|
||||
settings.vsync = luax_boolflag(L, 3, settingName(Window::SETTING_VSYNC), true);
|
||||
settings.fsaa = luax_intflag(L, 3, settingName(Window::SETTING_FSAA), 0);
|
||||
settings.msaa = luax_intflag(L, 3, settingName(Window::SETTING_MSAA), 0);
|
||||
settings.resizable = luax_boolflag(L, 3, settingName(Window::SETTING_RESIZABLE), false);
|
||||
settings.minwidth = luax_intflag(L, 3, settingName(Window::SETTING_MIN_WIDTH), 1);
|
||||
settings.minheight = luax_intflag(L, 3, settingName(Window::SETTING_MIN_HEIGHT), 1);
|
||||
@@ -130,8 +141,8 @@ int w_getMode(lua_State *L)
|
||||
luax_pushboolean(L, settings.vsync);
|
||||
lua_setfield(L, -2, settingName(Window::SETTING_VSYNC));
|
||||
|
||||
lua_pushinteger(L, settings.fsaa);
|
||||
lua_setfield(L, -2, settingName(Window::SETTING_FSAA));
|
||||
lua_pushinteger(L, settings.msaa);
|
||||
lua_setfield(L, -2, settingName(Window::SETTING_MSAA));
|
||||
|
||||
luax_pushboolean(L, settings.resizable);
|
||||
lua_setfield(L, -2, settingName(Window::SETTING_RESIZABLE));
|
||||
@@ -300,6 +311,7 @@ int w_getPixelScale(lua_State *L)
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getDisplayCount", w_getDisplayCount },
|
||||
{ "getDisplayName", w_getDisplayName },
|
||||
{ "setMode", w_setMode },
|
||||
{ "getMode", w_getMode },
|
||||
{ "getFullscreenModes", w_getFullscreenModes },
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace window
|
||||
{
|
||||
|
||||
int w_getDisplayCount(lua_State *L);
|
||||
int w_getDisplayName(lua_State *L);
|
||||
int w_setMode(lua_State *L);
|
||||
int w_getMode(lua_State *L);
|
||||
int w_getFullscreenModes(lua_State *L);
|
||||
|
||||
Reference in New Issue
Block a user