From 8038ce5dc3e8f5a728f500cfc9adf98f30ec45b9 Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Thu, 6 Mar 2014 16:16:58 +0000
Subject: [PATCH] [Add] More FSAA awareness.

---
 src/opengl.c | 22 +++++++++++++---------
 src/opengl.h |  2 +-
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/opengl.c b/src/opengl.c
index 2ccf94b..07f521c 100644
--- a/src/opengl.c
+++ b/src/opengl.c
@@ -857,7 +857,7 @@ void gl_checkErr(void) {
 
 /* Initialize SDL/OpenGL etc. */
 int gl_init(void) {
-  int doublebuf, depth, i, j, off, toff, supported;
+  int doublebuf, depth, i, j, off, toff, supported, fsaa;
   SDL_Rect** modes;
   int flags = SDL_OPENGL;
   flags |= SDL_FULLSCREEN * (gl_has(OPENGL_FULLSCREEN) ? 1: 0);
@@ -946,7 +946,7 @@ int gl_init(void) {
   /* Actually creating the screen. */
   if(SDL_SetVideoMode(SCREEN_W, SCREEN_H, gl_screen.depth, flags) == NULL) {
     if(gl_has(OPENGL_FSAA)) {
-      LOG("Disablin FSAA.");
+      LOG("Unable to create OpenGL window: Trying without FSAA.");
       gl_screen.flags &= ~OPENGL_FSAA;
       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
@@ -958,11 +958,12 @@ int gl_init(void) {
   }
 
   /* Grab some info. */
-  SDL_GL_GetAttribute(SDL_GL_RED_SIZE,      &gl_screen.r);
-  SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE,    &gl_screen.g);
-  SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE,     &gl_screen.b);
-  SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE,    &gl_screen.a);
-  SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER,  &doublebuf);
+  SDL_GL_GetAttribute(SDL_GL_RED_SIZE,            &gl_screen.r);
+  SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE,          &gl_screen.g);
+  SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE,           &gl_screen.b);
+  SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE,          &gl_screen.a);
+  SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER,        &doublebuf);
+  SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES,  &fsaa);
   if(doublebuf) gl_screen.flags |= OPENGL_DOUBLEBUF;
   gl_screen.depth = gl_screen.r + gl_screen.g + gl_screen.b + gl_screen.a;
 
@@ -980,10 +981,10 @@ int gl_init(void) {
   DEBUG("OpenGL Window Created: %dx%d@%dbpp %s", SCREEN_W, SCREEN_H,
         gl_screen.depth, (gl_has(OPENGL_FULLSCREEN)) ? "fullscreen" : "window");
 
-  DEBUG("r: %d, g: %d, b: %d, a: %d, db: %s, tex: %d",
+  DEBUG("r: %d, g: %d, b: %d, a: %d, db: %s, fsaa: %d, tex: %d",
         gl_screen.r, gl_screen.g, gl_screen.b, gl_screen.a,
         gl_has(OPENGL_DOUBLEBUF) ? "yes" : "no",
-        gl_screen.tex_max);
+        fsaa, gl_screen.tex_max);
 
   DEBUG("Renderer: %s", glGetString(GL_RENDERER));
   DEBUG("Version: %s", glGetString(GL_VERSION));
@@ -991,6 +992,9 @@ int gl_init(void) {
   if(gl_screen.multitex_max < OPENGL_REQ_MULTITEX)
     WARN("Missing texture units (%d required, %d found)",
         OPENGL_REQ_MULTITEX, gl_screen.multitex_max);
+  if(gl_has(OPENGL_FSAA) && (fsaa != gl_screen.fsaa))
+    WARN("Unable to get requested fsaa level (%d requested, got %d)",
+        gl_screen.fsaa, fsaa);
   if(!gl_has(OPENGL_FRAG_SHADER))
     DEBUG("No fragment shader extension detected"); /* Not a warning yet. */
   DEBUG("");
diff --git a/src/opengl.h b/src/opengl.h
index 94f0971..41ba7a1 100644
--- a/src/opengl.h
+++ b/src/opengl.h
@@ -48,7 +48,7 @@ typedef struct glInfo_ {
   int flags;        /**< Store different properties. */
   int tex_max;      /**< Max texture size. */
   int multitex_max; /**< Max multitexture levels. */
-  int fsaa;         /**< Full scene Anti-Aliasing level. */
+  int fsaa;         /**< Full screen Anti-Aliasing level. */
 } glInfo;
 extern glInfo gl_screen; /* Local structure set with gl_init etc. */