]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
Calculate ping in the server list better.
[xonotic/darkplaces.git] / gl_rmain.c
index 2897c78f8e43f7997cc1c5627c4539c50ba25c2a..053a91c475069ae96143742ffe908a49fd7e17d3 100644 (file)
@@ -142,7 +142,7 @@ cvar_t r_transparent_sortmindist = {CVAR_CLIENT | CVAR_SAVE, "r_transparent_sort
 cvar_t r_transparent_sortmaxdist = {CVAR_CLIENT | CVAR_SAVE, "r_transparent_sortmaxdist", "32768", "upper distance limit for transparent sorting"};
 cvar_t r_transparent_sortarraysize = {CVAR_CLIENT | CVAR_SAVE, "r_transparent_sortarraysize", "4096", "number of distance-sorting layers"};
 cvar_t r_celshading = {CVAR_CLIENT | CVAR_SAVE, "r_celshading", "0", "cartoon-style light shading (OpenGL 2.x only)"}; // FIXME remove OpenGL 2.x only once implemented for DX9
-cvar_t r_celoutlines = {CVAR_CLIENT | CVAR_SAVE, "r_celoutlines", "0", "cartoon-style outlines (requires r_shadow_deferred; OpenGL 2.x only)"}; // FIXME remove OpenGL 2.x only once implemented for DX9
+cvar_t r_celoutlines = {CVAR_CLIENT | CVAR_SAVE, "r_celoutlines", "0", "cartoon-style outlines (requires r_shadow_deferred)"};
 
 cvar_t gl_fogenable = {CVAR_CLIENT, "gl_fogenable", "0", "nehahra fog enable (for Nehahra compatibility only)"};
 cvar_t gl_fogdensity = {CVAR_CLIENT, "gl_fogdensity", "0.25", "nehahra fog density (recommend values below 0.1) (for Nehahra compatibility only)"};
@@ -1458,7 +1458,7 @@ static void R_GLSL_DumpShader_f(cmd_state_t *cmd)
                                Con_Printf("%s written\n", modeinfo[mode].filename);
                        }
                        else
-                               Con_Printf("failed to write to %s\n", modeinfo[mode].filename);
+                               Con_Errorf("failed to write to %s\n", modeinfo[mode].filename);
                }
        }
 }
@@ -2399,9 +2399,10 @@ skinframe_t *R_SkinFrame_LoadExternal_SkinFrame(skinframe_t *skinframe, const ch
        }
 
        // _luma is supported only for tenebrae compatibility
+       // _blend and .blend are supported only for Q3 & QL compatibility, this hack can be removed if better Q3 shader support is implemented
        // _glow is the preferred name
        mymiplevel = savemiplevel;
