diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-04-21 22:06:04 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-04-21 22:44:59 +0200 |
commit | e53313391a77eacc23b9aac4a68b4ed0471e0271 (patch) | |
tree | e2406924f277ee1d257fa7a57f9a2e84ae8aa855 /src | |
parent | 5ff15443e9160d2669ee9f54a3cefd0c43537320 (diff) | |
download | openttd-e53313391a77eacc23b9aac4a68b4ed0471e0271.tar.xz |
Fix: [OpenGL] Check maximum supported texture size against screen resolution.
Diffstat (limited to 'src')
-rw-r--r-- | src/video/cocoa/cocoa_ogl.mm | 2 | ||||
-rw-r--r-- | src/video/opengl.cpp | 13 | ||||
-rw-r--r-- | src/video/opengl.h | 4 | ||||
-rw-r--r-- | src/video/sdl2_opengl_v.cpp | 2 | ||||
-rw-r--r-- | src/video/win32_v.cpp | 2 |
5 files changed, 15 insertions, 8 deletions
diff --git a/src/video/cocoa/cocoa_ogl.mm b/src/video/cocoa/cocoa_ogl.mm index f8c2e97e0..96c3ea1bf 100644 --- a/src/video/cocoa/cocoa_ogl.mm +++ b/src/video/cocoa/cocoa_ogl.mm @@ -254,7 +254,7 @@ const char *VideoDriver_CocoaOpenGL::AllocateContext(bool allow_software) CGLSetCurrentContext(this->gl_context); - return OpenGLBackend::Create(&GetOGLProcAddressCallback); + return OpenGLBackend::Create(&GetOGLProcAddressCallback, this->GetScreenSize()); } NSView *VideoDriver_CocoaOpenGL::AllocateDrawView() diff --git a/src/video/opengl.cpp b/src/video/opengl.cpp index bb509bcd7..8a4ce3451 100644 --- a/src/video/opengl.cpp +++ b/src/video/opengl.cpp @@ -464,16 +464,17 @@ void SetupDebugOutput() /** * Create and initialize the singleton back-end class. * @param get_proc Callback to get an OpenGL function from the OS driver. + * @param screen_res Current display resolution. * @return nullptr on success, error message otherwise. */ -/* static */ const char *OpenGLBackend::Create(GetOGLProcAddressProc get_proc) +/* static */ const char *OpenGLBackend::Create(GetOGLProcAddressProc get_proc, const Dimension &screen_res) { if (OpenGLBackend::instance != nullptr) OpenGLBackend::Destroy(); GetOGLProcAddress = get_proc; OpenGLBackend::instance = new OpenGLBackend(); - return OpenGLBackend::instance->Init(); + return OpenGLBackend::instance->Init(screen_res); } /** @@ -521,9 +522,10 @@ OpenGLBackend::~OpenGLBackend() /** * Check for the needed OpenGL functionality and allocate all resources. + * @param screen_res Current display resolution. * @return Error string or nullptr if successful. */ -const char *OpenGLBackend::Init() +const char *OpenGLBackend::Init(const Dimension &screen_res) { if (!BindBasicInfoProcs()) return "OpenGL not supported"; @@ -581,6 +583,11 @@ const char *OpenGLBackend::Init() } if (this->persistent_mapping_supported) DEBUG(driver, 3, "OpenGL: Using persistent buffer mapping"); + /* Check maximum texture size against screen resolution. */ + GLint max_tex_size = 0; + _glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size); + if (std::max(screen_res.width, screen_res.height) > (uint)max_tex_size) return "Max supported texture size is too small"; + /* Check available texture units. */ GLint max_tex_units = 0; _glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_tex_units); diff --git a/src/video/opengl.h b/src/video/opengl.h index b0318f988..e5cd749f2 100644 --- a/src/video/opengl.h +++ b/src/video/opengl.h @@ -74,7 +74,7 @@ private: OpenGLBackend(); ~OpenGLBackend(); - const char *Init(); + const char *Init(const Dimension &screen_res); bool InitShaders(); void InternalClearCursorCache(); @@ -87,7 +87,7 @@ public: { return OpenGLBackend::instance; } - static const char *Create(GetOGLProcAddressProc get_proc); + static const char *Create(GetOGLProcAddressProc get_proc, const Dimension &screen_res); static void Destroy(); void PrepareContext(); diff --git a/src/video/sdl2_opengl_v.cpp b/src/video/sdl2_opengl_v.cpp index 202593e64..9c84c36b1 100644 --- a/src/video/sdl2_opengl_v.cpp +++ b/src/video/sdl2_opengl_v.cpp @@ -117,7 +117,7 @@ const char *VideoDriver_SDL_OpenGL::AllocateContext() ToggleVsync(_video_vsync); - return OpenGLBackend::Create(&GetOGLProcAddressCallback); + return OpenGLBackend::Create(&GetOGLProcAddressCallback, this->GetScreenSize()); } void VideoDriver_SDL_OpenGL::PopulateSystemSprites() diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 08ab27c53..19e186ae2 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -1380,7 +1380,7 @@ const char *VideoDriver_Win32OpenGL::AllocateContext() this->ToggleVsync(_video_vsync); this->gl_rc = rc; - return OpenGLBackend::Create(&GetOGLProcAddressCallback); + return OpenGLBackend::Create(&GetOGLProcAddressCallback, this->GetScreenSize()); } bool VideoDriver_Win32OpenGL::ToggleFullscreen(bool full_screen) |