]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/slider_picmip.qc
Merge remote-tracking branch 'origin/master' into BuddyFriendGuy/mapStringFilter
[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         me.autofix(me);
25         me.have_s3tc = GL_Have_TextureCompression();
26 }
27 float texmemsize(float s3tc)
28 {
29         return
30         (
31                   2500 * pow(0.25, max(0, cvar("gl_picmip") + cvar("gl_picmip_other")))
32                 + 1500 * pow(0.25, max(0, cvar("gl_picmip") + cvar("gl_picmip_world")))
33         ) * ((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
34 }
35 void XonoticPicmipSlider_autofix(entity me)
36 {
37         float max_hard, max_soft;
38         if(cvar("menu_picmip_bypass"))
39                 return;
40         max_hard = cvar("sys_memsize_virtual");
41         max_soft = cvar("sys_memsize_physical");
42         if(max_hard > 0)
43         {
44                 while(me.value > 0 && texmemsize(me.have_s3tc) > max_hard)
45                         me.setValue(me, me.value - 1);
46         }
47         // TODO also check the soft limit!
48         // TODO better handling than clamping the slider!
49 }
50 void XonoticPicmipSlider_draw(entity me)
51 {
52         me.autofix(me);
53         SUPER(XonoticPicmipSlider).draw(me);
54 }
55 #endif