foxygit / doom Log in
commit e82b4c186cc1f2e65414c211c3db9c84bd2c3cdf
Author:     Jonathan Dowland <jon+github@alcopop.org>
AuthorDate: Tue Jul 12 17:47:35 2016 +0100
Commit:     Jonathan Dowland <jon+github@alcopop.org>
CommitDate: Wed Jul 13 17:06:57 2016 +0100

    Add CheckGLVersion to warn about software GL

    Performance with a software GL implementation is not great. Check
    the GL_VERSION string and warn about possible performance problems
    if we find "Mesa", suggesting hardware acceleration is not
    available.

    Additional LDFLAGS are needed for OS X when using SDL_opengl.h,
    adjust configure.ac accordingly.

    Fixes #741.
---
 configure.ac  |  7 +++++++
 src/i_video.c | 22 ++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/configure.ac b/configure.ac
index 47cb3353..064a3cbf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,6 +39,13 @@ PKG_CHECK_MODULES(SDLMIXER, [SDL2_mixer >= 2.0.0])
 PKG_CHECK_MODULES(SDLNET, [SDL2_net >= 2.0.0])
 PKG_CHECK_MODULES(SDLIMAGE, [SDL2_image >= 2.0.0])

+# Additional LDFLAGS for OS X are required for OpenGL
+case "$host" in
+  *-darwin*)
+    LDFLAGS="$LDFLAGS -framework OpenGL"
+    ;;
+esac
+
 # Check for libsamplerate.
 AC_ARG_WITH([libsamplerate],
 AS_HELP_STRING([--without-libsamplerate],
diff --git a/src/i_video.c b/src/i_video.c
index ea0d5300..1a7fcfbe 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -19,6 +19,7 @@

 #include "SDL.h"
 #include "SDL_image.h"
+#include "SDL_opengl.h"

 #ifdef _WIN32
 #define WIN32_LEAN_AND_MEAN
@@ -1147,6 +1148,23 @@ static void SetVideoMode(void)
     CreateUpscaledTexture();
 }

+static const char *hw_emu_warning =
+"===========================================================================\n"
+"WARNING: it looks like you are using a software GL implementation.\n"
+"To improve performance, try setting force_software_renderer in your\n"
+"configuration file.\n"
+"===========================================================================\n";
+
+static void CheckGLVersion(void)
+{
+    const GLubyte* version = glGetString(GL_VERSION);
+
+    if (version && strstr((const char *)version, "Mesa"))
+    {
+        printf("%s", hw_emu_warning);
+    }
+}
+
 void I_InitGraphics(void)
 {
     SDL_Event dummy;
@@ -1189,6 +1207,10 @@ void I_InitGraphics(void)
     AdjustWindowSize();
     SetVideoMode();

+    // We might have poor performance if we are using an emulated
+    // HW accelerator. Check for Mesa and warn if we're using it.
+    CheckGLVersion();
+
     // Start with a clear black screen
     // (screen will be flipped after we set the palette)