Commits

Alex Szpakowski committed 770ce11

Code cleanup

Comments (0)

Files changed (6)

src/modules/graphics/opengl/Graphics.cpp

 	catch(love::Exception &e)
 	{
 		image->release();
-		throw love::Exception(e.what());
+		throw;
 	}
 	if (!success)
 	{

src/modules/graphics/opengl/Image.cpp

 	drawv(t, v);
 }
 
+void Image::checkMipmapsCreated() const
+{
+	if (filter.mipmap != FILTER_NEAREST && filter.mipmap != FILTER_LINEAR)
+		return;
+	
+	if (!hasMipmapSupport())
+		throw love::Exception("Mipmap filtering is not supported on this system!");
+	
+	// some old GPUs/systems claim support for NPOT textures, but fail when generating mipmaps
+	// we can't detect which systems will do this, so we fail gracefully for all NPOT images
+	int w = int(width), h = int(height);
+	if (w != next_p2(w) || h != next_p2(h))
+		throw love::Exception("Could not generate mipmaps: image does not have power of two dimensions!");
+	
+	bind();
+	
+	GLboolean mipmapscreated;
+	glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, (GLint *)&mipmapscreated);
+	
+	// generate mipmaps for this image if we haven't already
+	if (!mipmapscreated)
+	{
+		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
+		
+		if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)
+			glGenerateMipmap(GL_TEXTURE_2D);
+		else if (GLEE_EXT_framebuffer_object)
+			glGenerateMipmapEXT(GL_TEXTURE_2D);
+		else
+			// modify single texel to trigger mipmap chain generation
+			glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data->getData());
+	}
+}
+
 void Image::setFilter(const Image::Filter &f)
 {
 	filter = f;
 	
 	bind();
-	
-	if (f.mipmap == FILTER_NEAREST || f.mipmap == FILTER_LINEAR)
-	{
-		if (!hasMipmapSupport())
-			throw love::Exception("Mipmap filtering is not supported on this system!");
-		
-		// some old GPUs/systems claim support for NPOT textures, but fail when generating mipmaps for them
-		// we can't detect which systems will do this, so it's better to fail gracefully for all NPOT images
-		int w = int(width), h = int(height);
-		if (w != next_p2(w) || h != next_p2(h))
-			throw love::Exception("Could not generate mipmaps: image does not have power of two dimensions!");
-		
-		GLboolean mipmapscreated;
-		glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, (GLint *)&mipmapscreated);
-		
-		// generate mipmaps for this image if we haven't already
-		if (!mipmapscreated)
-		{
-			glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
-			
-			if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)
-				glGenerateMipmap(GL_TEXTURE_2D);
-			else if (GLEE_EXT_framebuffer_object)
-				glGenerateMipmapEXT(GL_TEXTURE_2D);
-			else
-				// modify single texel in texture to trigger mipmap chain generation
-				glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data->getData());
-		}
-	}
-	
+	checkMipmapsCreated();
 	setTextureFilter(f);
 }
 
 	return filter;
 }
 
-void Image::setWrap(Image::Wrap &w)
+void Image::setWrap(const Image::Wrap &w)
 {
 	wrap = w;
 	
 
 void Image::setMipmapSharpness(float sharpness)
 {
-	if (!(GLEE_VERSION_1_4 || GLEE_EXT_texture_lod_bias))
+	if (!hasMipmapSharpnessSupport())
 		return;
 	
 	// LOD bias has the range (-maxbias, maxbias)
 
 bool Image::loadVolatile()
 {
-	if (GLEE_VERSION_1_4 || GLEE_EXT_texture_lod_bias)
+	if (hasMipmapSharpnessSupport())
 		glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &maxmipmapsharpness);
 	
 	if (hasNpot())
 	return (GLEE_VERSION_1_4 || GLEE_SGIS_generate_mipmap) != 0;
 }
 
+bool Image::hasMipmapSharpnessSupport()
+{
+	return (GLEE_VERSION_1_4 || GLEE_EXT_texture_lod_bias) != 0;
+}
+
 } // opengl
 } // graphics
 } // love

src/modules/graphics/opengl/Image.h

 
 	/**
 	 * Sets the filter mode.
-	 *
 	 * @param f The filter mode.
 	 **/
 	void setFilter(const Image::Filter &f);
 
 	const Image::Filter &getFilter() const;
 
-	void setWrap(Image::Wrap &w);
+	void setWrap(const Image::Wrap &w);
 
 	const Image::Wrap &getWrap() const;
 	
 
 	static bool hasNpot();
 	static bool hasMipmapSupport();
+	static bool hasMipmapSharpnessSupport();
 
 private:
 
 	// Mipmap texture LOD bias value
 	float mipmapsharpness;
 	
-	// Implementation-dependent maximum/minimum sharpness values
+	// Implementation-dependent maximum/minimum mipmap sharpness values
 	float maxmipmapsharpness;
 	
 	// The image's filter mode
 
 	bool loadVolatilePOT();
 	bool loadVolatileNPOT();
