]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_shared.c
Added a mempool parameter to FS_LoadFile
[xonotic/darkplaces.git] / model_shared.c
index 28841924473b46dac64f961a3b08ad9c3a99e398..3927458428f3d40517c3b49754e77a353f679132 100644 (file)
@@ -112,19 +112,24 @@ void Mod_BuildDistortTexture (void)
                }
        }
 
+
        for (i=0; i<4; i++)
        {
                for (j=0; j<16; j++)
                {
-                       for (y=0; y<DISTORTRESOLUTION; y++)
+                       mod_shared_distorttexture[i*16+j] = NULL;
+                       if (gl_textureshader)
                        {
-                               for (x=0; x<DISTORTRESOLUTION; x++)
+                               for (y=0; y<DISTORTRESOLUTION; y++)
                                {
-                                       data[4][y][x][0] = Mod_MorphDistortTexture (data[(i-1)&3][y][x][0], data[i][y][x][0], data[(i+1)&3][y][x][0], data[(i+2)&3][y][x][0], 0.0625*j);
-                                       data[4][y][x][1] = Mod_MorphDistortTexture (data[(i-1)&3][y][x][1], data[i][y][x][1], data[(i+1)&3][y][x][1], data[(i+2)&3][y][x][1], 0.0625*j);
+                                       for (x=0; x<DISTORTRESOLUTION; x++)
+                                       {
+                                               data[4][y][x][0] = Mod_MorphDistortTexture (data[(i-1)&3][y][x][0], data[i][y][x][0], data[(i+1)&3][y][x][0], data[(i+2)&3][y][x][0], 0.0625*j);
+                                               data[4][y][x][1] = Mod_MorphDistortTexture (data[(i-1)&3][y][x][1], data[i][y][x][1], data[(i+1)&3][y][x][1], data[(i+2)&3][y][x][1], 0.0625*j);
+                                       }
                                }
+                               mod_shared_distorttexture[i*16+j] = R_LoadTexture2D(mod_shared_texturepool, va("distorttexture%i", i*16+j), DISTORTRESOLUTION, DISTORTRESOLUTION, &data[4][0][0][0], TEXTYPE_DSDT, TEXF_PRECACHE, NULL);
                        }
-                       mod_shared_distorttexture[i*16+j] = R_LoadTexture2D(mod_shared_texturepool, va("distorttexture%i", i*16+j), DISTORTRESOLUTION, DISTORTRESOLUTION, &data[4][0][0][0], TEXTYPE_DSDT, TEXF_PRECACHE, NULL);
                }
        }
 
@@ -196,7 +201,7 @@ static void mod_newmap(void)
 Mod_Init
 ===============
 */
-static void Mod_Print (void);
+static void Mod_Print(void);
 static void Mod_Precache (void);
 void Mod_Init (void)
 {
@@ -259,7 +264,7 @@ static model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk,
        {
                if (checkdisk)
                {
-                       buf = FS_LoadFile (mod->name, false);
+                       buf = FS_LoadFile (mod->name, tempmempool, false);
                        if (!buf)
                        {
                                if (crash)
@@ -284,7 +289,7 @@ static model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk,
 
        if (!buf)
        {
-               buf = FS_LoadFile (mod->name, false);
+               buf = FS_LoadFile (mod->name, tempmempool, false);
                if (!buf)
                {
                        if (crash)
@@ -471,10 +476,10 @@ static void Mod_Print(void)
        int             i;
        model_t *mod;
 
-       Con_Print("Loaded models:\n");
+       Con_Print("Loaded models:\n");
        for (i = 0, mod = mod_known;i < MAX_MOD_KNOWN;i++, mod++)
                if (mod->name[0])
-                       Con_Printf ("%4iK %s\n", mod->mempool ? (mod->mempool->totalsize + 1023) / 1024 : 0, mod->name);
+                       Con_Printf("%4iK %s\n", mod->mempool ? (mod->mempool->totalsize + 1023) / 1024 : 0, mod->name);
 }
 
 /*
@@ -487,7 +492,7 @@ static void Mod_Precache(void)
        if (Cmd_Argc() == 2)
                Mod_ForName(Cmd_Argv(1), false, true, cl.worldmodel && !strcasecmp(Cmd_Argv(1), cl.worldmodel->name));
        else
-               Con_Printf("usage: modelprecache <filename>\n");
+               Con_Print("usage: modelprecache <filename>\n");
 }
 
 #if 1
@@ -620,7 +625,13 @@ void Mod_BuildBumpVectors(const float *v0, const float *v1, const float *v2, con
        f = -DotProduct(tvector3f, normal3f);
        VectorMA(tvector3f, f, normal3f, tvector3f);
        VectorNormalize(tvector3f);
-       CrossProduct(normal3f, tvector3f, svector3f);
+       // note: can't be a CrossProduct as that sometimes flips the texture
+       svector3f[0] = ((tc1[1] - tc0[1]) * (v2[0] - v0[0]) - (tc2[1] - tc0[1]) * (v1[0] - v0[0]));
+       svector3f[1] = ((tc1[1] - tc0[1]) * (v2[1] - v0[1]) - (tc2[1] - tc0[1]) * (v1[1] - v0[1]));
+       svector3f[2] = ((tc1[1] - tc0[1]) * (v2[2] - v0[2]) - (tc2[1] - tc0[1]) * (v1[2] - v0[2]));
+       f = -DotProduct(svector3f, normal3f);
+       VectorMA(svector3f, f, normal3f, svector3f);
+       VectorNormalize(svector3f);
 }
 
 // warning: this is an expensive function!
@@ -800,7 +811,7 @@ void Mod_ShadowMesh_AddTriangle(mempool_t *mempool, shadowmesh_t *mesh, rtexture
        mesh->numtriangles++;
 }
 
-void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, rtexture_t *map_diffuse, rtexture_t *map_specular, rtexture_t *map_normal, float *vertex3f, float *svector3f, float *tvector3f, float *normal3f, float *texcoord2f, int numtris, int *element3i)
+void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, rtexture_t *map_diffuse, rtexture_t *map_specular, rtexture_t *map_normal, const float *vertex3f, const float *svector3f, const float *tvector3f, const float *normal3f, const float *texcoord2f, int numtris, const int *element3i)
 {
        int i, j, e;
        float vbuf[3*14], *v;
@@ -1096,7 +1107,7 @@ tag_torso,
 */
        memset(tagsets, 0, sizeof(tagsets));
        memset(word, 0, sizeof(word));
-       for (i = 0;i < MAX_SKINS && (data = text = FS_LoadFile(va("%s_%i.skin", loadmodel->name, i), true));i++)
+       for (i = 0;i < MAX_SKINS && (data = text = FS_LoadFile(va("%s_%i.skin", loadmodel->name, i), tempmempool, true));i++)
        {
                numtags = 0;
                skinfile = Mem_Alloc(tempmempool, sizeof(skinfile_t));