]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/slider_picmip.c
make the texture compression control sensitive towards support of the feature
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / slider_picmip.c
1 #ifdef INTERFACE
2 CLASS(XonoticPicmipSlider) EXTENDS(XonoticTextSlider)
3         METHOD(XonoticPicmipSlider, configureXonoticPicmipSlider, void(entity))
4         METHOD(XonoticPicmipSlider, draw, void(entity))
5         METHOD(XonoticPicmipSlider, autofix, void(entity))
6         ATTRIB(XonoticPicmipSlider, have_s3tc, float, 0)
7 ENDCLASS(XonoticPicmipSlider)
8 entity makeXonoticPicmipSlider(); // note: you still need to call addValue and configureXonoticTextSliderValues!
9 #endif
10
11 #ifdef IMPLEMENTATION
12 entity makeXonoticPicmipSlider()
13 {
14         entity me;
15         me = spawnXonoticPicmipSlider();
16         me.configureXonoticPicmipSlider(me);
17         return me;
18 }
19 void XonoticPicmipSlider_configureXonoticPicmipSlider(entity me)
20 {
21         me.configureXonoticTextSlider(me, "gl_picmip");
22         me.autofix(me);
23         me.have_s3tc = GL_Have_TextureCompression();
24 }
25 float texmemsize(float s3tc)
26 {
27         return
28         (
29                   2500 * pow(0.5, max(0, cvar("gl_picmip") + cvar("gl_picmip_other")))
30                 + 1500 * pow(0.5, max(0, cvar("gl_picmip") + cvar("gl_picmip_world")))
31         ) * (s3tc && ((cvar("r_texture_dds_load") || cvar("gl_texturecompression")) ? 0.4 : 1.0)); // TC: normalmaps 50%, other 25%, few incompressible, guessing 40% as conservative average
32 }
33 void XonoticPicmipSlider_autofix(entity me)
34 {
35         float max_hard, max_soft;
36         max_hard = cvar("sys_memsize_virtual");
37         max_soft = cvar("sys_memsize_physical");
38         if(max_hard > 0)
39         {
40                 while(me.value > 0 && texmemsize(me.have_s3tc) > max_hard)
41                         me.setValue(me, me.value - 1);
42         }
43         // TODO also check the soft limit!
44         // TODO better handling than clamping the slider!
45 }
46 void XonoticPicmipSlider_draw(entity me)
47 {
48         me.autofix(me);
49         SUPER(XonoticPicmipSlider).draw(me);
50 }
51 #endif