]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
alias model fake shadows can now be cached
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 25 May 2003 11:59:58 +0000 (11:59 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 25 May 2003 11:59:58 +0000 (11:59 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3030 d7cf8633-e32d-0410-b094-e92efae38249

gl_models.c

index d7b5b66e8219393de89d57fea8a186cc851622fd..d74a30b17705eaaa8f3da59339d41f6abc616816 100644 (file)
@@ -350,7 +350,8 @@ void R_Model_Alias_DrawFakeShadow (entity_render_t *ent)
        aliasmesh_t *mesh;
        aliasskin_t *skin;
        rmeshstate_t m;
-       float *v, planenormal[3], planedist, dist, projection[3], floororigin[3], surfnormal[3], lightdirection[3], v2[3];
+       float *v, plane[4], dist, projection[3], floororigin[3], surfnormal[3], lightdirection[3], v2[3];
+       rcachearrayrequest_t request;
 
        if ((ent->effects & EF_ADDITIVE) || ent->alpha < 1)
                return;
@@ -369,7 +370,8 @@ void R_Model_Alias_DrawFakeShadow (entity_render_t *ent)
        memset(&m, 0, sizeof(m));
        m.blendfunc1 = GL_SRC_ALPHA;
        m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
-       R_Mesh_State(&m);
+       if (gl_mesh_copyarrays.integer)
+               R_Mesh_State(&m);
        GL_Color(0, 0, 0, 0.5);
 
        // put a light direction in the entity's coordinate space
@@ -377,27 +379,52 @@ void R_Model_Alias_DrawFakeShadow (entity_render_t *ent)
        VectorNormalizeFast(projection);
 
        // put the plane's normal in the entity's coordinate space
-       Matrix4x4_Transform3x3(&ent->inversematrix, surfnormal, planenormal);
-       VectorNormalizeFast(planenormal);
+       Matrix4x4_Transform3x3(&ent->inversematrix, surfnormal, plane);
+       VectorNormalizeFast(plane);
 
        // put the plane's distance in the entity's coordinate space
        VectorSubtract(floororigin, ent->origin, floororigin);
-       planedist = DotProduct(floororigin, surfnormal) + 2;
+       plane[3] = DotProduct(floororigin, surfnormal) + 2;
 
-       dist = -1.0f / DotProduct(projection, planenormal);
+       dist = -1.0f / DotProduct(projection, plane);
        VectorScale(projection, dist, projection);
+       memset(&request, 0, sizeof(request));
        for (meshnum = 0, mesh = ent->model->aliasdata_meshes;meshnum < ent->model->aliasnum_meshes;meshnum++)
        {
                skin = R_FetchAliasSkin(ent, mesh);
                if (skin->flags & ALIASSKIN_TRANSPARENT)
                        continue;
-               R_Mesh_GetSpace(mesh->num_vertices);
-               R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_VERTEX, varray_vertex3f);
-               for (i = 0, v = varray_vertex3f;i < mesh->num_vertices;i++, v += 3)
+               if (gl_mesh_copyarrays.integer)
+               {
+                       R_Mesh_GetSpace(mesh->num_vertices);
+                       R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_VERTEX, varray_vertex3f);
+                       for (i = 0, v = varray_vertex3f;i < mesh->num_vertices;i++, v += 3)
+                       {
+                               dist = DotProduct(v, plane) - plane[3];
+                               if (dist > 0)
+                                       VectorMA(v, dist, projection, v);
+                       }
+               }
+               else
                {
-                       dist = DotProduct(v, planenormal) - planedist;
-                       if (dist > 0)
-                               VectorMA(v, dist, projection, v);
+                       request.data_size = mesh->num_vertices * sizeof(float[3]);
+                       request.id_pointer1 = mesh;
+                       request.id_number1 = CRC_Block((void *)&ent->matrix, sizeof(ent->matrix));
+                       request.id_number2 = CRC_Block((void *)&plane, sizeof(plane));
+                       request.id_number3 = CRC_Block((void *)&ent->frameblend, sizeof(ent->frameblend));
+                       m.pointervertexcount = mesh->num_vertices;
+                       if (R_Mesh_CacheArray(&request))
+                       {
+                               R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_VERTEX, request.data);
+                               for (i = 0, v = request.data;i < mesh->num_vertices;i++, v += 3)
+                               {
+                                       dist = DotProduct(v, plane) - plane[3];
+                                       if (dist > 0)
+                                               VectorMA(v, dist, projection, v);
+                               }
+                       }
+                       m.pointer_vertex = request.data;
+                       R_Mesh_State(&m);
                }
                c_alias_polys += mesh->num_triangles;
                R_Mesh_Draw(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);