Browse Source

Font texture atlases can be created in Core Profile GL3.

--HG--
branch : minor
Alex Szpakowski 8 years ago
parent
commit
22c4d1ae79

+ 8 - 0
src/modules/graphics/opengl/Font.cpp

@@ -85,6 +85,14 @@ void Font::createTexture()
 	bool sRGB = isGammaCorrect();
 	OpenGL::TextureFormat fmt = gl.convertPixelFormat(pixelFormat, false, sRGB);
 
+	if (fmt.swizzled)
+	{
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, fmt.swizzle[0]);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, fmt.swizzle[1]);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, fmt.swizzle[2]);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, fmt.swizzle[3]);
+	}
+
 	// Initialize the texture with transparent black.
 	std::vector<GLubyte> emptydata(size.width * size.height * bpp, 0);
 

+ 15 - 3
src/modules/graphics/opengl/OpenGL.cpp

@@ -868,9 +868,21 @@ OpenGL::TextureFormat OpenGL::convertPixelFormat(PixelFormat pixelformat, bool r
 		break;
 
 	case PIXELFORMAT_LA8:
-		f.internalformat = GL_LUMINANCE8_ALPHA8;
-		f.externalformat = GL_LUMINANCE_ALPHA;
-		f.type = GL_UNSIGNED_BYTE;
+		if (gl.isCoreProfile() || GLAD_ES_VERSION_3_0)
+		{
+			f.internalformat = GL_RG8;
+			f.externalformat = GL_RG;
+			f.type = GL_UNSIGNED_BYTE;
+			f.swizzled = true;
+			f.swizzle[0] = f.swizzle[1] = f.swizzle[2] = GL_RED;
+			f.swizzle[3] = GL_GREEN;
+		}
+		else
+		{
+			f.internalformat = GL_LUMINANCE8_ALPHA8;
+			f.externalformat = GL_LUMINANCE_ALPHA;
+			f.type = GL_UNSIGNED_BYTE;
+		}
 		break;
 
 	case PIXELFORMAT_RGBA4:

+ 3 - 0
src/modules/graphics/opengl/OpenGL.h

@@ -92,6 +92,9 @@ public:
 		GLenum internalformat = 0;
 		GLenum externalformat = 0;
 		GLenum type = 0;
+
+		bool swizzled = false;
+		GLint swizzle[4];
 	};
 
 	class TempDebugGroup