- dolightmap = false;
- dobase = false;
- GL_Color(0, 0, 0, 1);
- memset(&m, 0, sizeof(m));
- R_Mesh_State(&m);
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
- GL_LockArrays(0, surface->num_vertices);
- R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
- GL_LockArrays(0, 0);
- }
- }
- if (r_textureunits.integer >= 2 && gl_combine.integer && dolightmap && dobase)
- {
- // dualtexture combine
- GL_BlendFunc(GL_ONE, GL_ZERO);
- GL_DepthMask(true);
- dolightmap = false;
- dobase = false;
- memset(&m, 0, sizeof(m));
- m.tex[1] = R_GetTexture(texture->skin.base);
- if (waterscrolling)
- m.texmatrix[1] = r_surf_waterscrollmatrix;
- m.texrgbscale[1] = 2;
- R_Mesh_State(&m);
- r = ent->colormod[0] * r_lightmapintensity;
- g = ent->colormod[1] * r_lightmapintensity;
- b = ent->colormod[2] * r_lightmapintensity;
- GL_Color(r, g, b, 1);
- if (texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
- {
- R_Mesh_VertexPointer(varray_vertex3f);
- if (r == 1 && g == 1 && b == 1)
- {
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- RSurf_DeformVertices(ent, texture, surface, modelorg);
- R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
- R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
- if (surface->lightmaptexture)
- {
- R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
- R_Mesh_ColorPointer(NULL);
- }
- else //if (r == 1 && g == 1 && b == 1)
- {
- R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
- R_Mesh_ColorPointer((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
- }
- GL_LockArrays(0, surface->num_vertices);
- R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
- GL_LockArrays(0, 0);
- }
- }
- else
- {
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- RSurf_DeformVertices(ent, texture, surface, modelorg);
- R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
- R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
- if (surface->lightmaptexture)
- {
- R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
- R_Mesh_ColorPointer(NULL);
- }
- else
- {
- R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
- R_Mesh_ColorPointer(varray_color4f);
- for (i = 0;i < surface->num_vertices;i++)
- {
- varray_color4f[i*4+0] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+0] * r;
- varray_color4f[i*4+1] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+1] * g;
- varray_color4f[i*4+2] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+2] * b;
- varray_color4f[i*4+3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3];
- }
- }
- GL_LockArrays(0, surface->num_vertices);
- R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
- GL_LockArrays(0, 0);
- }
- }
- }
- else
- {
- if (r == 1 && g == 1 && b == 1)
- {
-#if 0
- // experimental direct state calls for measuring
- // R_Mesh_ call overhead, do not use!
- R_Mesh_VertexPointer(varray_vertex3f);
- R_Mesh_TexCoordPointer(0, 2, varray_texcoord2f[0]);
- R_Mesh_TexCoordPointer(1, 2, varray_texcoord2f[1]);
- R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
- R_Mesh_ColorPointer(varray_color4f);
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
- qglClientActiveTexture(GL_TEXTURE0_ARB);
- qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
- qglClientActiveTexture(GL_TEXTURE1_ARB);
- qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
- if (surface->lightmaptexture)
- {
- R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
- qglDisableClientState(GL_COLOR_ARRAY);
- qglColor4f(r, g, b, 1);
- }
- else //if (r == 1 && g == 1 && b == 1)
- {
- R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
- qglEnableClientState(GL_COLOR_ARRAY);
- qglColorPointer(4, GL_FLOAT, sizeof(float[4]), (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
- }
- qglLockArraysEXT(0, surface->num_vertices);
- qglDrawRangeElements(GL_TRIANGLES, 0, surface->num_vertices, surface->num_triangles * 3, GL_UNSIGNED_INT, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
- qglUnlockArraysEXT();
- }
-#else
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- R_Mesh_VertexPointer((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
- R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
- R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
- if (surface->lightmaptexture)
- {
- R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
- R_Mesh_ColorPointer(NULL);
- }
- else //if (r == 1 && g == 1 && b == 1)
- {
- R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
- R_Mesh_ColorPointer((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
- }
- GL_LockArrays(0, surface->num_vertices);
- R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
- GL_LockArrays(0, 0);
- }
-#endif
- }
- else
- {
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- R_Mesh_VertexPointer((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
- R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
- R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
- if (surface->lightmaptexture)
- {
- R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
- R_Mesh_ColorPointer(NULL);
- }
- else
- {
- R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
- R_Mesh_ColorPointer(varray_color4f);
- for (i = 0;i < surface->num_vertices;i++)
- {
- varray_color4f[i*4+0] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+0] * r;
- varray_color4f[i*4+1] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+1] * g;
- varray_color4f[i*4+2] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+2] * b;
- varray_color4f[i*4+3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3];
- }
- }
- GL_LockArrays(0, surface->num_vertices);
- R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
- GL_LockArrays(0, 0);
- }
- }
- }
- }
- // single texture
- if (dolightmap)
- {
- GL_BlendFunc(GL_ONE, GL_ZERO);
- GL_DepthMask(true);
- GL_Color(1, 1, 1, 1);
- memset(&m, 0, sizeof(m));
- R_Mesh_State(&m);
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
- R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
- R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
- R_Mesh_ColorPointer(surface->lightmaptexture ? NULL : (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
- GL_LockArrays(0, surface->num_vertices);
- R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
- GL_LockArrays(0, 0);
- }
- }
- if (dobase)
- {
- GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
- GL_DepthMask(false);
- GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
- memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(texture->skin.base);
- if (waterscrolling)
- m.texmatrix[0] = r_surf_waterscrollmatrix;
- R_Mesh_State(&m);
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)