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