Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Plombo on July 20, 2011, 11:00:29 pm

Title: Making S3TC work with Mesa without libtxc_dxtn
Post by: Plombo on July 20, 2011, 11:00:29 pm
As some of you might know, OpenGL drivers using Mesa don't support compression of S3TC textures since the encoding algorithm is patented; since the GL_EXT_texture_compression_s3tc extension requires the driver to do this as well as accept precompressed textures, Mesa doesn't advertise the extension.  This makes FSO not work with Mesa unless the legally questionable  libtxc_dxtn library is used.

But since the MediaVPs only use precompressed S3TC textures, FSO doesn't care whether the driver can encode S3TC textures, and Mesa can handle precompressed textures with no problem.  There is a driconf option called force_s3tc_enable that makes Mesa advertise S3TC support even without libtxc_dxtn present.  The following patch makes FSO set that environment variable before creating an OpenGL context for the first time:

Code: [Select]
diff --git a/code/graphics/gropengl.cpp b/code/graphics/gropengl.cpp
index 47a5737..2e5ede6 100644
--- a/code/graphics/gropengl.cpp
+++ b/code/graphics/gropengl.cpp
@@ -1659,6 +1659,9 @@ int opengl_init_display_device()
 
  SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (fsaa_samples == 0) ? 0 : 1);
  SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa_samples);
+
+ // Slight hack to make Mesa advertise S3TC support without libtxc_dxtn
+ setenv("force_s3tc_enable", "true", 1);
 
  mprintf(("  Requested SDL Video values = R: %d, G: %d, B: %d, depth: %d, double-buffer: %d, FSAA: %d\n", Gr_red.bits, Gr_green.bits, Gr_blue.bits, (bpp == 32) ? 24 : 16, db, fsaa_samples));
 

This should work out of the box with all Mesa DRI drivers - in other words, for people using Intel hardware on Linux, and some Radeon users with the older driver.  The only problem with this is that Gallium drivers (used for the open-source Nvidia and AMD drivers) don't currently support the force_s3tc_enable environment variable.  However, I sent 2 small patches to the Mesa mailing list earlier today that fix this shortcoming in Gallium.  So it's likely that this fix will work for Gallium drivers as well in the future. :)
Title: Re: Making S3TC work with Mesa without libtxc_dxtn
Post by: kkmic on July 21, 2011, 01:42:04 am
Great news!

I am one of the Radeon X1650 Linux users.

Let's hope this gets reviewed and committed to the trunk soon enough.

Thanks Plombo.
Title: Re: Making S3TC work with Mesa without libtxc_dxtn
Post by: Plombo on July 25, 2011, 02:40:18 pm
Could someone please commit this patch?  There are no negative side effects. :)
Title: Re: Making S3TC work with Mesa without libtxc_dxtn
Post by: Zacam on July 25, 2011, 11:33:44 pm

Committed to Trunk r7381.
Title: Re: Making S3TC work with Mesa without libtxc_dxtn
Post by: Plombo on July 26, 2011, 09:38:32 am

Committed to Trunk r7381.


Thanks! :)

I've gotten the green light to push my Gallium patches to Mesa, so this patch should work with Gallium drivers, probably starting with Mesa 7.11.1. :)
Title: Re: Making S3TC work with Mesa without libtxc_dxtn
Post by: chief1983 on July 26, 2011, 05:39:25 pm
Awesome news!  Always glad to see improved cross platform support.