Commits

Alex Szpakowski  committed 6bf7373

Graphics objects no longer get recreated every time the window is resized by the user

  • Participants
  • Parent commits 3255a21
  • Branches SDL2

Comments (0)

Files changed (4)

File src/modules/graphics/Graphics.h

 	virtual ~Graphics();
 
 	/**
+	 * Sets the current graphics display viewport dimensions.
+	 **/
+	virtual void setViewportSize(int width, int height) = 0;
+
+	/**
 	 * Sets the current graphics display viewport and initializes the renderer.
 	 * @param width The viewport width.
 	 * @param height The viewport height.

File src/modules/graphics/opengl/Graphics.cpp

 	setColorMask(s.colorMask[0], s.colorMask[1], s.colorMask[2], s.colorMask[3]);
 }
 
+void Graphics::setViewportSize(int width, int height)
+{
+	this->width = width;
+	this->height = height;
+
+	if (!isCreated())
+		return;
+
+	// Set the viewport to top-left corner
+	gl.setViewport(OpenGL::Viewport(0, 0, width, height));
+
+	// Reset the projection matrix
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+
+	// Set up orthographic view (no depth)
+	glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
+
+	glMatrixMode(GL_MODELVIEW);
+}
+
 bool Graphics::setMode(int width, int height)
 {
 	this->width = width;
 	// Okay, setup OpenGL.
 	gl.initContext();
 
+	created = true;
+
+	setViewportSize(width, height);
+
 	// Make sure antialiasing works when set elsewhere
 	if (GLEE_VERSION_1_3 || GLEE_ARB_multisample)
 		glEnable(GL_MULTISAMPLE);
 	glEnable(GL_TEXTURE_2D);
 	gl.setActiveTextureUnit(0);
 
-	// Set the viewport to top-left corner
-	gl.setViewport(OpenGL::Viewport(0, 0, width, height));
-
-	// Reset the projection matrix
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-
-	// Set up orthographic view (no depth)
-	glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
-
 	// Reset modelview matrix
 	glMatrixMode(GL_MODELVIEW);
 	glLoadIdentity();
 	glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &matrixLimit);
 	matrixLimit -= 5;
 
-	created = true;
-
 	return true;
 }
 

File src/modules/graphics/opengl/Graphics.h

 
 	void restoreState(const DisplayState &s);
 
+	virtual void setViewportSize(int width, int height);
 	virtual bool setMode(int width, int height);
 	virtual void unSetMode();
 

File src/modules/window/sdl/Window.cpp

 
 bool Window::Window::onWindowResize(int width, int height, graphics::Graphics *gfx)
 {
-	if (!window)
-		return false;
-
-	if ((SDL_GetWindowFlags(window) & SDL_WINDOW_RESIZABLE) == 0)
-		return false;
+	if (window)
+	{
+		currentMode.width = width;
+		currentMode.height = height;
+	}
 
 	if (gfx)
-		gfx->unSetMode();
-
-	currentMode.width = width;
-	currentMode.height = height;
-
-	// We may have to recreate the OpenGL context if it gets lost.
-	setContext(currentMode.flags.fsaa, currentMode.flags.vsync);
-
-	if (gfx)
-		gfx->setMode(width, height);
+		gfx->setViewportSize(width, height);
 
 	return true;
 }