- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- vertex3f = RSurf_GetVertexPointer(ent, surface);
- R_Mesh_VertexPointer(vertex3f);
- R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
- for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- c[0] = 0;
- c[1] = 0;
- c[2] = 0;
- if (surface->styles[0] != 255)
- {
- if (surface->mesh.data_lightmapcolor4f)
- {
- float scale = d_lightstylevalue[surface->styles[0]] * (1.0f / 128.0f);
- VectorMA(c, scale, surface->mesh.data_lightmapcolor4f + i*4, c);
- }
- else if (surface->mesh.data_lightmapoffsets)
- {
- const qbyte *lm = surface->samples + surface->mesh.data_lightmapoffsets[i];
- float scale = d_lightstylevalue[surface->styles[0]] * (1.0f / 32768.0f);
- VectorMA(c, scale, lm, c);
- if (surface->styles[1] != 255)
- {
- int size3 = ((surface->extents[0]>>4)+1)*((surface->extents[1]>>4)+1)*3;
- lm += size3;
- scale = d_lightstylevalue[surface->styles[1]] * (1.0f / 32768.0f);
- VectorMA(c, scale, lm, c);
- if (surface->styles[2] != 255)
- {
- lm += size3;
- scale = d_lightstylevalue[surface->styles[2]] * (1.0f / 32768.0f);
- VectorMA(c, scale, lm, c);
- if (surface->styles[3] != 255)
- {
- lm += size3;
- scale = d_lightstylevalue[surface->styles[3]] * (1.0f / 32768.0f);
- VectorMA(c, scale, lm, c);
- }
- }
- }
- }
- }
- c[0] *= r;
- c[1] *= g;
- c[2] *= b;
- if (fogallpasses)
- {
- VectorSubtract(v, modelorg, diff);
- f = 1 - exp(fogdensity/DotProduct(diff, diff));
- VectorScale(c, f, c);
- }
- if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
- c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
- else
- c[3] = a;
- }
- 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 (fogallpasses)
- {
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- vertex3f = RSurf_GetVertexPointer(ent, surface);
- R_Mesh_VertexPointer(vertex3f);
- R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
- if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
- {
- R_Mesh_ColorPointer(varray_color4f);
- for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- VectorSubtract(v, modelorg, diff);
- f = 1 - exp(fogdensity/DotProduct(diff, diff));
- c[0] = r * f;
- c[1] = g * f;
- c[2] = b * f;
- c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
- }
- }
- else
- {
- R_Mesh_ColorPointer(varray_color4f);
- for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- VectorSubtract(v, modelorg, diff);
- f = 1 - exp(fogdensity/DotProduct(diff, diff));
- c[0] = r * f;
- c[1] = g * f;
- c[2] = b * f;
- c[3] = a;
- }
- }
- 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);
- }
- }
- else
- {
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- vertex3f = RSurf_GetVertexPointer(ent, surface);
- R_Mesh_VertexPointer(vertex3f);
- R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
- if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
- {
- R_Mesh_ColorPointer(varray_color4f);
- for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- c[0] = r;
- c[1] = g;
- c[2] = b;
- c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
- }
- }
- else
- {
- R_Mesh_ColorPointer(NULL);
- GL_Color(r, g, b, a);
- }
- 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);
- }
- }