Commits

Alex Szpakowski  committed 8dc3d7f

love.graphics.polygon("fill", ...) now uses GL_TRIANGLE_FAN instead of GL_POLYGON; removed the last instances of deprecated glPop/glPush functions in favour of state tracking handled by the program.

  • Participants
  • Parent commits 4c62d46
  • Branches GLES2-compatibility

Comments (0)

Files changed (4)

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

 	if (current != NULL)
 		previous = current->fbo;
 
+	Context *ctx = getContext();
+
 	strategy->bindFBO(fbo);
-	glPushAttrib(GL_COLOR_BUFFER_BIT);
-	glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f);
+
+	Color prevcolor = ctx->getClearColor();
+	ctx->setClearColor(c);
+
 	glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-	glPopAttrib();
+
+	ctx->setClearColor(prevcolor);
 
 	strategy->bindFBO(previous);
 }

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

 	glGetFloatv(GL_CURRENT_COLOR, color);
 	state.color = Color(color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255);
 
+	// get the current clear color
+	glGetFloatv(GL_COLOR_CLEAR_VALUE, color);
+	state.clearColor = Color(color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255);
+
 	// get the current point size
 	glGetFloatv(GL_POINT_SIZE, &state.pointSize);
 
 
 void Context::setBlendState(const Context::BlendState &s)
 {
-	if (GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_4 || GLEW_ARB_imaging)
-		glBlendEquation(s.function);
-	else if (GLEW_EXT_blend_minmax && GLEW_EXT_blend_subtract)
-		glBlendEquationEXT(s.function);
-	else if (s.function != GL_FUNC_ADD)
+	if (s.function != state.blend.function)
 	{
-		if (s.function == GL_FUNC_REVERSE_SUBTRACT)
-			throw love::Exception("This graphics card does not support the subtract blend mode!");
-		else
-			throw love::Exception("This graphics card does not support this blend mode!");
+		if (GLEW_ES_VERSION_2_0 || GLEW_VERSION_1_4 || GLEW_ARB_imaging)
+			glBlendEquation(s.function);
+		else if (GLEW_EXT_blend_minmax && GLEW_EXT_blend_subtract)
+			glBlendEquationEXT(s.function);
+		else if (s.function != GL_FUNC_ADD)
+		{
+			if (s.function == GL_FUNC_REVERSE_SUBTRACT)
+				throw love::Exception("This graphics card does not support the subtract blend mode!");
+			else
+				throw love::Exception("This graphics card does not support this blend mode!");
+		}
 	}
 
-	glBlendFunc(s.source, s.destination);
+	if (s.source != state.blend.source || s.destination != state.blend.destination)
+		glBlendFunc(s.source, s.destination);
 
 	state.blend = s;
 }
 
 void Context::setPointSize(float size)
 {
-	state.pointSize = size;
-
 	// GLES2 can only set the point size with gl_PointSize in shaders
 	if (!GLEW_ES_VERSION_2_0)
 		glPointSize((GLfloat) size);
+
+	state.pointSize = size;
 }
 
 float Context::getPointSize() const
 	return state.maxPointSize;
 }
 
