- surface = texturesurfacelist[texturesurfaceindex];
- m.tex[1] = R_GetTexture(surface->lightmaptexture);
- m.pointer_vertex = surface->mesh.data_vertex3f;
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
- R_Mesh_State(&m);
- GL_LockArrays(0, surface->mesh.num_vertices);
- R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
- GL_LockArrays(0, 0);
- }
- }
- }
- // anything not handled above
- if (dobase)
- {
- GL_BlendFunc(GL_ONE, GL_ZERO);
- GL_DepthMask(true);
- GL_DepthTest(true);
- GL_Color(1, 1, 1, 1);
- if (ent->flags & RENDER_LIGHT)
- GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
- else
- GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], 1);
- memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(texture->skin.base);
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = surface->mesh.data_vertex3f;
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- R_Mesh_State(&m);
- GL_LockArrays(0, surface->mesh.num_vertices);
- R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
- GL_LockArrays(0, 0);
- }
- }
- GL_DepthMask(false);
- if (dolightmap)
- {
- GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
- GL_DepthMask(false);
- GL_DepthTest(true);
- GL_Color(1, 1, 1, 1);
- memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(texture->skin.base);
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.tex[0] = R_GetTexture(surface->lightmaptexture);
- m.pointer_vertex = surface->mesh.data_vertex3f;
- m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
- R_Mesh_State(&m);
- GL_LockArrays(0, surface->mesh.num_vertices);
- R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
- GL_LockArrays(0, 0);
- }
- }
- if (doambient)
- {
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
- GL_DepthMask(false);
- GL_DepthTest(true);
- memset(&m, 0, sizeof(m));
- GL_Color(r_ambient.value * (1.0f / 128.0f) * ent->colormod[0], r_ambient.value * (1.0f / 128.0f) * ent->colormod[1], r_ambient.value * (1.0f / 128.0f) * ent->colormod[2], 1);
- m.tex[0] = R_GetTexture(texture->skin.base);
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = surface->mesh.data_vertex3f;
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- R_Mesh_State(&m);
- GL_LockArrays(0, surface->mesh.num_vertices);
- R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
- GL_LockArrays(0, 0);
- }
- }
- if (dodetail)
- {
- GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
- GL_DepthMask(false);
- GL_DepthTest(true);
- GL_Color(1, 1, 1, 1);
- memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(texture->skin.detail);
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = surface->mesh.data_vertex3f;
- m.pointer_texcoord[0] = surface->mesh.data_texcoorddetail2f;
- R_Mesh_State(&m);
- GL_LockArrays(0, surface->mesh.num_vertices);
- R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
- GL_LockArrays(0, 0);
- }
- }
- if (doglow)
- {
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
- GL_DepthMask(false);
- GL_DepthTest(true);
- GL_Color(1, 1, 1, 1);
- memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(texture->skin.glow);
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = surface->mesh.data_vertex3f;
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- R_Mesh_State(&m);
- GL_LockArrays(0, surface->mesh.num_vertices);
- R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
- GL_LockArrays(0, 0);
- }
- }
- if (dofog)
- {
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- GL_DepthMask(false);
- GL_DepthTest(true);
- memset(&m, 0, sizeof(m));
- m.pointer_color = varray_color4f;
- m.tex[0] = R_GetTexture(texture->skin.glow);
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = surface->mesh.data_vertex3f;
- if (m.tex[0])
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- R_Mesh_State(&m);
- RSurf_FogPassColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], 1, 1, surface->mesh.num_vertices, modelorg);
- GL_LockArrays(0, surface->mesh.num_vertices);
- R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
- GL_LockArrays(0, 0);
- }
- }
- }
- else if (texture->flags & SURF_DRAWTURB)
- {
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- RSurfShader_Transparent_Callback(ent, surface - ent->model->brush.data_surfaces);
- }
- }
- else if (texture->flags & SURF_DRAWSKY)
- {
- if (skyrendernow)
- {
- skyrendernow = false;
- if (skyrendermasked)
- R_Sky();
- }
- // LordHavoc: HalfLife maps have freaky skypolys...
- if (!ent->model->brush.ishlbsp)
- {
- R_Mesh_Matrix(&ent->matrix);
- GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
- if (skyrendermasked)
- {
- // depth-only (masking)
- GL_ColorMask(0,0,0,0);
- // just to make sure that braindead drivers don't draw anything
- // despite that colormask...
- GL_BlendFunc(GL_ZERO, GL_ONE);
- }
- else
- {
- // fog sky
- GL_BlendFunc(GL_ONE, GL_ZERO);
- }
- GL_DepthMask(true);
- GL_DepthTest(true);
- memset(&m, 0, sizeof(m));
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = surface->mesh.data_vertex3f;
- R_Mesh_State(&m);
- GL_LockArrays(0, surface->mesh.num_vertices);
- R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
- GL_LockArrays(0, 0);
- }
- GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
- }
- }
-}
-
-void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
-{
- int i, j, f, flagsmask;
- msurface_t *surface, **surfacechain;
- texture_t *t, *texture;
- model_t *model = ent->model;
- vec3_t modelorg;
- const int maxsurfacelist = 1024;
- int numsurfacelist = 0;
- msurface_t *surfacelist[1024];
- if (model == NULL)
- return;
- R_Mesh_Matrix(&ent->matrix);
- Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
-
- if (ent != r_refdef.worldentity)
- {
- // because bmodels can be reused, we have to clear dlightframe every time
- surface = model->brush.data_surfaces + model->firstmodelsurface;
- for (i = 0;i < model->nummodelsurfaces;i++, surface++)
- surface->dlightframe = -1;
- }
-
- // update light styles
- if (!skysurfaces)
- {
- if (r_dynamic.integer && !r_rtdlight)
- R_MarkLights(ent);
- for (i = 0;i < model->brushq1.light_styles;i++)
- {
- if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]])
- {
- model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]];
- if ((surfacechain = model->brushq1.light_styleupdatechains[i]))
- for (;(surface = *surfacechain);surfacechain++)
- surface->cached_dlight = true;
- }
- }
- }
-
- R_UpdateTextureInfo(ent);
- flagsmask = skysurfaces ? SURF_DRAWSKY : (SURF_DRAWTURB | SURF_LIGHTMAP);
- f = 0;
- t = NULL;
- numsurfacelist = 0;
- for (i = 0, j = model->firstmodelsurface;i < model->nummodelsurfaces;i++, j++)
- {
- if (ent != r_refdef.worldentity || r_worldsurfacevisible[j])
- {
- surface = model->brush.data_surfaces + j;
- if (t != surface->texture)
- {
- if (numsurfacelist)
- {
- R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
- numsurfacelist = 0;
- }
- t = surface->texture;
- f = t->flags & flagsmask;
- texture = t->currentframe;
- }
- if (f)
- {
- // add face to draw list and update lightmap if necessary
- c_faces++;
- if (surface->cached_dlight && surface->lightmaptexture != NULL)
- R_BuildLightMap(ent, surface);
- surfacelist[numsurfacelist++] = surface;
- if (numsurfacelist >= maxsurfacelist)
- {
- R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
- numsurfacelist = 0;