← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~qcumber-some/widelands/bug1098263 into lp:widelands

 

Jens Beyer (Qcumber-some) has proposed merging lp:~qcumber-some/widelands/bug1098263 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1098263 in widelands: "Widelands does not start if PC has OpenGL problems"
  https://bugs.launchpad.net/widelands/+bug/1098263

For more details, see:
https://code.launchpad.net/~qcumber-some/widelands/bug1098263/+merge/174275

Ok, I tried to fix this.

The reason I had to split the init function is that the GL_EXTENSIONS seems to be available only late in the game (it looks like glewInit() does provide it).

Problem now is that it looks like we are leaking a sdlsurface instance there (check the TODO), or not? I am not sure.
And I am not sure if I found all possible paths in the code.

Please review thoroughly ;-)
-- 
https://code.launchpad.net/~qcumber-some/widelands/bug1098263/+merge/174275
Your team Widelands Developers is requested to review the proposed merge of lp:~qcumber-some/widelands/bug1098263 into lp:widelands.
=== modified file 'src/graphic/graphic.cc'
--- src/graphic/graphic.cc	2013-03-09 14:41:03 +0000
+++ src/graphic/graphic.cc	2013-07-11 19:21:43 +0000
@@ -149,6 +149,9 @@
 		log("Graphics: FULLSCREEN ENABLED\n");
 
 #ifdef USE_OPENGL
+	bool use_arb = true;
+	const char * extensions;
+
 	if (0 != (sdlsurface->flags & SDL_OPENGL)) {
 		//  We have successful opened an opengl screen. Print some information
 		//  about opengl and set the rendering capabilities.
@@ -160,9 +163,35 @@
 			throw wexception("glewInit returns %i: Broken OpenGL installation.", err);
 		}
 
+		extensions = reinterpret_cast<const char *>(glGetString (GL_EXTENSIONS));
+
+		if (strstr(extensions, "GL_ARB_framebuffer_object") != 0) {
+			use_arb = true;
+		} else if (strstr(extensions, "GL_EXT_framebuffer_object") != 0) {
+			use_arb = false;
+		}
+		else {
+			log
+			("Graphics: Neither GL_ARB_framebuffer_object or GL_EXT_framebuffer_object supported! "
+			"Switching off OpenGL!\n"
+			);
+			flags &= ~SDL_OPENGL;
+			m_fallback_settings_in_effect = true;
+
+			//TODO Do we have a leak of the old sdlsurface instance here?!
+			sdlsurface = SDL_SetVideoMode
+			(FALLBACK_GRAPHICS_WIDTH, FALLBACK_GRAPHICS_HEIGHT, FALLBACK_GRAPHICS_DEPTH, flags);
+			m_fallback_settings_in_effect = true;
+			if (!sdlsurface)
+				throw wexception
+				("Graphics: could not set video mode: %s", SDL_GetError());
+		}
+	}
+
+	if (0 != (sdlsurface->flags & SDL_OPENGL)) {
+		//  We now really have a working opengl screen...
 		g_opengl = true;
 
-
 		GLboolean glBool;
 		glGetBooleanv(GL_DOUBLEBUFFER, &glBool);
 		log
@@ -193,8 +222,6 @@
 			("Graphics: OpenGL: Version %d.%d \"%s\"\n",
 			 m_caps.gl.major_version, m_caps.gl.minor_version, str);
 
-		const char * extensions = reinterpret_cast<const char *>(glGetString (GL_EXTENSIONS));
-
 		m_caps.gl.tex_power_of_two =
 			(m_caps.gl.major_version < 2) and
 			(strstr(extensions, "GL_ARB_texture_non_power_of_two") == 0);
@@ -287,7 +314,7 @@
 		SDL_GL_SwapBuffers();
 		glEnable(GL_TEXTURE_2D);
 
-		GLSurfaceTexture::Initialize();
+		GLSurfaceTexture::Initialize(use_arb);
 
 	}
 

=== modified file 'src/graphic/render/gl_surface_texture.cc'
--- src/graphic/render/gl_surface_texture.cc	2013-02-10 18:47:18 +0000
+++ src/graphic/render/gl_surface_texture.cc	2013-07-11 19:21:43 +0000
@@ -30,27 +30,25 @@
 /**
  * Initial global resources needed for fast offscreen rendering.
  */
-void GLSurfaceTexture::Initialize() {
-	const char * extensions = reinterpret_cast<const char *>(glGetString (GL_EXTENSIONS));
+void GLSurfaceTexture::Initialize(bool use_arb) {
+	use_arb_ = use_arb;
 
 	// Generate the framebuffer for Offscreen rendering.
 	bool fbs = false;
-	if (strstr(extensions, "GL_ARB_framebuffer_object") != 0) {
+	if (use_arb) {
 		fbs = true;
-		use_arb_ = true;
 		glGenFramebuffers(1, &gl_framebuffer_id_);
 		glBindFramebuffer(GL_FRAMEBUFFER, 0);
-	} else if (strstr(extensions, "GL_EXT_framebuffer_object") != 0) {
+	} else {
 		fbs = true;
-		use_arb_ = false;
 		glGenFramebuffersEXT(1, &gl_framebuffer_id_);
 		glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
 	}
 	if (!fbs) {
 		throw wexception
-			("No support for GL_ARB_framebuffer_object or GL_ARB_framebuffer_object "
-			 "in OpenGL implementation. One of these is needed for Widelands in OpenGL mode. You can "
-			 "try launching Widelands with --opengl=0.");
+			("Could not initialize framebuffer for OpenGL. Your video card reported "
+			"sufficient capabilities, but it did not work. You can "
+			"try launching Widelands with --opengl=0.");
 	}
 }
 

=== modified file 'src/graphic/render/gl_surface_texture.h'
--- src/graphic/render/gl_surface_texture.h	2013-02-10 17:39:24 +0000
+++ src/graphic/render/gl_surface_texture.h	2013-07-11 19:21:43 +0000
@@ -27,7 +27,7 @@
 public:
 	// Call this once before using any instance of this class and Cleanup once
 	// before the program exits.
-	static void Initialize();
+	static void Initialize(bool use_arb);
 	static void Cleanup();
 
 	GLSurfaceTexture(SDL_Surface * surface, bool intensity = false);


Follow ups