+void Context::setClearColor(const Color &color)
+{
+	glClearColor(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
+	state.clearColor = color;
+}
+
+const Color &Context::getClearColor() const
+{
+	return state.clearColor;
+}
+
 void Context::setActiveTextureUnit(int textureunit)
 {
 	if (textureunit < 0 || (size_t) textureunit >= state.textureUnits.size())

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

 		GLsizei width, height;
 
 		Viewport() : x(0), y(0), width(0), height(0) { };
-		
 		Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
 		: x(x), y(y), width(width), height(height) { };
 	};
 	void setViewport(GLint x, GLint y, GLsizei width, GLsizei height);
 
 	/**
-	 * Returns the last window viewport set with setViewport.
+	 * Gets the last window viewport set with setViewport.
 	 **/
 	const Viewport &getViewport() const;
 
 	bool isGenericVertexAttrib(unsigned int attrib) const;
 
 	/**
-	 * Returns the OpenGL representation of the specified vertex attribute.
+	 * Gets the OpenGL representation of the specified vertex attribute.
 	 * Will be the attribute index for generic vertex attributes, or a
 	 * GL_*_ARRAY for fixed-function ones.
 	 *
 	void setPointSize(float size);
 
 	/**
-	 * Returns the current point size.
+	 * Gets the current point size.
 	 **/
 	float getPointSize() const;
 
 	/**
-	 * Returns the implementation-dependent maximum point size.
+	 * Gets the implementation-dependent maximum point size.
 	 **/
 	float getMaxPointSize() const;
 
 	/**
-	 * Sets the current blend mode.
+	 * Sets the current blend state.
 	 **/
 	void setBlendState(const BlendState &s);
 	void setBlendState(GLenum function, GLenum source, GLenum destination);
 
 	/**
-	 * Returns the currently set blend mode state.
+	 * Gets the current blend state.
 	 **/
 	const BlendState &getBlendState() const;
 
 	/**
+	 * Sets the color used when clearing the screen for the currently active
+	 * framebuffer.
+	 **/
+	void setClearColor(const Color &color);
+
+	/**
+	 * Gets the last clear color set using setClearColor. May be different from
+	 * the clear color on the currently active framebuffer!
+	 **/
+	const Color &getClearColor() const;
+
+	/**
 	 * Sets the active texture unit.
 	 *
 	 * @param textureunit Index in the range of [0, maxtextureunits-1]
 	void bindTextureToUnit(GLuint texture, int textureunit, bool restoreprev);
 
 	/**
-	 * Returns the number of texture units supported on the current system.
+	 * Gets the number of texture units supported on the current system.
 	 **/
 	int getNumTextureUnits() const { return state.textureUnits.size(); };
 
 	void setTextureFilter(const graphics::Image::Filter &f) const;
 
 	/**
-	 * Returns the image filter mode for the currently bound texture.
+	 * Gets the image filter mode for the currently bound texture.
 	 */
 	graphics::Image::Filter getTextureFilter() const;
 
 	void setTextureWrap(const graphics::Image::Wrap &w) const;
 
 	/**
-	 * Returns the image wrap mode for the currently bound texture.
+	 * Gets the image wrap mode for the currently bound texture.
 	 */
 	graphics::Image::Wrap getTextureWrap() const;
 
 		// Current color.
 		Color color;
 
+		// The last clear color set with setClearColor.
+		Color clearColor;
+
 		float pointSize;
 		float maxPointSize;
 

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

 
 	// Enable line/point smoothing.
 	setLineStyle(LINE_SMOOTH);
-	ctx->setCapability(GL_POINT_SMOOTH, true);
+	setPointStyle(POINT_SMOOTH);
+
 	glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
 
 	// Auto-generated mipmaps should be the best quality possible
 
 void Graphics::setBackgroundColor(const Color &c)
 {
-	glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f);
+	getContext()->setClearColor(c);
 }
 
 Color Graphics::getBackgroundColor()
 {
+	// We shouldn't use getContext()->getClearColor() because it returns the
+	// last set color regardless of the currently bound canvas, instead of the
+	// currently set color on the currently active canvas.
+
 	float c[4];
 	glGetFloatv(GL_COLOR_CLEAR_VALUE, c);
 
-	Color t;
-	t.r = (unsigned char)(255.0f*c[0]);
-	t.g = (unsigned char)(255.0f*c[1]);
-	t.b = (unsigned char)(255.0f*c[2]);
-	t.a = (unsigned char)(255.0f*c[3]);
+	Color t(c[0]*255, c[1]*255, c[2]*255, c[3]*255);
 
 	return t;
 }
 		Context *ctx = getContext();
 		ctx->bindTexture(0);
 		ctx->useVertexAttribArrays(Context::ATTRIB_VERTEX);
-		ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, 0, (const GLvoid *)coords);
+		ctx->vertexAttribPointer(Context::ATTRIB_VERTEX, 2, GL_FLOAT, 0, (const GLvoid *) coords);
 
 		ctx->setupRender();
-		glDrawArrays(GL_POLYGON, 0, count/2-1); // opengl will close the polygon for us
+		glDrawArrays(GL_TRIANGLE_FAN, 0, count/2-1); // opengl will close the polygon for us
 	}
 }
 
 		memcpy(dst-=row, src+=row, row);
 	}
 
-	love::image::ImageData *img = image->newImageData(w, h, (void *)screenshot);
+	love::image::ImageData *img = image->newImageData(w, h, (void *) screenshot);
 
 	delete [] pixels;
 	delete [] screenshot;