]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
movement packet loss tracking
[xonotic/darkplaces.git] / gl_rmain.c
index 41734a4e1cf45adaafac316b93c64fd15c25592d..7e2308e2a5d7a38ce626a2c8c7cafab883cd7140 100644 (file)
@@ -95,7 +95,7 @@ cvar_t r_polygonoffset_decals_factor = {0, "r_polygonoffset_decals_factor", "0",
 cvar_t r_polygonoffset_decals_offset = {0, "r_polygonoffset_decals_offset", "-14", "biases depth values of decals to prevent z-fighting artifacts"};
 cvar_t r_fog_exp2 = {0, "r_fog_exp2", "0", "uses GL_EXP2 fog (as in Nehahra) rather than realistic GL_EXP fog"};
 cvar_t r_drawfog = {CVAR_SAVE, "r_drawfog", "1", "allows one to disable fog rendering"};
-cvar_t r_transparentdepthmasking = {CVAR_SAVE, "r_transparentdepthmasking", "1", "enables depth writes on transparent meshes whose materially is normally opaque, this prevents seeing the inside of a transparent mesh"};
+cvar_t r_transparentdepthmasking = {CVAR_SAVE, "r_transparentdepthmasking", "0", "enables depth writes on transparent meshes whose materially is normally opaque, this prevents seeing the inside of a transparent mesh"};
 
 cvar_t gl_fogenable = {0, "gl_fogenable", "0", "nehahra fog enable (for Nehahra compatibility only)"};
 cvar_t gl_fogdensity = {0, "gl_fogdensity", "0.25", "nehahra fog density (recommend values below 0.1) (for Nehahra compatibility only)"};
@@ -343,7 +343,8 @@ static void R_BuildNormalizationCube(void)
        vec3_t v;
        vec_t s, t, intensity;
 #define NORMSIZE 64
-       unsigned char data[6][NORMSIZE][NORMSIZE][4];
+       unsigned char *data;
+       data = Mem_Alloc(tempmempool, 6*NORMSIZE*NORMSIZE*4);
        for (side = 0;side < 6;side++)
        {
                for (y = 0;y < NORMSIZE;y++)
@@ -387,14 +388,15 @@ static void R_BuildNormalizationCube(void)
                                        break;
                                }
                                intensity = 127.0f / sqrt(DotProduct(v, v));
-                               data[side][y][x][2] = (unsigned char)(128.0f + intensity * v[0]);
-                               data[side][y][x][1] = (unsigned char)(128.0f + intensity * v[1]);
-                               data[side][y][x][0] = (unsigned char)(128.0f + intensity * v[2]);
-                               data[side][y][x][3] = 255;
+                               data[((side*64+y)*64+x)*4+2] = (unsigned char)(128.0f + intensity * v[0]);
+                               data[((side*64+y)*64+x)*4+1] = (unsigned char)(128.0f + intensity * v[1]);
+                               data[((side*64+y)*64+x)*4+0] = (unsigned char)(128.0f + intensity * v[2]);
+                               data[((side*64+y)*64+x)*4+3] = 255;
                        }
                }
        }
-       r_texture_normalizationcube = R_LoadTextureCubeMap(r_main_texturepool, "normalcube", NORMSIZE, &data[0][0][0][0], TEXTYPE_BGRA, TEXF_PRECACHE | TEXF_CLAMP | TEXF_PERSISTENT, NULL);
+       r_texture_normalizationcube = R_LoadTextureCubeMap(r_main_texturepool, "normalcube", NORMSIZE, data, TEXTYPE_BGRA, TEXF_PRECACHE | TEXF_CLAMP | TEXF_PERSISTENT, NULL);
+       Mem_Free(data);
 }
 
 static void R_BuildFogTexture(void)