-       if (skinframe->glow == NULL && ((pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_glow",  skinframe->basename), false, false, false, &mymiplevel)) || (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_luma", skinframe->basename), false, false, false, &mymiplevel))))
+       if (skinframe->glow == NULL && ((pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_glow", skinframe->basename), false, false, false, &mymiplevel)) || (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s.blend", skinframe->basename), false, false, false, &mymiplevel)) || (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_blend", skinframe->basename), false, false, false, &mymiplevel)) || (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_luma", skinframe->basename), false, false, false, &mymiplevel))))
        {
                skinframe->glow = R_LoadTexture2D (r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_glow", skinframe->basename), image_width, image_height, pixels, vid.sRGB3D ? TEXTYPE_SRGB_BGRA : TEXTYPE_BGRA, textureflags & (gl_texturecompression_glow.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), mymiplevel, NULL);
 #ifndef USE_GLES2
@@ -3085,6 +3086,8 @@ static void gl_main_start(void)
 #endif
 }
 
+extern unsigned int r_shadow_occlusion_buf;
+
 static void gl_main_shutdown(void)
 {
        R_RenderTarget_FreeUnused(true);
@@ -3105,7 +3108,7 @@ static void gl_main_shutdown(void)
 #endif
                break;
        }
-
+       r_shadow_occlusion_buf = 0;
        r_numqueries = 0;
        r_maxqueries = 0;
        memset(r_queries, 0, sizeof(r_queries));
@@ -4390,14 +4393,6 @@ static void R_View_Update(void)
 
 float viewscalefpsadjusted = 1.0f;
 
-static void R_GetScaledViewSize(int width, int height, int *outwidth, int *outheight)
-{
-       float scale = r_viewscale.value * sqrt(viewscalefpsadjusted);
-       scale = bound(0.03125f, scale, 1.0f);
-       *outwidth = (int)ceil(width * scale);
-       *outheight = (int)ceil(height * scale);
-}
-
 void R_SetupView(qboolean allowwaterclippingplane, int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
 {
        const float *customclipplane = NULL;
@@ -4617,7 +4612,7 @@ r_rendertarget_t *R_RenderTarget_Get(int texturewidth, int textureheight, textyp
        return r;
 }
 
-static void R_Water_StartFrame(void)
+static void R_Water_StartFrame(int viewwidth, int viewheight)
 {
        int waterwidth, waterheight;
 
@@ -4626,9 +4621,8 @@ static void R_Water_StartFrame(void)
 
        // set waterwidth and waterheight to the water resolution that will be
        // used (often less than the screen resolution for faster rendering)
-       waterwidth = (int)bound(1, r_refdef.view.width * r_water_resolutionmultiplier.value, r_refdef.view.width);
-       waterheight = (int)bound(1, r_refdef.view.height * r_water_resolutionmultiplier.value, r_refdef.view.height);
-       R_GetScaledViewSize(waterwidth, waterheight, &waterwidth, &waterheight);
+       waterwidth = (int)bound(16, viewwidth * r_water_resolutionmultiplier.value, viewwidth);
+       waterheight = (int)bound(16, viewheight * r_water_resolutionmultiplier.value, viewheight);
 
        if (!r_water.integer || r_showsurfaces.integer)
                waterwidth = waterheight = 0;
@@ -5038,8 +5032,8 @@ finish:
 static void R_Bloom_StartFrame(void)
 {
        int screentexturewidth, screentextureheight;
-       int viewwidth, viewheight;
        textype_t textype = TEXTYPE_COLORBUFFER;
+       double scale;
 
        // clear the pointers to rendertargets from last frame as they're stale
        r_fb.rt_screen = NULL;
@@ -5067,33 +5061,43 @@ static void R_Bloom_StartFrame(void)
                adjust = (targetframetime - actualframetime) * r_viewscale_fpsscaling_multiply.value;
                adjust = bound(-r_viewscale_fpsscaling_stepmax.value, adjust, r_viewscale_fpsscaling_stepmax.value);
                if (r_viewscale_fpsscaling_stepsize.value > 0)
-                       adjust = (int)(adjust / r_viewscale_fpsscaling_stepsize.value) * r_viewscale_fpsscaling_stepsize.value;
+               {
+                       if (adjust > 0)
+                               adjust = floor(adjust / r_viewscale_fpsscaling_stepsize.value) * r_viewscale_fpsscaling_stepsize.value;
+                       else
+                               adjust = ceil(adjust / r_viewscale_fpsscaling_stepsize.value) * r_viewscale_fpsscaling_stepsize.value;
+               }
                viewscalefpsadjusted += adjust;
                viewscalefpsadjusted = bound(r_viewscale_fpsscaling_min.value, viewscalefpsadjusted, 1.0f);
        }
        else
                viewscalefpsadjusted = 1.0f;
 
-       R_GetScaledViewSize(r_refdef.view.width, r_refdef.view.height, &viewwidth, &viewheight);
+       scale = r_viewscale.value * sqrt(viewscalefpsadjusted);
+       if (vid.samples)
+               scale *= sqrt(vid.samples); // supersampling
+       scale = bound(0.03125f, scale, 4.0f);
+       screentexturewidth = (int)ceil(r_refdef.view.width * scale);
+       screentextureheight = (int)ceil(r_refdef.view.height * scale);
+       screentexturewidth = bound(1, screentexturewidth, (int)vid.maxtexturesize_2d);
+       screentextureheight = bound(1, screentextureheight, (int)vid.maxtexturesize_2d);
 
        // set bloomwidth and bloomheight to the bloom resolution that will be
        // used (often less than the screen resolution for faster rendering)
-       r_fb.bloomwidth = bound(1, r_bloom_resolution.integer, vid.width);
-       r_fb.bloomheight = r_fb.bloomwidth * vid.height / vid.width;
-       r_fb.bloomheight = bound(1, r_fb.bloomheight, vid.height);
+       r_fb.bloomheight = bound(1, r_bloom_resolution.value * 0.75f, vid.height * 4);
+       r_fb.bloomwidth = r_fb.bloomheight * vid.width / vid.height;
+       r_fb.bloomwidth = bound(1, r_fb.bloomwidth, vid.width * 4);
        r_fb.bloomwidth = bound(1, r_fb.bloomwidth, (int)vid.maxtexturesize_2d);
        r_fb.bloomheight = bound(1, r_fb.bloomheight, (int)vid.maxtexturesize_2d);
 
-       // calculate desired texture sizes
-       screentexturewidth = viewwidth;
-       screentextureheight = viewheight;
-
        if ((r_bloom.integer || (!R_Stereo_Active() && (r_motionblur.value > 0 || r_damageblur.value > 0))) && ((r_bloom_resolution.integer < 4 || r_bloom_blur.value < 1 || r_bloom_blur.value >= 512) || r_refdef.view.width > (int)vid.maxtexturesize_2d || r_refdef.view.height > (int)vid.maxtexturesize_2d))
        {
                Cvar_SetValueQuick(&r_bloom, 0);
                Cvar_SetValueQuick(&r_motionblur, 0);
                Cvar_SetValueQuick(&r_damageblur, 0);
        }
+       if (!r_bloom.integer)
+               r_fb.bloomwidth = r_fb.bloomheight = 0;
 
        // allocate motionblur ghost texture if needed - this is the only persistent texture and is only useful on the main view
        if (r_refdef.view.ismain && (r_fb.screentexturewidth != screentexturewidth || r_fb.screentextureheight != screentextureheight || r_fb.textype != textype))
@@ -5114,16 +5118,6 @@ static void R_Bloom_StartFrame(void)
                }
        }
 
-       if (r_bloom.integer)
-       {
-               // bloom texture is a different resolution
-               r_fb.bloomwidth = bound(1, r_bloom_resolution.integer, r_refdef.view.width);
-               r_fb.bloomheight = r_fb.bloomwidth * r_refdef.view.height / r_refdef.view.width;
-               r_fb.bloomheight = bound(1, r_fb.bloomheight, r_refdef.view.height);
-       }
-       else
-               r_fb.bloomwidth = r_fb.bloomheight = 0;
-
        r_fb.rt_screen = R_RenderTarget_Get(screentexturewidth, screentextureheight, TEXTYPE_DEPTHBUFFER24STENCIL8, true, textype, TEXTYPE_UNUSED, TEXTYPE_UNUSED, TEXTYPE_UNUSED);
 
        r_refdef.view.clear = true;
@@ -5705,11 +5699,11 @@ void R_RenderView(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture, i
                viewcolortexture = r_fb.rt_screen->colortexture[0];
                viewx = 0;
                viewy = 0;
-               viewwidth = width;
-               viewheight = height;
+               viewwidth = r_fb.rt_screen->texturewidth;
+               viewheight = r_fb.rt_screen->textureheight;
        }
 
-       R_Water_StartFrame();
+       R_Water_StartFrame(viewwidth, viewheight);
 
        CHECKGLERROR
        if (r_timereport_active)
@@ -10067,7 +10061,7 @@ void R_DebugLine(vec3_t start, vec3_t end)
                offsetx = 0.5f * width * vid_conwidth.value / vid.width;
                offsety = 0;
        }
-       surf = Mod_Mesh_AddSurface(mod, Mod_Mesh_GetTexture(mod, "white", 0, 0, MATERIALFLAG_WALL | MATERIALFLAG_VERTEXCOLOR | MATERIALFLAG_ALPHAGEN_VERTEX), true);
+       surf = Mod_Mesh_AddSurface(mod, Mod_Mesh_GetTexture(mod, "white", 0, 0, MATERIALFLAG_WALL | MATERIALFLAG_VERTEXCOLOR | MATERIALFLAG_ALPHAGEN_VERTEX | MATERIALFLAG_ALPHA | MATERIALFLAG_BLENDED | MATERIALFLAG_NOSHADOW), true);
        e0 = Mod_Mesh_IndexForVertex(mod, surf, x1 - offsetx, y1 - offsety, 10, 0, 0, -1, 0, 0, 0, 0, r1, g1, b1, alpha1);
        e1 = Mod_Mesh_IndexForVertex(mod, surf, x2 - offsetx, y2 - offsety, 10, 0, 0, -1, 0, 0, 0, 0, r2, g2, b2, alpha2);
        e2 = Mod_Mesh_IndexForVertex(mod, surf, x2 + offsetx, y2 + offsety, 10, 0, 0, -1, 0, 0, 0, 0, r2, g2, b2, alpha2);