Commits

Alex Szpakowski committed 2991a1c

Added mipmap support to Image filter struct and OpenGL texture filter helper functions

  • Participants
  • Parent commits 1bf09d0

Comments (0)

Files changed (3)

File src/modules/graphics/Image.cpp

 Image::Filter::Filter()
 	: min(FILTER_LINEAR)
 	, mag(FILTER_LINEAR)
+	, mipmap(FILTER_NONE)
 {
 }
 

File src/modules/graphics/Image.h

 	{
 		FILTER_LINEAR = 1,
 		FILTER_NEAREST,
+		FILTER_NONE,
 		FILTER_MAX_ENUM
 	};
 
 		Filter();
 		FilterMode min;
 		FilterMode mag;
+		FilterMode mipmap;
 	};
 
 	struct Wrap

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

 {
 	GLint gmin, gmag;
 	
-	switch (f.min)
+	if (f.mipmap == Image::FILTER_NONE)
 	{
-	case Image::FILTER_NEAREST:
-		gmin = GL_NEAREST;
-		break;
-	case Image::FILTER_LINEAR:
-	default:
-		gmin = GL_LINEAR;
-		break;
+		if (f.min == Image::FILTER_NEAREST)
+			gmin = GL_NEAREST;
+		else // f.min == Image::FILTER_LINEAR
+			gmin = GL_LINEAR;
 	}
+	else
+	{
+		if (f.min == f.mipmap == Image::FILTER_NEAREST)
+			gmin = GL_NEAREST_MIPMAP_NEAREST;
+		else if (f.min == Image::FILTER_NEAREST && f.mipmap == Image::FILTER_LINEAR)
+			gmin = GL_NEAREST_MIPMAP_LINEAR;
+		else if (f.min == Image::FILTER_LINEAR && f.mipmap == Image::FILTER_NEAREST)
+			gmin = GL_LINEAR_MIPMAP_NEAREST;
+		else if (f.min == f.mipmap == Image::FILTER_LINEAR)
+			gmin = GL_LINEAR_MIPMAP_LINEAR;
+		else
+			gmin = GL_LINEAR;
+	}
+	
 	
 	switch (f.mag)
 	{
 	{
 	case GL_NEAREST:
 		f.min = Image::FILTER_NEAREST;
+		f.mipmap = Image::FILTER_NONE;
+		break;
+	case GL_NEAREST_MIPMAP_NEAREST:
+		f.min = f.mipmap = Image::FILTER_NEAREST;
+		break;
+	case GL_NEAREST_MIPMAP_LINEAR:
+		f.min = Image::FILTER_NEAREST;
+		f.mipmap = Image::FILTER_LINEAR;
+		break;
+	case GL_LINEAR_MIPMAP_NEAREST:
+		f.min = Image::FILTER_LINEAR;
+		f.mipmap = Image::FILTER_NEAREST;
+		break;
+	case GL_LINEAR_MIPMAP_LINEAR:
+		f.min = f.mipmap = Image::FILTER_LINEAR;
 		break;
 	case GL_LINEAR:
 	default:
 		f.min = Image::FILTER_LINEAR;
+		f.mipmap = Image::FILTER_NONE;
 		break;
 	}