@@ -448,8 +450,8 @@ static void R_BuildFogTexture(void)
        }
        else
        {
-               r_texture_fogattenuation = R_LoadTexture2D(r_main_texturepool, "fogattenuation", FOGWIDTH, 1, &data1[0][0], TEXTYPE_BGRA, TEXF_PRECACHE | TEXF_FORCELINEAR | TEXF_CLAMP | TEXF_PERSISTENT, NULL);
-               //r_texture_fogintensity = R_LoadTexture2D(r_main_texturepool, "fogintensity", FOGWIDTH, 1, &data2[0][0], TEXTYPE_BGRA, TEXF_PRECACHE | TEXF_FORCELINEAR | TEXF_CLAMP, NULL);
+               r_texture_fogattenuation = R_LoadTexture2D(r_main_texturepool, "fogattenuation", FOGWIDTH, 1, &data1[0][0], TEXTYPE_BGRA, TEXF_PRECACHE | TEXF_FORCELINEAR | TEXF_CLAMP | TEXF_PERSISTENT | TEXF_ALLOWUPDATES, NULL);
+               //r_texture_fogintensity = R_LoadTexture2D(r_main_texturepool, "fogintensity", FOGWIDTH, 1, &data2[0][0], TEXTYPE_BGRA, TEXF_PRECACHE | TEXF_FORCELINEAR | TEXF_CLAMP | TEXF_ALLOWUPDATES, NULL);
        }
 }
 
@@ -484,13 +486,16 @@ static const char *builtinshaderstring =
 "#endif\n"
 "#else // !MODE_SHOWDEPTH\n"
 "#ifdef MODE_POSTPROCESS\n"
+"varying vec2 TexCoord1;\n"
+"varying vec2 TexCoord2;\n"
+"\n"
 "#ifdef VERTEX_SHADER\n"
 "void main(void)\n"
 "{\n"
 "      gl_Position = ftransform();\n"
-"      gl_TexCoord[0] = gl_MultiTexCoord0;\n"
+"      TexCoord1 = gl_MultiTexCoord0.xy;\n"
 "#ifdef USEBLOOM\n"
-"      gl_TexCoord[1] = gl_MultiTexCoord1;\n"
+"      TexCoord2 = gl_MultiTexCoord1.xy;\n"
 "#endif\n"
 "}\n"
 "#endif\n"
@@ -518,9 +523,9 @@ static const char *builtinshaderstring =
 "uniform vec2 PixelSize;\n"
 "void main(void)\n"
 "{\n"
-"      gl_FragColor = texture2D(Texture_First, gl_TexCoord[0].xy);\n"
+"      gl_FragColor = texture2D(Texture_First, TexCoord1);\n"
 "#ifdef USEBLOOM\n"
-"      gl_FragColor += texture2D(Texture_Second, gl_TexCoord[1].xy);\n"
+"      gl_FragColor += texture2D(Texture_Second, TexCoord2);\n"
 "#endif\n"
 "#ifdef USEVIEWTINT\n"
 "      gl_FragColor = mix(gl_FragColor, ViewTintColor, ViewTintColor.a);\n"
@@ -529,11 +534,11 @@ static const char *builtinshaderstring =
 "#ifdef USEPOSTPROCESSING\n"
 "// do r_glsl_dumpshader, edit glsl/default.glsl, and replace this by your own postprocessing if you want\n"
 "// this code does a blur with the radius specified in the first component of r_glsl_postprocess_uservec1 and blends it using the second component\n"
-"      gl_FragColor += texture2D(Texture_First, gl_TexCoord[0].xy + PixelSize*UserVec1.x*vec2(-0.987688, -0.156434)) * UserVec1.y;\n"
-"      gl_FragColor += texture2D(Texture_First, gl_TexCoord[0].xy + PixelSize*UserVec1.x*vec2(-0.156434, -0.891007)) * UserVec1.y;\n"
-"      gl_FragColor += texture2D(Texture_First, gl_TexCoord[0].xy + PixelSize*UserVec1.x*vec2( 0.891007, -0.453990)) * UserVec1.y;\n"
-"      gl_FragColor += texture2D(Texture_First, gl_TexCoord[0].xy + PixelSize*UserVec1.x*vec2( 0.707107,  0.707107)) * UserVec1.y;\n"
-"      gl_FragColor += texture2D(Texture_First, gl_TexCoord[0].xy + PixelSize*UserVec1.x*vec2(-0.453990,  0.891007)) * UserVec1.y;\n"
+"      gl_FragColor += texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2(-0.987688, -0.156434)) * UserVec1.y;\n"
+"      gl_FragColor += texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2(-0.156434, -0.891007)) * UserVec1.y;\n"
+"      gl_FragColor += texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2( 0.891007, -0.453990)) * UserVec1.y;\n"
+"      gl_FragColor += texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2( 0.707107,  0.707107)) * UserVec1.y;\n"
+"      gl_FragColor += texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2(-0.453990,  0.891007)) * UserVec1.y;\n"
 "      gl_FragColor /= (1 + 5 * UserVec1.y);\n"
 "#endif\n"
 "\n"