+	
+	void checkMipmapsCreated() const;
 
 }; // Image
 

src/modules/graphics/opengl/wrap_Canvas.cpp

 {
 	Canvas *canvas = luax_checkcanvas(L, 1);
 	
-	Image::FilterMode min;
-	Image::FilterMode mag;
+	Image::Filter f;
 	
 	const char *minstr = luaL_checkstring(L, 2);
 	const char *magstr = luaL_optstring(L, 3, minstr);
 	
-	if (!Image::getConstant(minstr, min))
+	if (!Image::getConstant(minstr, f.min))
 		return luaL_error(L, "Invalid filter mode: %s", minstr);
-	if (!Image::getConstant(magstr, mag))
+	if (!Image::getConstant(magstr, f.mag))
 		return luaL_error(L, "Invalid filter mode: %s", magstr);
 	
-	Image::Filter f;
-	f.min = min;
-	f.mag = mag;
-	
 	canvas->setFilter(f);
 	
 	return 0;
 int w_Canvas_getFilter(lua_State *L)
 {
 	Canvas *canvas = luax_checkcanvas(L, 1);
-	Image::Filter f = canvas->getFilter();
+	const Image::Filter f = canvas->getFilter();
 
 	const char *minstr;
 	const char *magstr;
 {
 	Canvas *canvas = luax_checkcanvas(L, 1);
 	
-	Image::WrapMode s;
-	Image::WrapMode t;
+	Image::Wrap w;
 	
 	const char *sstr = luaL_checkstring(L, 2);
 	const char *tstr = luaL_optstring(L, 3, sstr);
 	
-	if (!Image::getConstant(sstr, s))
+	if (!Image::getConstant(sstr, w.s))
 		return luaL_error(L, "Invalid wrap mode: %s", sstr);
-	if (!Image::getConstant(tstr, t))
+	if (!Image::getConstant(tstr, w.t))
 		return luaL_error(L, "Invalid wrap mode, %s", tstr);
 	
-	Image::Wrap w;
-	w.s = s;
-	w.t = t;
-	
 	canvas->setWrap(w);
 	
 	return 0;
 int w_Canvas_getWrap(lua_State *L)
 {
 	Canvas *canvas = luax_checkcanvas(L, 1);
-	Image::Wrap w = canvas->getWrap();
+	const Image::Wrap w = canvas->getWrap();
 
 	const char *wrap_s;
 	const char *wrap_t;

src/modules/graphics/opengl/wrap_Font.cpp

 {
 	Font *t = luax_checkfont(L, 1);
 	
-	Image::FilterMode min;
-	Image::FilterMode mag;
+	Image::Filter f;
 	
 	const char *minstr = luaL_checkstring(L, 2);
 	const char *magstr = luaL_optstring(L, 3, minstr);
 	
-	if (!Image::getConstant(minstr, min))
+	if (!Image::getConstant(minstr, f.min))
 		return luaL_error(L, "Invalid filter mode: %s", minstr);
-	if (!Image::getConstant(magstr, mag))
+	if (!Image::getConstant(magstr, f.mag))
 		return luaL_error(L, "Invalid filter mode: %s", magstr);
 	
-	Image::Filter f;
-	f.min = min;
-	f.mag = mag;
-	
 	t->setFilter(f);
 	
 	return 0;
 int w_Font_getFilter(lua_State *L)
 {
 	Font *t = luax_checkfont(L, 1);
-	Image::Filter f = t->getFilter();
-	Image::FilterMode min = f.min;
-	Image::FilterMode mag = f.mag;
+	const Image::Filter f = t->getFilter();
 	const char *minstr;
 	const char *magstr;
-	Image::getConstant(min, minstr);
-	Image::getConstant(mag, magstr);
+	Image::getConstant(f.min, minstr);
+	Image::getConstant(f.mag, magstr);
 	lua_pushstring(L, minstr);
 	lua_pushstring(L, magstr);
 	return 2;

src/modules/graphics/opengl/wrap_Image.cpp

 	const Image::Filter f = t->getFilter();
 	const char *minstr;
 	const char *magstr;
-	const char *mipmapstr;
 	Image::getConstant(f.min, minstr);
 	Image::getConstant(f.mag, magstr);
 	lua_pushstring(L, minstr);
 	lua_pushstring(L, magstr);
 	
+	const char *mipmapstr;
 	if (Image::getConstant(f.mipmap, mipmapstr))
 		lua_pushstring(L, mipmapstr);
 	else
 int w_Image_getMipmapSharpness(lua_State *L)
 {
 	Image *i = luax_checkimage(L, 1);
-	
-	float sharpness = i->getMipmapSharpness();
-	lua_pushnumber(L, sharpness);
-	
+	lua_pushnumber(L, i->getMipmapSharpness());
 	return 1;
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.