From ddf29ee760ff83c108fb9c13cdf27d17dca6ac8e Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 5 Sep 2002 14:24:16 +0000 Subject: [PATCH] surfvertex_t is gone, in it's place are non-interleaved arrays, which keeps things simpler... git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2333 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rsurf.c | 162 +++++++++++++--------------------- model_brush.c | 237 +++++++++++++++----------------------------------- model_brush.h | 21 ++--- 3 files changed, 138 insertions(+), 282 deletions(-) diff --git a/gl_rsurf.c b/gl_rsurf.c index 48440d94..43318ed9 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -624,56 +624,16 @@ void R_Stain (vec3_t origin, float radius, int cr1, int cg1, int cb1, int ca1, i ============================================================= */ -static void RSurf_CopyXYZ(const surfvertex_t *in, float *out, int numverts) -{ - int i; - for (i = 0;i < numverts;i++, in++, out += 4) - { - VectorCopy(in->v, out); - out[3] = 1; - } -} - -static void RSurf_CopyST(const surfvertex_t *in, float *out, int numverts) -{ - int i; - for (i = 0;i < numverts;i++, in++, out += 2) - { - out[0] = in->st[0]; - out[1] = in->st[1]; - } -} - -static void RSurf_CopyUV(const surfvertex_t *in, float *out, int numverts) -{ - int i; - for (i = 0;i < numverts;i++, in++, out += 2) - { - out[0] = in->uv[0]; - out[1] = in->uv[1]; - } -} - -static void RSurf_CopyAB(const surfvertex_t *in, float *out, int numverts) -{ - int i; - for (i = 0;i < numverts;i++, in++, out += 2) - { - out[0] = in->ab[0]; - out[1] = in->ab[1]; - } -} - -static void RSurf_AddLightmapToVertexColors(const surfvertex_t *in, float *c, int numverts, const qbyte *samples, int size3, const qbyte *styles) +static void RSurf_AddLightmapToVertexColors(const int *lightmapoffsets, float *c, int numverts, const qbyte *samples, int size3, const qbyte *styles) { int i; float scale; const qbyte *lm; if (styles[0] != 255) { - for (i = 0;i < numverts;i++, in++, c += 4) + for (i = 0;i < numverts;i++, c += 4) { - lm = samples + in->lightmapoffset; + lm = samples + lightmapoffsets[i]; scale = d_lightstylevalue[styles[0]] * (1.0f / 32768.0f); VectorMA(c, scale, lm, c); if (styles[1] != 255) @@ -779,7 +739,7 @@ static int RSurf_LightSeparate(const matrix4x4_t *matrix, const int *dlightbits, const float *v; float *c; int i, l, lit = false; - rdlight_t *rd; + const rdlight_t *rd; vec3_t lightorigin; for (l = 0;l < r_numdlights;l++) { @@ -803,21 +763,21 @@ static int RSurf_LightSeparate(const matrix4x4_t *matrix, const int *dlightbits, } // note: this untransforms lights to do the checking, -// and takes surf->mesh->vertex data -static int RSurf_LightCheck(const matrix4x4_t *matrix, const int *dlightbits, surfmesh_t *mesh) +// and takes surf->mesh->verts data +static int RSurf_LightCheck(const matrix4x4_t *matrix, const int *dlightbits, const surfmesh_t *mesh) { int i, l; - rdlight_t *rd; + const rdlight_t *rd; vec3_t lightorigin; - surfvertex_t *sv; + const float *v; for (l = 0;l < r_numdlights;l++) { if (dlightbits[l >> 5] & (1 << (l & 31))) { rd = &r_dlight[l]; Matrix4x4_Transform(matrix, rd->origin, lightorigin); - for (i = 0, sv = mesh->vertex;i < mesh->numverts;i++, sv++) - if (VectorDistance2(sv->v, lightorigin) < rd->cullradius2) + for (i = 0, v = mesh->verts;i < mesh->numverts;i++, v += 4) + if (VectorDistance2(v, lightorigin) < rd->cullradius2) return true; } } @@ -827,7 +787,7 @@ static int RSurf_LightCheck(const matrix4x4_t *matrix, const int *dlightbits, su static void RSurfShader_Sky(const entity_render_t *ent, const msurface_t *firstsurf) { const msurface_t *surf; - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; // LordHavoc: HalfLife maps have freaky skypolys... @@ -865,7 +825,7 @@ static void RSurfShader_Sky(const entity_render_t *ent, const msurface_t *firsts if (R_Mesh_Draw_GetBuffer(&m, false)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); if (skyrendermasked) memset(m.color, 0, m.numverts * sizeof(float[4])); else @@ -879,9 +839,9 @@ static void RSurfShader_Sky(const entity_render_t *ent, const msurface_t *firsts static void RSurfShader_Water_Callback(const void *calldata1, int calldata2) { const entity_render_t *ent = calldata1; - msurface_t *surf = ent->model->surfaces + calldata2; + const msurface_t *surf = ent->model->surfaces + calldata2; float f; - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; float alpha = ent->alpha * (surf->flags & SURF_DRAWNOALPHA ? 1 : r_wateralpha.value); float modelorg[3]; @@ -912,8 +872,8 @@ static void RSurfShader_Water_Callback(const void *calldata1, int calldata2) if (R_Mesh_Draw_GetBuffer(&m, true)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); f = surf->flags & SURF_DRAWFULLBRIGHT ? 1.0f : ((surf->flags & SURF_LIGHTMAP) ? 0 : 0.5f); R_FillColors(m.color, m.numverts, f, f, f, alpha); if (!(surf->flags & SURF_DRAWFULLBRIGHT || ent->effects & EF_FULLBRIGHT)) @@ -921,7 +881,7 @@ static void RSurfShader_Water_Callback(const void *calldata1, int calldata2) if (surf->dlightframe == r_framecount) RSurf_LightSeparate(&ent->inversematrix, surf->dlightbits, m.numverts, m.vertex, m.color); if (surf->flags & SURF_LIGHTMAP) - RSurf_AddLightmapToVertexColors(mesh->vertex, m.color, m.numverts, surf->samples, ((surf->extents[0]>>4)+1)*((surf->extents[1]>>4)+1)*3, surf->styles); + RSurf_AddLightmapToVertexColors(mesh->lightmapoffsets, m.color, m.numverts, surf->samples, ((surf->extents[0]>>4)+1)*((surf->extents[1]>>4)+1)*3, surf->styles); } RSurf_FogColors(m.vertex, m.color, m.colorscale, m.numverts, modelorg); R_Mesh_Render(); @@ -942,9 +902,9 @@ static void RSurfShader_Water_Callback(const void *calldata1, int calldata2) if (R_Mesh_Draw_GetBuffer(&m, false)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); if (m.tex[0]) - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); RSurf_FogPassColors(m.vertex, m.color, fogcolor[0], fogcolor[1], fogcolor[2], alpha, m.colorscale, m.numverts, modelorg); R_Mesh_Render(); } @@ -971,7 +931,7 @@ static void RSurfShader_Water(const entity_render_t *ent, const msurface_t *firs static void RSurfShader_Wall_Pass_BaseVertex(const entity_render_t *ent, const msurface_t *surf) { float base; - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; float modelorg[3]; Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg); @@ -1001,15 +961,15 @@ static void RSurfShader_Wall_Pass_BaseVertex(const entity_render_t *ent, const m if (R_Mesh_Draw_GetBuffer(&m, true)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); R_FillColors(m.color, m.numverts, base, base, base, ent->alpha); if (!(ent->effects & EF_FULLBRIGHT)) { if (surf->dlightframe == r_framecount) RSurf_LightSeparate(&ent->inversematrix, surf->dlightbits, m.numverts, m.vertex, m.color); if (surf->flags & SURF_LIGHTMAP) - RSurf_AddLightmapToVertexColors(mesh->vertex, m.color, m.numverts, surf->samples, ((surf->extents[0]>>4)+1)*((surf->extents[1]>>4)+1)*3, surf->styles); + RSurf_AddLightmapToVertexColors(mesh->lightmapoffsets, m.color, m.numverts, surf->samples, ((surf->extents[0]>>4)+1)*((surf->extents[1]>>4)+1)*3, surf->styles); } RSurf_FogColors(m.vertex, m.color, m.colorscale, m.numverts, modelorg); R_Mesh_Render(); @@ -1019,7 +979,7 @@ static void RSurfShader_Wall_Pass_BaseVertex(const entity_render_t *ent, const m static void RSurfShader_Wall_Pass_BaseFullbright(const entity_render_t *ent, const msurface_t *surf) { - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; float modelorg[3]; Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg); @@ -1048,8 +1008,8 @@ static void RSurfShader_Wall_Pass_BaseFullbright(const entity_render_t *ent, con if (R_Mesh_Draw_GetBuffer(&m, false)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); RSurf_FoggedColors(m.vertex, m.color, 1, 1, 1, ent->alpha, m.colorscale, m.numverts, modelorg); R_Mesh_Render(); } @@ -1058,7 +1018,7 @@ static void RSurfShader_Wall_Pass_BaseFullbright(const entity_render_t *ent, con static void RSurfShader_Wall_Pass_Glow(const entity_render_t *ent, const msurface_t *surf) { - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; float modelorg[3]; Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg); @@ -1074,8 +1034,8 @@ static void RSurfShader_Wall_Pass_Glow(const entity_render_t *ent, const msurfac if (R_Mesh_Draw_GetBuffer(&m, false)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); RSurf_FoggedColors(m.vertex, m.color, 1, 1, 1, ent->alpha, m.colorscale, m.numverts, modelorg); R_Mesh_Render(); } @@ -1084,7 +1044,7 @@ static void RSurfShader_Wall_Pass_Glow(const entity_render_t *ent, const msurfac static void RSurfShader_Wall_Pass_Fog(const entity_render_t *ent, const msurface_t *surf) { - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; float modelorg[3]; Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg); @@ -1100,9 +1060,9 @@ static void RSurfShader_Wall_Pass_Fog(const entity_render_t *ent, const msurface if (R_Mesh_Draw_GetBuffer(&m, false)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); if (m.tex[0]) - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); RSurf_FogPassColors(m.vertex, m.color, fogcolor[0], fogcolor[1], fogcolor[2], ent->alpha, m.colorscale, m.numverts, modelorg); R_Mesh_Render(); } @@ -1111,10 +1071,10 @@ static void RSurfShader_Wall_Pass_Fog(const entity_render_t *ent, const msurface static void RSurfShader_OpaqueWall_Pass_TripleTexCombine(const entity_render_t *ent, const msurface_t *surf) { - surfmesh_t *mesh; - rmeshbufferinfo_t m; + const surfmesh_t *mesh; + static rmeshbufferinfo_t m; float cl; - memset(&m, 0, sizeof(m)); + //memset(&m, 0, sizeof(m)); m.blendfunc1 = GL_ONE; m.blendfunc2 = GL_ZERO; m.tex[0] = R_GetTexture(surf->currenttexture->texture); @@ -1131,12 +1091,12 @@ static void RSurfShader_OpaqueWall_Pass_TripleTexCombine(const entity_render_t * if (R_Mesh_Draw_GetBuffer(&m, false)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); + memcpy(m.texcoords[1], mesh->uv, m.numverts * sizeof(float[2])); + memcpy(m.texcoords[2], mesh->ab, m.numverts * sizeof(float[2])); cl = (float) (1 << lightscalebit) * m.colorscale; R_FillColors(m.color, m.numverts, cl, cl, cl, 1); - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); - RSurf_CopyUV(mesh->vertex, m.texcoords[1], m.numverts); - RSurf_CopyAB(mesh->vertex, m.texcoords[2], m.numverts); R_Mesh_Render(); } } @@ -1144,7 +1104,7 @@ static void RSurfShader_OpaqueWall_Pass_TripleTexCombine(const entity_render_t * static void RSurfShader_OpaqueWall_Pass_BaseMTex(const entity_render_t *ent, const msurface_t *surf) { - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; float cl; memset(&m, 0, sizeof(m)); @@ -1160,11 +1120,11 @@ static void RSurfShader_OpaqueWall_Pass_BaseMTex(const entity_render_t *ent, con if (R_Mesh_Draw_GetBuffer(&m, true)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); + memcpy(m.texcoords[1], mesh->uv, m.numverts * sizeof(float[2])); cl = (float) (1 << lightscalebit) * m.colorscale; R_FillColors(m.color, m.numverts, cl, cl, cl, 1); - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); - RSurf_CopyUV(mesh->vertex, m.texcoords[1], m.numverts); R_Mesh_Render(); } } @@ -1172,7 +1132,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseMTex(const entity_render_t *ent, con static void RSurfShader_OpaqueWall_Pass_BaseTexture(const entity_render_t *ent, const msurface_t *surf) { - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; float cl; memset(&m, 0, sizeof(m)); @@ -1187,10 +1147,10 @@ static void RSurfShader_OpaqueWall_Pass_BaseTexture(const entity_render_t *ent, if (R_Mesh_Draw_GetBuffer(&m, false)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); cl = m.colorscale; R_FillColors(m.color, m.numverts, cl, cl, cl, 1); - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); R_Mesh_Render(); } } @@ -1198,7 +1158,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseTexture(const entity_render_t *ent, static void RSurfShader_OpaqueWall_Pass_BaseLightmap(const entity_render_t *ent, const msurface_t *surf) { - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; float cl; memset(&m, 0, sizeof(m)); @@ -1213,10 +1173,10 @@ static void RSurfShader_OpaqueWall_Pass_BaseLightmap(const entity_render_t *ent, if (R_Mesh_Draw_GetBuffer(&m, true)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); + memcpy(m.texcoords[0], mesh->uv, m.numverts * sizeof(float[2])); cl = (float) (1 << lightscalebit) * m.colorscale; R_FillColors(m.color, m.numverts, cl, cl, cl, 1); - RSurf_CopyUV(mesh->vertex, m.texcoords[0], m.numverts); R_Mesh_Render(); } } @@ -1224,7 +1184,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseLightmap(const entity_render_t *ent, static void RSurfShader_OpaqueWall_Pass_Light(const entity_render_t *ent, const msurface_t *surf) { - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; if (surf->dlightframe != r_framecount) @@ -1246,8 +1206,8 @@ static void RSurfShader_OpaqueWall_Pass_Light(const entity_render_t *ent, const if (R_Mesh_Draw_GetBuffer(&m, true)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); R_FillColors(m.color, m.numverts, 0, 0, 0, 1); RSurf_LightSeparate(&ent->inversematrix, surf->dlightbits, m.numverts, m.vertex, m.color); RSurf_ScaleColors(m.color, m.colorscale, m.numverts); @@ -1259,7 +1219,7 @@ static void RSurfShader_OpaqueWall_Pass_Light(const entity_render_t *ent, const static void RSurfShader_OpaqueWall_Pass_Fog(const entity_render_t *ent, const msurface_t *surf) { - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; float modelorg[3]; Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg); @@ -1275,9 +1235,9 @@ static void RSurfShader_OpaqueWall_Pass_Fog(const entity_render_t *ent, const ms if (R_Mesh_Draw_GetBuffer(&m, false)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); if (m.tex[0]) - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); RSurf_FogPassColors(m.vertex, m.color, fogcolor[0], fogcolor[1], fogcolor[2], 1, m.colorscale, m.numverts, modelorg); R_Mesh_Render(); } @@ -1286,7 +1246,7 @@ static void RSurfShader_OpaqueWall_Pass_Fog(const entity_render_t *ent, const ms static void RSurfShader_OpaqueWall_Pass_BaseDetail(const entity_render_t *ent, const msurface_t *surf) { - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; memset(&m, 0, sizeof(m)); m.blendfunc1 = GL_DST_COLOR; @@ -1300,9 +1260,9 @@ static void RSurfShader_OpaqueWall_Pass_BaseDetail(const entity_render_t *ent, c if (R_Mesh_Draw_GetBuffer(&m, false)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); + memcpy(m.texcoords[0], mesh->ab, m.numverts * sizeof(float[2])); R_FillColors(m.color, m.numverts, 1, 1, 1, 1); - RSurf_CopyAB(mesh->vertex, m.texcoords[0], m.numverts); R_Mesh_Render(); } } @@ -1310,7 +1270,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseDetail(const entity_render_t *ent, c static void RSurfShader_OpaqueWall_Pass_Glow(const entity_render_t *ent, const msurface_t *surf) { - surfmesh_t *mesh; + const surfmesh_t *mesh; rmeshbufferinfo_t m; memset(&m, 0, sizeof(m)); m.blendfunc1 = GL_SRC_ALPHA; @@ -1324,9 +1284,9 @@ static void RSurfShader_OpaqueWall_Pass_Glow(const entity_render_t *ent, const m if (R_Mesh_Draw_GetBuffer(&m, false)) { memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3])); - RSurf_CopyXYZ(mesh->vertex, m.vertex, m.numverts); + memcpy(m.vertex, mesh->verts, m.numverts * sizeof(float[4])); + memcpy(m.texcoords[0], mesh->st, m.numverts * sizeof(float[2])); R_FillColors(m.color, m.numverts, m.colorscale, m.colorscale, m.colorscale, 1); - RSurf_CopyST(mesh->vertex, m.texcoords[0], m.numverts); R_Mesh_Render(); } } diff --git a/model_brush.c b/model_brush.c index 4eec6da8..28aa2d24 100644 --- a/model_brush.c +++ b/model_brush.c @@ -1106,92 +1106,51 @@ void Mod_GenerateWarpMesh (msurface_t *surf) } #endif -void Mod_GenerateVertexLitMesh (msurface_t *surf) +void Mod_GenerateWallMesh (msurface_t *surf, int vertexonly) { - int i, is, it, *index, smax, tmax; - float *in, s, t; - surfvertex_t *out; - surfmesh_t *mesh; + int i, iu, iv, *index, smax, tmax; + float *in, s, t, u, v, ubase, vbase, uscale, vscale; + surfmesh_t *mesh; smax = surf->extents[0] >> 4; tmax = surf->extents[1] >> 4; - surf->lightmaptexturestride = 0; - surf->lightmaptexture = NULL; - - surf->mesh = mesh = Mem_Alloc(loadmodel->mempool, sizeof(surfmesh_t) + (surf->poly_numverts - 2) * sizeof(int[3]) + surf->poly_numverts * sizeof(surfvertex_t)); - mesh->numverts = surf->poly_numverts; - mesh->numtriangles = surf->poly_numverts - 2; - mesh->vertex = (surfvertex_t *)(mesh + 1); - mesh->index = (int *)(mesh->vertex + mesh->numverts); - memset(mesh->vertex, 0, mesh->numverts * sizeof(surfvertex_t)); - - index = mesh->index; - for (i = 0;i < mesh->numtriangles;i++) - { - *index++ = 0; - *index++ = i + 1; - *index++ = i + 2; - } - - for (i = 0, in = surf->poly_verts, out = mesh->vertex;i < mesh->numverts;i++, in += 3, out++) - { - VectorCopy (in, out->v); - - s = DotProduct (out->v, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]; - t = DotProduct (out->v, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]; - - out->ab[0] = s * (1.0f / 16.0f); - out->ab[1] = t * (1.0f / 16.0f); - - out->st[0] = s / surf->texinfo->texture->width; - out->st[1] = t / surf->texinfo->texture->height; - - s = (s + 8 - surf->texturemins[0]) * (1.0 / 16.0); - t = (t + 8 - surf->texturemins[1]) * (1.0 / 16.0); - - // lightmap coordinates - out->uv[0] = 0; - out->uv[1] = 0; - - // LordHavoc: calc lightmap data offset for vertex lighting to use - is = (int) s; - it = (int) t; - is = bound(0, is, smax); - it = bound(0, it, tmax); - out->lightmapoffset = ((it * (smax+1) + is) * 3); - } -} - -void Mod_GenerateLightmappedMesh (msurface_t *surf) -{ - int i, is, it, *index, smax, tmax; - float *in, s, t, xbase, ybase, xscale, yscale; - surfvertex_t *out; - surfmesh_t *mesh; - surf->flags |= SURF_LIGHTMAP; - smax = surf->extents[0] >> 4; - tmax = surf->extents[1] >> 4; - if (r_miplightmaps.integer) + if (vertexonly) { - surf->lightmaptexturestride = (surf->extents[0]>>4)+1; - surf->lightmaptexture = R_LoadTexture(loadmodel->texturepool, NULL, surf->lightmaptexturestride, (surf->extents[1]>>4)+1, NULL, loadmodel->lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, TEXF_MIPMAP | TEXF_PRECACHE); + surf->lightmaptexturestride = 0; + surf->lightmaptexture = NULL; + uscale = 0; + vscale = 0; + ubase = 0; + vbase = 0; } else { - surf->lightmaptexturestride = R_CompatibleFragmentWidth((surf->extents[0]>>4)+1, loadmodel->lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, 0); - surf->lightmaptexture = R_LoadTexture(loadmodel->texturepool, NULL, surf->lightmaptexturestride, (surf->extents[1]>>4)+1, NULL, loadmodel->lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, TEXF_FRAGMENT | TEXF_PRECACHE); + surf->flags |= SURF_LIGHTMAP; + if (r_miplightmaps.integer) + { + surf->lightmaptexturestride = (surf->extents[0]>>4)+1; + surf->lightmaptexture = R_LoadTexture(loadmodel->texturepool, NULL, surf->lightmaptexturestride, (surf->extents[1]>>4)+1, NULL, loadmodel->lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, TEXF_MIPMAP | TEXF_PRECACHE); + } + else + { + surf->lightmaptexturestride = R_CompatibleFragmentWidth((surf->extents[0]>>4)+1, loadmodel->lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, 0); + surf->lightmaptexture = R_LoadTexture(loadmodel->texturepool, NULL, surf->lightmaptexturestride, (surf->extents[1]>>4)+1, NULL, loadmodel->lightmaprgba ? TEXTYPE_RGBA : TEXTYPE_RGB, TEXF_FRAGMENT | TEXF_PRECACHE); + } + R_FragmentLocation(surf->lightmaptexture, NULL, NULL, &ubase, &vbase, &uscale, &vscale); + uscale = (uscale - ubase) * 16.0 / ((surf->extents[0] & ~15) + 16); + vscale = (vscale - vbase) * 16.0 / ((surf->extents[1] & ~15) + 16); } - R_FragmentLocation(surf->lightmaptexture, NULL, NULL, &xbase, &ybase, &xscale, &yscale); - xscale = (xscale - xbase) * 16.0 / ((surf->extents[0] & ~15) + 16); - yscale = (yscale - ybase) * 16.0 / ((surf->extents[1] & ~15) + 16); - surf->mesh = mesh = Mem_Alloc(loadmodel->mempool, sizeof(surfmesh_t) + (surf->poly_numverts - 2) * sizeof(int[3]) + surf->poly_numverts * sizeof(surfvertex_t)); + surf->mesh = mesh = Mem_Alloc(loadmodel->mempool, sizeof(surfmesh_t) + (surf->poly_numverts - 2) * sizeof(int[3]) + surf->poly_numverts * (4 + 2 + 2 + 2 + 1) * sizeof(float)); mesh->numverts = surf->poly_numverts; mesh->numtriangles = surf->poly_numverts - 2; - mesh->vertex = (surfvertex_t *)(mesh + 1); - mesh->index = (int *)(mesh->vertex + mesh->numverts); - memset(mesh->vertex, 0, mesh->numverts * sizeof(surfvertex_t)); + mesh->verts = (float *)(mesh + 1); + mesh->st = mesh->verts + mesh->numverts * 4; + mesh->uv = mesh->st + mesh->numverts * 2; + mesh->ab = mesh->uv + mesh->numverts * 2; + mesh->lightmapoffsets = (int *)(mesh->ab + mesh->numverts * 2); + mesh->index = mesh->lightmapoffsets + mesh->numverts; index = mesh->index; for (i = 0;i < mesh->numtriangles;i++) @@ -1201,51 +1160,47 @@ void Mod_GenerateLightmappedMesh (msurface_t *surf) *index++ = i + 2; } - for (i = 0, in = surf->poly_verts, out = mesh->vertex;i < mesh->numverts;i++, in += 3, out++) + for (i = 0, in = surf->poly_verts;i < mesh->numverts;i++, in += 3) { - VectorCopy (in, out->v); - - s = DotProduct (out->v, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]; - t = DotProduct (out->v, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]; - - out->ab[0] = s * (1.0f / 16.0f); - out->ab[1] = t * (1.0f / 16.0f); - - out->st[0] = s / surf->texinfo->texture->width; - out->st[1] = t / surf->texinfo->texture->height; - - s = (s + 8 - surf->texturemins[0]) * (1.0 / 16.0); - t = (t + 8 - surf->texturemins[1]) * (1.0 / 16.0); - - // lightmap coordinates - out->uv[0] = s * xscale + xbase; - out->uv[1] = t * yscale + ybase; - + s = DotProduct (in, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]; + t = DotProduct (in, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]; + u = (s + 8 - surf->texturemins[0]) * (1.0 / 16.0) * uscale + ubase; + v = (t + 8 - surf->texturemins[1]) * (1.0 / 16.0) * vscale + vbase; // LordHavoc: calc lightmap data offset for vertex lighting to use - is = (int) s; - it = (int) t; - is = bound(0, is, smax); - it = bound(0, it, tmax); - out->lightmapoffset = ((it * (smax+1) + is) * 3); + iu = (int) u; + iv = (int) v; + iu = bound(0, iu, smax); + iv = bound(0, iv, tmax); + + mesh->verts[i * 4 + 0] = in[0]; + mesh->verts[i * 4 + 1] = in[1]; + mesh->verts[i * 4 + 2] = in[2]; + mesh->st[i * 2 + 0] = s / surf->texinfo->texture->width; + mesh->st[i * 2 + 1] = t / surf->texinfo->texture->height; + mesh->uv[i * 2 + 0] = u; + mesh->uv[i * 2 + 1] = v; + mesh->ab[i * 2 + 0] = s * (1.0f / 16.0f); + mesh->ab[i * 2 + 1] = t * (1.0f / 16.0f); + mesh->lightmapoffsets[i] = ((iv * (smax+1) + iu) * 3); } } void Mod_GenerateVertexMesh (msurface_t *surf) { - int i, *index; - float *in, s, t; - surfvertex_t *out; - surfmesh_t *mesh; + int i, *index; + float *in, s, t; + surfmesh_t *mesh; surf->lightmaptexturestride = 0; surf->lightmaptexture = NULL; - surf->mesh = mesh = Mem_Alloc(loadmodel->mempool, sizeof(surfmesh_t) + (surf->poly_numverts - 2) * sizeof(int[3]) + surf->poly_numverts * sizeof(surfvertex_t)); + surf->mesh = mesh = Mem_Alloc(loadmodel->mempool, sizeof(surfmesh_t) + (surf->poly_numverts - 2) * sizeof(int[3]) + surf->poly_numverts * (4 + 2 + 2) * sizeof(float)); mesh->numverts = surf->poly_numverts; mesh->numtriangles = surf->poly_numverts - 2; - mesh->vertex = (surfvertex_t *)(mesh + 1); - mesh->index = (int *)(mesh->vertex + mesh->numverts); - memset(mesh->vertex, 0, mesh->numverts * sizeof(surfvertex_t)); + mesh->verts = (float *)(mesh + 1); + mesh->st = mesh->verts + mesh->numverts * 4; + mesh->ab = mesh->st + mesh->numverts * 2; + mesh->index = (int *)(mesh->ab + mesh->numverts * 2); index = mesh->index; for (i = 0;i < mesh->numtriangles;i++) @@ -1255,15 +1210,17 @@ void Mod_GenerateVertexMesh (msurface_t *surf) *index++ = i + 2; } - for (i = 0, in = surf->poly_verts, out = mesh->vertex;i < mesh->numverts;i++, in += 3, out++) + for (i = 0, in = surf->poly_verts;i < mesh->numverts;i++, in += 3) { - VectorCopy (in, out->v); - s = (DotProduct (out->v, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]); - t = (DotProduct (out->v, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]); - out->st[0] = s / surf->texinfo->texture->width; - out->st[1] = t / surf->texinfo->texture->height; - out->ab[0] = s * (1.0f / 16.0f); - out->ab[1] = t * (1.0f / 16.0f); + s = (DotProduct (in, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]); + t = (DotProduct (in, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]); + mesh->verts[i * 4 + 0] = in[0]; + mesh->verts[i * 4 + 1] = in[1]; + mesh->verts[i * 4 + 2] = in[2]; + mesh->st[i * 2 + 0] = s / surf->texinfo->texture->width; + mesh->st[i * 2 + 1] = t / surf->texinfo->texture->height; + mesh->ab[i * 2 + 0] = s * (1.0f / 16.0f); + mesh->ab[i * 2 + 1] = t * (1.0f / 16.0f); } } @@ -1303,55 +1260,6 @@ void Mod_GenerateSurfacePolygon (msurface_t *surf) surf->poly_center[2] = (mins[2] + maxs[2]) * 0.5f; } -static void Mod_SplitSurfMeshIfTooBig(msurface_t *s) -{ - int j, base, tricount, newvertexcount, *index, *vertexremap; - surfmesh_t *newmesh, *oldmesh, *firstmesh; - if (s->mesh->numtriangles > 1000) - { - vertexremap = Mem_Alloc(tempmempool, s->mesh->numverts * sizeof(int)); - base = 0; - oldmesh = NULL; - firstmesh = NULL; - newmesh = NULL; - while (base < s->mesh->numtriangles) - { - tricount = s->mesh->numtriangles - base; - if (tricount > 1000) - tricount = 1000; - index = s->mesh->index + base * 3; - base += tricount; - - newvertexcount = 0; - memset(vertexremap, -1, s->mesh->numverts * sizeof(int)); - for (j = 0;j < tricount * 3;j++) - if (vertexremap[index[j]] < 0) - vertexremap[index[j]] = newvertexcount++; - - newmesh = Mem_Alloc(loadmodel->mempool, sizeof(surfmesh_t) + newvertexcount * sizeof(surfvertex_t) + tricount * sizeof(int[3])); - newmesh->chain = NULL; - newmesh->numverts = newvertexcount; - newmesh->numtriangles = tricount; - newmesh->vertex = (surfvertex_t *)(newmesh + 1); - newmesh->index = (int *)(newmesh->vertex + newvertexcount); - for (j = 0;j < tricount * 3;j++) - { - newmesh->index[j] = vertexremap[index[j]]; - // yes this copies the same vertex multiple times in many cases... but that's ok... - memcpy(&newmesh->vertex[newmesh->index[j]], &s->mesh->vertex[index[j]], sizeof(surfvertex_t)); - } - if (oldmesh) - oldmesh->chain = newmesh; - else - firstmesh = newmesh; - oldmesh = newmesh; - } - Mem_Free(vertexremap); - Mem_Free(s->mesh); - s->mesh = firstmesh; - } -} - /* ================= Mod_LoadFaces @@ -1461,16 +1369,15 @@ static void Mod_LoadFaces (lump_t *l) if (out->extents[0] < r_vertexsurfacesthreshold.integer && out->extents[1] < r_vertexsurfacesthreshold.integer) { out->shader = &Cshader_wall_vertex; - Mod_GenerateVertexLitMesh(out); + Mod_GenerateWallMesh (out, true); } else { out->shader = &Cshader_wall_lightmap; - Mod_GenerateLightmappedMesh(out); + Mod_GenerateWallMesh (out, false); } } } - Mod_SplitSurfMeshIfTooBig(out); } } diff --git a/model_brush.h b/model_brush.h index cd53901d..36d0a605 100644 --- a/model_brush.h +++ b/model_brush.h @@ -108,21 +108,6 @@ typedef struct } mtexinfo_t; -typedef struct surfvertex_s -{ - // position - float v[3]; - // offset into lightmap (used by vertex lighting) - int lightmapoffset; - // texture coordinates - float st[2]; - // lightmap coordinates - float uv[2]; - // detail texture coordinates - float ab[2]; -} -surfvertex_t; - // LordHavoc: replaces glpoly, triangle mesh typedef struct surfmesh_s { @@ -130,7 +115,11 @@ typedef struct surfmesh_s struct surfmesh_s *chain; int numverts; int numtriangles; - surfvertex_t *vertex; + float *verts; + int *lightmapoffsets; + float *st; + float *uv; + float *ab; int *index; } surfmesh_t; -- 2.39.2