@@ -553,15 +558,21 @@ static const char *builtinshaderstring =
 "#endif\n"
 "#else // !MODE_POSTPROCESS\n"
 "#ifdef MODE_GENERIC\n"
+"#ifdef USEDIFFUSE\n"
+"varying vec2 TexCoord1;\n"
+"#endif\n"
+"#ifdef USESPECULAR\n"
+"varying vec2 TexCoord2;\n"
+"#endif\n"
 "#ifdef VERTEX_SHADER\n"
 "void main(void)\n"
 "{\n"
 "      gl_FrontColor = gl_Color;\n"
 "#ifdef USEDIFFUSE\n"
-"      gl_TexCoord[0] = gl_MultiTexCoord0;\n"
+"      TexCoord1 = gl_MultiTexCoord0.xy;\n"
 "#endif\n"
 "#ifdef USESPECULAR\n"
-"      gl_TexCoord[1] = gl_MultiTexCoord1;\n"
+"      TexCoord2 = gl_MultiTexCoord1.xy;\n"
 "#endif\n"
 "      gl_Position = ftransform();\n"
 "}\n"
@@ -579,11 +590,11 @@ static const char *builtinshaderstring =
 "{\n"
 "      gl_FragColor = gl_Color;\n"
 "#ifdef USEDIFFUSE\n"
-"      gl_FragColor *= texture2D(Texture_First, gl_TexCoord[0].xy);\n"
+"      gl_FragColor *= texture2D(Texture_First, TexCoord1);\n"
 "#endif\n"
 "\n"
 "#ifdef USESPECULAR\n"
-"      vec4 tex2 = texture2D(Texture_Second, gl_TexCoord[1].xy);\n"
+"      vec4 tex2 = texture2D(Texture_Second, TexCoord2);\n"
 "#endif\n"
 "#ifdef USECOLORMAPPING\n"
 "      gl_FragColor *= tex2;\n"
@@ -598,11 +609,12 @@ static const char *builtinshaderstring =
 "#endif\n"
 "#else // !MODE_GENERIC\n"
 "#ifdef MODE_BLOOMBLUR\n"
+"varying TexCoord;\n"
 "#ifdef VERTEX_SHADER\n"
 "void main(void)\n"
 "{\n"
 "      gl_FrontColor = gl_Color;\n"
-"      gl_TexCoord[0] = gl_MultiTexCoord0;\n"
+"      TexCoord = gl_MultiTexCoord0.xy;\n"
 "      gl_Position = ftransform();\n"
 "}\n"
 "#endif\n"
@@ -614,7 +626,7 @@ static const char *builtinshaderstring =
 "void main(void)\n"
 "{\n"
 "      int i;\n"
-"      vec2 tc = gl_TexCoord[0].xy;\n"
+"      vec2 tc = TexCoord;\n"
 "      vec3 color = texture2D(Texture_First, tc).rgb;\n"
 "      tc += BloomBlur_Parameters.xy;\n"
 "      for (i = 1;i < SAMPLES;i++)\n"
