]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/slider_picmip.qc
Sort menu classes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / slider_picmip.qc
1 #ifndef SLIDER_PICMIP_H
2 #define SLIDER_PICMIP_H
3 CLASS(XonoticPicmipSlider, XonoticTextSlider)
4         METHOD(XonoticPicmipSlider, configureXonoticPicmipSlider, void(entity))
5         METHOD(XonoticPicmipSlider, draw, void(entity))
6         METHOD(XonoticPicmipSlider, autofix, void(entity))
7         ATTRIB(XonoticPicmipSlider, have_s3tc, float, 0)
8 ENDCLASS(XonoticPicmipSlider)
9 entity makeXonoticPicmipSlider(); // note: you still need to call addValue and configureXonoticTextSliderValues!
10 #endif
11
12 #ifdef IMPLEMENTATION
13 entity makeXonoticPicmipSlider()
14 {
15         entity me;
16         me = NEW(XonoticPicmipSlider);
17         me.configureXonoticPicmipSlider(me);
18         return me;
19 }
20 void XonoticPicmipSlider_configureXonoticPicmipSlider(entity me)
21 {
22         me.configureXonoticTextSlider(me, "gl_picmip");
23         me.autofix(me);
24         me.have_s3tc = GL_Have_TextureCompression();
25 }
26 float texmemsize(float s3tc)
27 {
28         return
29         (
30                   2500 * pow(0.25, max(0, cvar("gl_picmip") + cvar("gl_picmip_other")))
31                 + 1500 * pow(0.25, max(0, cvar("gl_picmip") + cvar("gl_picmip_world")))
32         ) * ((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
33 }
34 void XonoticPicmipSlider_autofix(entity me)
35 {
36         float max_hard, max_soft;
37         if(cvar("menu_picmip_bypass"))
38                 return;
39         max_hard = cvar("sys_memsize_virtual");
40         max_soft = cvar("sys_memsize_physical");
41         if(max_hard > 0)
42         {
43                 while(me.value > 0 && texmemsize(me.have_s3tc) > max_hard)
44                         me.setValue(me, me.value - 1);
45         }
46         // TODO also check the soft limit!
47         // TODO better handling than clamping the slider!
48 }
49 void XonoticPicmipSlider_draw(entity me)
50 {
51         me.autofix(me);
52         SUPER(XonoticPicmipSlider).draw(me);
53 }
54 #endif