]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/slider_picmip.qc
Merge branch 'Mario/qc_updates' into TimePath/csqc_prediction
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / slider_picmip.qc
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.25, max(0, cvar("gl_picmip") + cvar("gl_picmip_other")))
30                 + 1500 * pow(0.25, max(0, cvar("gl_picmip") + cvar("gl_picmip_world")))
31         ) * ((s3tc && (cvar("r_texture_dds_load") || cvar("gl_texturecompression"))) ? 0.2 : 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         if(cvar("menu_picmip_bypass"))
37                 return;
38         max_hard = cvar("sys_memsize_virtual");
39         max_soft = cvar("sys_memsize_physical");
40         if(max_hard > 0)
41         {
42                 while(me.value > 0 && texmemsize(me.have_s3tc) > max_hard)
43                         me.setValue(me, me.value - 1);
44         }
45         // TODO also check the soft limit!
46         // TODO better handling than clamping the slider!
47 }
48 void XonoticPicmipSlider_draw(entity me)
49 {
50         me.autofix(me);
51         SUPER(XonoticPicmipSlider).draw(me);
52 }
53 #endif