@@ -4171,8 +4183,8 @@ void R_View_Update(void)
 
 void R_SetupView(qboolean allowwaterclippingplane)
 {
-       const double *customclipplane = NULL;
-       double plane[4];
+       const float *customclipplane = NULL;
+       float plane[4];
        if (r_refdef.view.useclipplane && allowwaterclippingplane)
        {
                // LordHavoc: couldn't figure out how to make this approach the
@@ -5124,7 +5136,7 @@ void R_UpdateVariables(void)
                                }
                                else
                                {
-                                       r_texture_gammaramps = R_LoadTexture2D(r_main_texturepool, "gammaramps", RAMPWIDTH, 1, &rampbgr[0][0], TEXTYPE_BGRA, TEXF_PRECACHE | TEXF_FORCELINEAR | TEXF_CLAMP | TEXF_PERSISTENT, NULL);
+                                       r_texture_gammaramps = R_LoadTexture2D(r_main_texturepool, "gammaramps", RAMPWIDTH, 1, &rampbgr[0][0], TEXTYPE_BGRA, TEXF_PRECACHE | TEXF_FORCELINEAR | TEXF_CLAMP | TEXF_PERSISTENT | TEXF_ALLOWUPDATES, NULL);
                                }
                        }
                }
@@ -7088,7 +7100,7 @@ void RSurf_DrawBatch_Simple(int texturenumsurfaces, const msurface_t **texturesu
        {
                #define MAXBATCHTRIANGLES 4096
                int batchtriangles = 0;
-               int batchelements[MAXBATCHTRIANGLES*3];
+               static int batchelements[MAXBATCHTRIANGLES*3];
                for (i = 0;i < texturenumsurfaces;i = j)
                {
                        surface = texturesurfacelist[i];
@@ -8200,7 +8212,7 @@ static void R_DrawSurface_TransparentCallback(const entity_render_t *ent, const
        int texturenumsurfaces, endsurface;
        texture_t *texture;
        const msurface_t *surface;
-       const msurface_t *texturesurfacelist[1024];
+       const msurface_t *texturesurfacelist[256];
 
        // if the model is static it doesn't matter what value we give for
        // wantnormals and wanttangents, so this logic uses only rules applicable
@@ -9414,10 +9426,31 @@ void R_DrawWorldSurfaces(qboolean skysurfaces, qboolean writedepth, qboolean dep
        }
        // update lightmaps if needed
        if (update)
+       {
+               int updated = 0;
                for (j = model->firstmodelsurface, endj = model->firstmodelsurface + model->nummodelsurfaces;j < endj;j++)
+               {
                        if (r_refdef.viewcache.world_surfacevisible[j])
+                       {
                                if (update[j])
+                               {
+                                       updated++;
                                        R_BuildLightMap(r_refdef.scene.worldentity, surfaces + j);
+                               }
+                       }
+               }
+               if (updated)
+               {
+                       int count = model->brushq3.num_mergedlightmaps;
+                       for (i = 0;i < count;i++)
+                       {
+                               if (model->brushq3.data_deluxemaps[i])
+                                       R_FlushTexture(model->brushq3.data_deluxemaps[i]);
+                               if (model->brushq3.data_lightmaps[i])
+                                       R_FlushTexture(model->brushq3.data_lightmaps[i]);
+                       }
+               }
+       }
        // don't do anything if there were no surfaces
        if (!numsurfacelist)
        {
@@ -9526,6 +9559,29 @@ void R_DrawModelSurfaces(entity_render_t *ent, qboolean skysurfaces, qboolean wr
                return;
        }
        // update lightmaps if needed
+       if (update)
+       {
+               int updated = 0;
+               for (j = model->firstmodelsurface, endj = model->firstmodelsurface + model->nummodelsurfaces;j < endj;j++)
+               {
+                       if (update[j])
+                       {
+                               updated++;
+                               R_BuildLightMap(ent, surfaces + j);
+                       }
+               }
+               if (updated)
+               {
+                       int count = model->brushq3.num_mergedlightmaps;
+                       for (i = 0;i < count;i++)
+                       {
+                               if (model->brushq3.data_deluxemaps[i])
+                                       R_FlushTexture(model->brushq3.data_deluxemaps[i]);
+                               if (model->brushq3.data_lightmaps[i])
+                                       R_FlushTexture(model->brushq3.data_lightmaps[i]);
+                       }
+               }
+       }
        if (update)
                for (j = model->firstmodelsurface, endj = model->firstmodelsurface + model->nummodelsurfaces;j < endj;j++)
                        if (update[j])