Merge branch 'master' into jgrpp

# Conflicts:
#	src/lang/korean.txt
#	src/settings.cpp
This commit is contained in:
Jonathan G Rennison
2021-04-12 00:22:13 +01:00
78 changed files with 184 additions and 55 deletions

View File

@@ -73,8 +73,11 @@ const char *VideoDriver_SDL_OpenGL::Start(const StringList &param)
int w, h;
SDL_GetWindowSize(this->sdl_window, &w, &h);
this->ClientSizeChanged(w, h, true);
SDL_GL_SetSwapInterval(GetDriverParamBool(param, "vsync") ? 1 : 0);
/* We should have a valid screen buffer now. If not, something went wrong and we should abort. */
if (_screen.dst_ptr == nullptr) {
this->Stop();
return "Can't get pointer to screen buffer";
}
return nullptr;
}
@@ -95,6 +98,11 @@ void VideoDriver_SDL_OpenGL::DestroyContext()
}
}
void VideoDriver_SDL_OpenGL::ToggleVsync(bool vsync)
{
SDL_GL_SetSwapInterval(vsync);
}
const char *VideoDriver_SDL_OpenGL::AllocateContext()
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
@@ -111,6 +119,8 @@ const char *VideoDriver_SDL_OpenGL::AllocateContext()
this->gl_context = SDL_GL_CreateContext(this->sdl_window);
if (this->gl_context == nullptr) return "SDL2: Can't active GL context";
ToggleVsync(_video_vsync);
return OpenGLBackend::Create(&GetOGLProcAddressCallback);
}

View File

@@ -29,6 +29,8 @@ public:
bool HasAnimBuffer() override { return true; }
uint8 *GetAnimBuffer() override { return this->anim_buffer; }
void ToggleVsync(bool vsync) override;
const char *GetName() const override { return "sdl-opengl"; }
protected:

View File

@@ -21,6 +21,7 @@
#include "video_driver.hpp"
bool _video_hw_accel; ///< Whether to consider hardware accelerated video drivers.
bool _video_vsync; ///< Whether we should use vsync (only if _video_hw_accel is enabled).
void VideoDriver::GameLoop()
{

View File

@@ -33,6 +33,7 @@ extern std::vector<Dimension> _resolutions;
extern Dimension _cur_resolution;
extern bool _rightclick_emulate;
extern bool _video_hw_accel;
extern bool _video_vsync;
/** The base of all video drivers. */
class VideoDriver : public Driver {
@@ -71,6 +72,12 @@ public:
*/
virtual bool ToggleFullscreen(bool fullscreen) = 0;
/**
* Change the vsync setting.
* @param vsync The new setting.
*/
virtual void ToggleVsync(bool vsync) {}
/**
* Callback invoked after the blitter was changed.
* @return True if no error.

View File

@@ -1295,7 +1295,6 @@ const char *VideoDriver_Win32OpenGL::Start(const StringList &param)
if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) return "Only real blitters supported";
Dimension old_res = _cur_resolution; // Save current screen resolution in case of errors, as MakeWindow invalidates it.
this->vsync = GetDriverParamBool(param, "vsync");
LoadWGLExtensions();
@@ -1311,6 +1310,12 @@ const char *VideoDriver_Win32OpenGL::Start(const StringList &param)
}
this->ClientSizeChanged(this->width, this->height, true);
/* We should have a valid screen buffer now. If not, something went wrong and we should abort. */
if (_screen.dst_ptr == nullptr) {
this->Stop();
_cur_resolution = old_res;
return "Can't get pointer to screen buffer";
}
MarkWholeScreenDirty();
@@ -1340,6 +1345,15 @@ void VideoDriver_Win32OpenGL::DestroyContext()
}
}
void VideoDriver_Win32OpenGL::ToggleVsync(bool vsync)
{
if (_wglSwapIntervalEXT != nullptr) {
_wglSwapIntervalEXT(vsync);
} else if (vsync) {
DEBUG(driver, 0, "OpenGL: Vsync requested, but not supported by driver");
}
}
const char *VideoDriver_Win32OpenGL::AllocateContext()
{
this->dc = GetDC(this->main_wnd);
@@ -1368,12 +1382,7 @@ const char *VideoDriver_Win32OpenGL::AllocateContext()
}
if (!wglMakeCurrent(this->dc, rc)) return "Can't active GL context";
/* Enable/disable Vsync if supported. */
if (_wglSwapIntervalEXT != nullptr) {
_wglSwapIntervalEXT(this->vsync ? 1 : 0);
} else if (vsync) {
DEBUG(driver, 0, "OpenGL: Vsync requested, but not supported by driver");
}
this->ToggleVsync(_video_vsync);
this->gl_rc = rc;
return OpenGLBackend::Create(&GetOGLProcAddressCallback);

View File

@@ -142,12 +142,13 @@ public:
bool HasAnimBuffer() override { return true; }
uint8 *GetAnimBuffer() override { return this->anim_buffer; }
void ToggleVsync(bool vsync) override;
const char *GetName() const override { return "win32-opengl"; }
protected:
HDC dc; ///< Window device context.
HGLRC gl_rc; ///< OpenGL context.
bool vsync; ///< Enable VSync?
uint8 *anim_buffer; ///< Animation buffer from OpenGL back-end.
uint8 GetFullscreenBpp() override { return 32; } // OpenGL is always 32 bpp.