Author Topic: Making S3TC work with Mesa without libtxc_dxtn  (Read 3792 times)

0 Members and 1 Guest are viewing this topic.

Offline Plombo

  • 23
Making S3TC work with Mesa without libtxc_dxtn
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. :)

 

Offline kkmic

  • 26
Re: Making S3TC work with Mesa without libtxc_dxtn
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.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I've watched C-beams glitter in the dark near the Tannhäuser Gate. All those... moments will be lost in time... like... tears... in rain. (pause) Time... to die.

wxLauncher 0.9.4 Beta | wxLauncher 2.0 Request for Comments

 

Offline Plombo

  • 23
Re: Making S3TC work with Mesa without libtxc_dxtn
Could someone please commit this patch?  There are no negative side effects. :)

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Steam
    • Twitter
    • ModDB Feature
Re: Making S3TC work with Mesa without libtxc_dxtn

Committed to Trunk r7381.
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline Plombo

  • 23
Re: Making S3TC work with Mesa without libtxc_dxtn

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. :)
« Last Edit: July 26, 2011, 09:48:24 am by Plombo »

  

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: Making S3TC work with Mesa without libtxc_dxtn
Awesome news!  Always glad to see improved cross platform support.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays