- // look for embedded bmodels
- for (n = 0;n < cl_num_brushmodel_entities;n++)
- {
- ent = cl_brushmodel_entities[n];
- model = ent->model;
- if (model && model->name[0] == '*')
- {
- Mod_CheckLoaded(model);
- if (model->brush.data_nodes)
- {
- Matrix4x4_Transform(&ent->inversematrix, origin, org);
- R_StainNode(model->brush.data_nodes + model->brushq1.hulls[0].firstclipnode, model, org, radius, fcolor);
- }
- }
- }
-}
-
-
-/*
-=============================================================
-
- BRUSH MODELS
-
-=============================================================
-*/
-
-#ifdef LHREMOVESOON
-static void RSurf_AddLightmapToVertexColors_Color4f(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++, c += 4)
- {
- lm = samples + lightmapoffsets[i];
- scale = d_lightstylevalue[styles[0]] * (1.0f / 32768.0f);
- VectorMA(c, scale, lm, c);
- if (styles[1] != 255)
- {
- lm += size3;
- scale = d_lightstylevalue[styles[1]] * (1.0f / 32768.0f);
- VectorMA(c, scale, lm, c);
- if (styles[2] != 255)
- {
- lm += size3;
- scale = d_lightstylevalue[styles[2]] * (1.0f / 32768.0f);
- VectorMA(c, scale, lm, c);
- if (styles[3] != 255)
- {
- lm += size3;
- scale = d_lightstylevalue[styles[3]] * (1.0f / 32768.0f);
- VectorMA(c, scale, lm, c);
- }
- }
- }
- }
- }
-}
-#endif
-
-#ifdef LHREMOVESOON
-static void RSurf_FogColors_Vertex3f_Color4f(const float *v, float *c, float colorscale, int numverts, const float *modelorg)
-{
- int i;
- float diff[3], f;
- if (fogenabled)
- {
- for (i = 0;i < numverts;i++, v += 3, c += 4)
- {
- VectorSubtract(v, modelorg, diff);
- f = colorscale * (1 - exp(fogdensity/DotProduct(diff, diff)));
- VectorScale(c, f, c);
- }
- }
- else if (colorscale != 1)
- for (i = 0;i < numverts;i++, c += 4)
- VectorScale(c, colorscale, c);
-}
-#endif
-
-#ifdef LHREMOVESOON
-static void RSurf_FoggedColors_Vertex3f_Color4f(const float *v, float *c, float r, float g, float b, float a, float colorscale, int numverts, const float *modelorg)
-{
- int i;
- float diff[3], f;
- r *= colorscale;
- g *= colorscale;
- b *= colorscale;
- if (fogenabled)
- {
- for (i = 0;i < numverts;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;
- }
- }
- else
- {
- for (i = 0;i < numverts;i++, c += 4)
- {
- c[0] = r;
- c[1] = g;
- c[2] = b;
- c[3] = a;
- }
- }
-}
-#endif
-
-#ifdef LHREMOVESOON
-static void RSurf_FogPassColors_Vertex3f_Color4f(const float *v, float *c, float r, float g, float b, float a, float colorscale, int numverts, const float *modelorg)
-{
- int i;
- float diff[3], f;
- r *= colorscale;
- g *= colorscale;
- b *= colorscale;
- for (i = 0;i < numverts;i++, v += 3, c += 4)
- {
- VectorSubtract(v, modelorg, diff);
- f = exp(fogdensity/DotProduct(diff, diff));
- c[0] = r;
- c[1] = g;
- c[2] = b;
- c[3] = a * f;
- }
-}
-#endif
-
-#ifdef LHREMOVESOON
-static int RSurf_LightSeparate_Vertex3f_Color4f(const matrix4x4_t *matrix, const int *dlightbits, int numverts, const float *vert, float *color, float scale)
-{
- float f;
- const float *v;
- float *c;
- int i, l, lit = false;
- const dlight_t *light;
- vec3_t lightorigin;
- for (l = 0;l < r_numdlights;l++)
- {
- if (dlightbits[l >> 5] & (1 << (l & 31)))
- {
- light = &r_dlight[l];
- Matrix4x4_Transform(matrix, light->origin, lightorigin);
- for (i = 0, v = vert, c = color;i < numverts;i++, v += 3, c += 4)
- {
- f = VectorDistance2(v, lightorigin) + LIGHTOFFSET;
- if (f < light->rtlight.lightmap_cullradius2)
- {
- f = ((1.0f / f) - light->rtlight.lightmap_subtract) * scale;
- VectorMA(c, f, light->rtlight.lightmap_light, c);
- lit = true;
- }
- }
- }
- }
- return lit;
-}
-#endif
-
-static float *RSurf_GetVertexPointer(const entity_render_t *ent, const msurface_t *surface)
-{
- if (surface->texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
- {
- texture_t *texture = surface->texture;
- int i, j;
- float center[3], center2[3], forward[3], right[3], up[3], v[4][3];
- matrix4x4_t matrix1, imatrix1;
- R_Mesh_Matrix(&r_identitymatrix);
- // a single autosprite surface can contain multiple sprites...
- for (j = 0;j < surface->mesh.num_vertices - 3;j += 4)
- {
- VectorClear(center);
- for (i = 0;i < 4;i++)
- VectorAdd(center, surface->mesh.data_vertex3f + (j+i) * 3, center);
- VectorScale(center, 0.25f, center);
- Matrix4x4_Transform(&ent->matrix, center, center2);
- // FIXME: calculate vectors from triangle edges instead of using texture vectors as an easy way out?
- Matrix4x4_FromVectors(&matrix1, surface->mesh.data_normal3f + j*3, surface->mesh.data_svector3f + j*3, surface->mesh.data_tvector3f + j*3, center);
- Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
- for (i = 0;i < 4;i++)
- Matrix4x4_Transform(&imatrix1, surface->mesh.data_vertex3f + (j+i)*3, v[i]);
- if (texture->textureflags & Q3TEXTUREFLAG_AUTOSPRITE2)
- {
- forward[0] = r_vieworigin[0] - center2[0];
- forward[1] = r_vieworigin[1] - center2[1];
- forward[2] = 0;
- VectorNormalize(forward);
- right[0] = forward[1];
- right[1] = -forward[0];
- right[2] = 0;
- up[0] = 0;
- up[1] = 0;
- up[2] = 1;
- }
- else
- {
- VectorCopy(r_viewforward, forward);
- VectorCopy(r_viewright, right);
- VectorCopy(r_viewup, up);
- }
- for (i = 0;i < 4;i++)
- VectorMAMAMAM(1, center2, v[i][0], forward, v[i][1], right, v[i][2], up, varray_vertex3f + (i+j) * 3);
- }
- return varray_vertex3f;
- }
- else
- return surface->mesh.data_vertex3f;
-}
-
-void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
-{
- // we don't need to set currentframe if t->animated is false because
- // it was already set up by the texture loader for non-animating
- if (t->animated)
- {
- t->currentframe = t->anim_frames[ent->frame != 0][(t->anim_total[ent->frame != 0] >= 2) ? ((int)(r_refdef.time * 5.0f) % t->anim_total[ent->frame != 0]) : 0];
- t = t->currentframe;
- }
- t->currentmaterialflags = t->basematerialflags;
- t->currentalpha = ent->alpha;
- if (t->basematerialflags & MATERIALFLAG_WATERALPHA)
- t->currentalpha *= r_wateralpha.value;
- if (!(ent->flags & RENDER_LIGHT))
- t->currentmaterialflags |= MATERIALFLAG_FULLBRIGHT;
- if (ent->effects & EF_ADDITIVE)
- t->currentmaterialflags |= MATERIALFLAG_ADD | MATERIALFLAG_TRANSPARENT;
- else if (t->currentalpha < 1)
- t->currentmaterialflags |= MATERIALFLAG_ALPHA | MATERIALFLAG_TRANSPARENT;
-}
-
-matrix4x4_t r_surf_waterscrollmatrix;
-
-void R_UpdateAllTextureInfo(entity_render_t *ent)
-{
- int i;
- Matrix4x4_CreateTranslate(&r_surf_waterscrollmatrix, sin(r_refdef.time) * 0.025 * r_waterscroll.value, sin(r_refdef.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
- if (ent->model)
- for (i = 0;i < ent->model->brush.num_textures;i++)
- R_UpdateTextureInfo(ent, ent->model->brush.data_textures + i);
-}
-
-static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, int texturenumsurfaces, const msurface_t **texturesurfacelist, const vec3_t modelorg)
-{
- int i;
- int texturesurfaceindex;
- const float *v;
- float *c;
- float diff[3];
- float f, r, g, b, a, base, colorscale;
- const msurface_t *surface;
- qboolean dolightmap;
- qboolean dobase;
- qboolean doambient;
- qboolean dodetail;
- qboolean doglow;
- qboolean dofogpass;
- qboolean fogallpasses;
- qboolean waterscrolling;
- rmeshstate_t m;
- texture = texture->currentframe;
- if (texture->currentmaterialflags & MATERIALFLAG_NODRAW)
- return;
- c_faces += texturenumsurfaces;
- // gl_lightmaps debugging mode skips normal texturing
- if (gl_lightmaps.integer)
- {
- GL_BlendFunc(GL_ONE, GL_ZERO);
- GL_DepthMask(true);
- GL_DepthTest(true);
- qglDisable(GL_CULL_FACE);
- GL_Color(1, 1, 1, 1);
- memset(&m, 0, sizeof(m));
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.tex[0] = R_GetTexture(surface->lightmaptexture);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
- if (surface->lightmaptexture)
- {
- GL_Color(1, 1, 1, 1);
- m.pointer_color = NULL;
- }
- else
- m.pointer_color = surface->mesh.data_lightmapcolor4f;
- 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);
- }
- qglEnable(GL_CULL_FACE);
- return;
- }
- GL_DepthTest(!(texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
- GL_DepthMask(!(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT));
- if (texture->currentmaterialflags & MATERIALFLAG_ADD)
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
- else if (texture->currentmaterialflags & MATERIALFLAG_ALPHA)
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- else
- GL_BlendFunc(GL_ONE, GL_ZERO);
- // water waterscrolling in texture matrix
- waterscrolling = (texture->currentmaterialflags & MATERIALFLAG_WATER) && r_waterscroll.value != 0;
- if (texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
- qglDisable(GL_CULL_FACE);
- if (texture->currentmaterialflags & MATERIALFLAG_SKY)
- {
- 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);
- }
- }
- else if ((texture->currentmaterialflags & MATERIALFLAG_WATER) && r_watershader.value && gl_textureshader && !texture->skin.glow && !fogenabled && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
- {
- // NVIDIA Geforce3 distortion texture shader on water
- float args[4] = {0.05f,0,0,0.04f};
- memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(mod_shared_distorttexture[(int)(r_refdef.time * 16)&63]);
- m.tex[1] = R_GetTexture(texture->skin.base);
- m.texcombinergb[0] = GL_REPLACE;
- m.texcombinergb[1] = GL_REPLACE;
- Matrix4x4_CreateFromQuakeEntity(&m.texmatrix[0], 0, 0, 0, 0, 0, 0, r_watershader.value);
- m.texmatrix[1] = r_surf_waterscrollmatrix;
-
- GL_ActiveTexture(0);
- qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
- GL_ActiveTexture(1);
- qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
- qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);
- qglTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, &args[0]);
- qglEnable(GL_TEXTURE_SHADER_NV);
-
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- m.pointer_texcoord[1] = 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);
- }
-
- qglDisable(GL_TEXTURE_SHADER_NV);
- qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
- GL_ActiveTexture(0);
- }
- else if (texture->currentmaterialflags & (MATERIALFLAG_WATER | MATERIALFLAG_WALL))
- {
- // normal surface (wall or water)
- dobase = true;
- dolightmap = !(texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT);
- doambient = r_ambient.value >= (1/64.0f);
- dodetail = texture->skin.detail != NULL && !(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT);
- doglow = texture->skin.glow != NULL;
- dofogpass = fogenabled && !(texture->currentmaterialflags & MATERIALFLAG_ADD);
- fogallpasses = fogenabled && !(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT);
- if (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT)
- {
- if (dobase && dolightmap && gl_combine.integer)
- {
- 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;
- m.pointer_color = varray_color4f;
- colorscale = 1;
- r = ent->colormod[0] * colorscale;
- g = ent->colormod[1] * colorscale;
- b = ent->colormod[2] * colorscale;
- a = texture->currentalpha;
- base = r_ambient.value * (1.0f / 64.0f);
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
- m.pointer_texcoord[1] = surface->mesh.data_texcoordtexture2f;
- if (surface->lightmaptexture)
- {
- m.tex[0] = R_GetTexture(surface->lightmaptexture);
- if (fogallpasses)
- {
- m.pointer_color = varray_color4f;
- for (i = 0, v = m.pointer_vertex, 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] = f * r;
- c[1] = f * g;
- c[2] = f * b;
- c[3] = a;
- }
- }
- else
- {
- m.pointer_color = NULL;
- GL_Color(r, g, b, a);
- }
- }
- else
- {
- m.tex[0] = R_GetTexture(r_texture_white);
- m.pointer_color = varray_color4f;
-#ifdef LHREMOVESOON
- if (surface->styles[0] != 255 || surface->dlightframe == r_framecount)
-#else
- if (surface->styles[0] != 255)
-#endif
- {
- for (i = 0, v = m.pointer_vertex, 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);
- }
- }
- }
- }
- }
-#ifdef LHREMOVESOON
- if (surface->dlightframe == r_framecount)
- {
- int l;
- float worldvertex[3];
- // TODO: make this work with autosprite which uses identitymatrix
- Matrix4x4_Transform(&ent->matrix, v, worldvertex);
- for (l = 0;l < r_numdlights;l++)
- {
- if (surface->dlightbits[l >> 5] & (1 << (l & 31)))
- {
- float f2;
- dlight_t *light = &r_dlight[l];
- f2 = VectorDistance2(worldvertex, light->origin) + LIGHTOFFSET;
- if (f2 < light->rtlight.lightmap_cullradius2)
- {
- f2 = (1.0f / f2) - light->rtlight.lightmap_subtract;
- VectorMA(c, f2, light->rtlight.lightmap_light, c);
- }
- }
- }
- }
-#endif
- 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;
- }
- }
- else
- {
- if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
- {
- for (i = 0, v = m.pointer_vertex, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- c[0] = 0;
- c[1] = 0;
- c[2] = 0;
- c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
- }
- }
- else
- {
- m.pointer_color = NULL;
- GL_Color(0, 0, 0, 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);
- }
- }
- if (dobase)
- {
- dobase = false;
- memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(texture->skin.base);
- if (waterscrolling)
- m.texmatrix[0] = r_surf_waterscrollmatrix;
- m.texmatrix[0] = r_surf_waterscrollmatrix;
- m.pointer_color = varray_color4f;
- colorscale = 1;
- if (gl_combine.integer)
- {
- m.texrgbscale[0] = 4;
- colorscale *= 0.25f;
- }
- r = ent->colormod[0] * colorscale;
- g = ent->colormod[1] * colorscale;
- b = ent->colormod[2] * colorscale;
- a = texture->currentalpha;
- if (dolightmap)
- {
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- for (i = 0, v = m.pointer_vertex, 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);
- }
- }
- }
- }
- }
-#ifdef LHREMOVESOON
- if (surface->dlightframe == r_framecount)
- {
- // TODO: make this work with autosprite which uses identitymatrix
- Matrix4x4_Transform(&ent->matrix, v, worldvertex);
- for (l = 0;l < r_numdlights;l++)
- {
- if (surface->dlightbits[l >> 5] & (1 << (l & 31)))
- {
- float f2;
- dlight_t *light = &r_dlight[l];
- f2 = VectorDistance2(worldvertex, light->origin) + LIGHTOFFSET;
- if (f2 < light->rtlight.lightmap_cullradius2)
- {
- f2 = (1.0f / f2) - light->rtlight.lightmap_subtract;
- VectorMA(c, f2, light->rtlight.lightmap_light, c);
- }
- }
- }
- }
-#endif
- 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;
- }
- 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
- {
- if (fogallpasses)
- {
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- if (m.tex[1])
- m.pointer_texcoord[1] = surface->mesh.data_texcoordtexture2f;
- if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
- {
- m.pointer_color = varray_color4f;
- for (i = 0, v = m.pointer_vertex, 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
- {
- m.pointer_color = varray_color4f;
- for (i = 0, v = m.pointer_vertex, 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];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- if (m.tex[1])
- m.pointer_texcoord[1] = surface->mesh.data_texcoordtexture2f;
- if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
- {
- m.pointer_color = varray_color4f;
- for (i = 0, v = m.pointer_vertex, 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
- {
- m.pointer_color = 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);
- }
- }
- }
- }
- }
- else
- {
- if (!dolightmap && dobase)
- {
- dolightmap = false;
- dobase = false;
- 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);
- if (waterscrolling)
- m.texmatrix[0] = r_surf_waterscrollmatrix;
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- 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 (r_lightmapintensity <= 0 && dolightmap && dobase)
- {
- dolightmap = false;
- dobase = false;
- GL_Color(0, 0, 0, 1);
- memset(&m, 0, sizeof(m));
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- 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 (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 = ent->colormod[0] * r_lightmapintensity;
- g = ent->colormod[1] * r_lightmapintensity;
- b = ent->colormod[2] * r_lightmapintensity;
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- 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;
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
- m.pointer_texcoord[1] = surface->mesh.data_texcoordtexture2f;
- if (surface->lightmaptexture)
- {
- m.tex[0] = R_GetTexture(surface->lightmaptexture);
- m.pointer_color = NULL;
- GL_Color(r, g, b, 1);
- }
- else if (r == 1 && g == 1 && b == 1)
- {
- m.tex[0] = R_GetTexture(r_texture_white);
- m.pointer_color = surface->mesh.data_lightmapcolor4f;
- }
- else
- {
- m.tex[0] = R_GetTexture(r_texture_white);
- m.pointer_color = varray_color4f;
- for (i = 0;i < surface->mesh.num_vertices;i++)
- {
- varray_color4f[i*4+0] = surface->mesh.data_lightmapcolor4f[i*4+0] * r;
- varray_color4f[i*4+1] = surface->mesh.data_lightmapcolor4f[i*4+1] * g;
- varray_color4f[i*4+2] = surface->mesh.data_lightmapcolor4f[i*4+2] * b;
- varray_color4f[i*4+3] = surface->mesh.data_lightmapcolor4f[i*4+3];
- }
- }
- 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);
- }
- }
- // single texture
- if (dolightmap)
- {
- GL_BlendFunc(GL_ONE, GL_ZERO);
- GL_DepthMask(true);
- GL_Color(1, 1, 1, 1);
- memset(&m, 0, sizeof(m));
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.tex[0] = R_GetTexture(surface->lightmaptexture);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
- if (surface->lightmaptexture)
- m.pointer_color = NULL;
- else
- m.pointer_color = surface->mesh.data_lightmapcolor4f;
- 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 (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;
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- 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 (doambient)
- {
- doambient = false;
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
- GL_DepthMask(false);
- memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(texture->skin.base);
- if (waterscrolling)
- m.texmatrix[0] = r_surf_waterscrollmatrix;
- m.pointer_color = varray_color4f;
- colorscale = 1;
- if (gl_combine.integer)
- {
- m.texrgbscale[0] = 4;
- colorscale *= 0.25f;
- }
- base = r_ambient.value * (1.0f / 64.0f);
- r = ent->colormod[0] * colorscale * base;
- g = ent->colormod[1] * colorscale * base;
- b = ent->colormod[2] * colorscale * base;
- a = texture->currentalpha;
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- for (i = 0, v = m.pointer_vertex, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- 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;
- }
- 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);
- }
- }
- // marklights based vertex dlight rendering... evil and broken
-#if 0
- GL_BlendFunc(GL_ONE, GL_ONE);
- GL_DepthMask(false);
- memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(texture->skin.base);
- if (waterscrolling)
- m.texmatrix[0] = r_surf_waterscrollmatrix;
- m.pointer_color = varray_color4f;
- r = ent->colormod[0] * r_lightmapintensity;
- g = ent->colormod[1] * r_lightmapintensity;
- b = ent->colormod[2] * r_lightmapintensity;
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- qboolean lit;
- surface = texturesurfacelist[texturesurfaceindex];
- if (surface->dlightframe != r_framecount)
- continue;
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- lit = false;
- for (i = 0, v = m.pointer_vertex, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- c[0] = 0;
- c[1] = 0;
- c[2] = 0;
- c[3] = 1;
- // TODO: make this work with autosprite which uses identitymatrix or change autosprite
- Matrix4x4_Transform(&ent->matrix, v, worldvertex);
- for (l = 0;l < r_numdlights;l++)
- {
- if (surface->dlightbits[l >> 5] & (1 << (l & 31)))
- {
- float f2;
- dlight_t *light = &r_dlight[l];
- f2 = VectorDistance2(worldvertex, light->origin) + LIGHTOFFSET;
- if (f2 < light->rtlight.lightmap_cullradius2)
- {
- f2 = (1.0f / f2) - light->rtlight.lightmap_subtract;
- VectorMA(c, f2, light->rtlight.lightmap_light, c);
- lit = true;
- }
- }
- }
- 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;
- }
- if (!lit)
- continue;
- 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);
- }
-#endif
- if (dodetail)
- {
- GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
- GL_DepthMask(false);
- 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 = RSurf_GetVertexPointer(ent, surface);
- 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)
- {
- // if glow was not already done using multitexture, do it now.
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
- GL_DepthMask(false);
- memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(texture->skin.glow);
- if (waterscrolling)
- m.texmatrix[0] = r_surf_waterscrollmatrix;
- m.pointer_color = varray_color4f;
- colorscale = 1;
- r = ent->colormod[0] * colorscale;
- g = ent->colormod[1] * colorscale;
- b = ent->colormod[2] * colorscale;
- a = texture->currentalpha;
- if (fogallpasses)
- {
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
- {
- m.pointer_color = varray_color4f;
- for (i = 0, v = m.pointer_vertex, 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] = f * r;
- c[1] = f * g;
- c[2] = f * b;
- c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
- }
- }
- else
- {
- m.pointer_color = varray_color4f;
- for (i = 0, v = m.pointer_vertex, 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] = f * r;
- c[1] = f * g;
- c[2] = f * b;
- 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];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
- {
- m.pointer_color = varray_color4f;
- for (i = 0, v = m.pointer_vertex, 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
- {
- m.pointer_color = 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);
- }
- }
- }
- if (dofogpass)
- {
- // if this is opaque use alpha blend which will darken the earlier
- // passes cheaply.
- //
- // if this is an alpha blended material, all the earlier passes
- // were darkened by fog already, so we only need to add the fog
- // color ontop through the fog mask texture
- //
- // if this is an additive blended material, all the earlier passes
- // were darkened by fog already, and we should not add fog color
- // (because the background was not darkened, there is no fog color
- // that was lost behind it).
- if (!fogallpasses)
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
- else
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- GL_DepthMask(false);
- memset(&m, 0, sizeof(m));
- m.tex[0] = R_GetTexture(texture->skin.fog);
- if (waterscrolling)
- m.texmatrix[0] = r_surf_waterscrollmatrix;
- r = fogcolor[0];
- g = fogcolor[1];
- b = fogcolor[2];
- a = texture->currentalpha;
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- m.pointer_color = varray_color4f;
- //RSurf_FogPassColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], texture->currentalpha, 1, surface->mesh.num_vertices, modelorg);
- if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
- {
- m.pointer_color = varray_color4f;
- for (i = 0, v = m.pointer_vertex, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- VectorSubtract(v, modelorg, diff);
- f = exp(fogdensity/DotProduct(diff, diff));
- c[0] = r;
- c[1] = g;
- c[2] = b;
- c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * f * a;
- }
- }
- else
- {
- m.pointer_color = varray_color4f;
- for (i = 0, v = m.pointer_vertex, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- VectorSubtract(v, modelorg, diff);
- f = exp(fogdensity/DotProduct(diff, diff));
- c[0] = r;
- c[1] = g;
- c[2] = b;
- c[3] = f * 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);
- }
- }
- }
- if (texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
- qglEnable(GL_CULL_FACE);
-}
-
-static void RSurfShader_Transparent_Callback(const void *calldata1, int calldata2)
-{
- const entity_render_t *ent = calldata1;
- const msurface_t *surface = ent->model->brush.data_surfaces + calldata2;
- vec3_t modelorg;
- texture_t *texture;
-#ifdef LHREMOVESOON
- rmeshstate_t m;
- float base, colorscale;
- float args[4] = {0.05f,0,0,0.04f};
- matrix4x4_t scrollmatrix;
-#endif
-
- texture = surface->texture;
- if (texture->basematerialflags & MATERIALFLAG_SKY)
- return; // transparent sky is too difficult
- R_UpdateTextureInfo(ent, texture);
-
- R_Mesh_Matrix(&ent->matrix);
- Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
- R_DrawSurfaceList(ent, texture, 1, &surface, modelorg);
-#ifdef LHREMOVESOON
- GL_DepthTest(!(texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
- GL_DepthMask(!(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT));
- if (texture->currentmaterialflags & MATERIALFLAG_ADD)
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
- else if (texture->currentmaterialflags & MATERIALFLAG_ALPHA)
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- else
- GL_BlendFunc(GL_ONE, GL_ZERO);
-
- // water scrolling in texture matrix
- if ((texture->currentmaterialflags & MATERIALFLAG_WATER) && r_waterscroll.value != 0)
- Matrix4x4_CreateTranslate(&scrollmatrix, sin(r_refdef.time) * 0.025 * r_waterscroll.value, sin(r_refdef.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
- else
- scrollmatrix = r_identitymatrix;
-
- if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
- qglDisable(GL_CULL_FACE);
- if ((texture->currentmaterialflags & MATERIALFLAG_WATER) && r_watershader.value && gl_textureshader && !texture->skin.glow && !fogenabled && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
- {
- // NVIDIA Geforce3 distortion texture shader on water
- GL_Color(1, 1, 1, texture->currentalpha);
- memset(&m, 0, sizeof(m));
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.tex[0] = R_GetTexture(mod_shared_distorttexture[(int)(r_refdef.time * 16)&63]);
- m.tex[1] = R_GetTexture(texture->skin.base);
- m.texcombinergb[0] = GL_REPLACE;
- m.texcombinergb[1] = GL_REPLACE;
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- m.pointer_texcoord[1] = surface->mesh.data_texcoordtexture2f;
- Matrix4x4_CreateFromQuakeEntity(&m.texmatrix[0], 0, 0, 0, 0, 0, 0, r_watershader.value);
- m.texmatrix[1] = scrollmatrix;
- R_Mesh_State(&m);
-
- GL_ActiveTexture(0);
- qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
- GL_ActiveTexture(1);
- qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
- qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);
- qglTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, &args[0]);
- qglEnable(GL_TEXTURE_SHADER_NV);
-
- 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);
-
- qglDisable(GL_TEXTURE_SHADER_NV);
- qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
- GL_ActiveTexture(0);
- }
- else
- {
- int i;
- float r, g, b, a, f, *c, diff[3];
- const float *v;
- qboolean dolightmaptexture;
- qboolean dodetail;
- qboolean doglow;
- dolightmaptexture = surface->lightmaptexture && gl_combine.integer && !(texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT);
- dodetail = texture->skin.detail != NULL && !(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT);
- doglow = texture->skin.glow != NULL;
- // TODO: ideally transparent surface rendering should call
- // R_RenderLighting instead of using vertex dlights
- // (it would need scrolling support added though!)
- if (dolightmaptexture)
- {
- {
- memset(&m, 0, sizeof(m));
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- m.tex[0] = R_GetTexture(texture->skin.base);
- m.texmatrix[0] = scrollmatrix;
- m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
- m.tex[1] = R_GetTexture(surface->lightmaptexture);
- m.texrgbscale[1] = 2;
- m.pointer_color = varray_color4f;
- if (r_textureunits.integer >= 3 && dodetail)
- {
- dodetail = false;
- m.pointer_texcoord[2] = surface->mesh.data_texcoorddetail2f;
- m.tex[2] = R_GetTexture(texture->skin.detail);
- m.texmatrix[2] = scrollmatrix;
- if (r_textureunits.integer >= 4 && doglow)
- {
- doglow = false;
- m.pointer_texcoord[3] = surface->mesh.data_texcoordtexture2f;
- m.tex[3] = R_GetTexture(texture->skin.glow);
- m.texmatrix[3] = scrollmatrix;
- }
- }
- else if (r_textureunits.integer >= 3 && doglow && !dodetail)
- {
- doglow = false;
- m.pointer_texcoord[2] = surface->mesh.data_texcoordtexture2f;
- m.tex[2] = R_GetTexture(texture->skin.glow);
- m.texmatrix[2] = scrollmatrix;
- }
- colorscale = 1;
- r = ent->colormod[0] * colorscale;
- g = ent->colormod[1] * colorscale;
- b = ent->colormod[2] * colorscale;
- a = texture->currentalpha;
- for (i = 0, v = m.pointer_vertex, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- c[0] = r;
- c[1] = g;
- c[2] = b;
- if (fogenabled)
- {
- VectorSubtract(v, modelorg, diff);
- f = 1 - exp(fogdensity/DotProduct(diff, diff));
- VectorScale(c, f, c);
- }
- if (surface->mesh.data_lightmapcolor4f)
- c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
- else
- 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);
- }
- if ((r_ambient.value > 0 || surface->dlightframe == r_framecount) && !(texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT))
- {
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
- GL_DepthMask(false);
- memset(&m, 0, sizeof(m));
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- m.tex[0] = R_GetTexture(texture->skin.base);
- m.texmatrix[0] = scrollmatrix;
- m.pointer_color = varray_color4f;
- colorscale = 1;
- if (gl_combine.integer)
- {
- m.texrgbscale[0] = 4;
- colorscale *= 0.25f;
- }
- r = ent->colormod[0] * colorscale;
- g = ent->colormod[1] * colorscale;
- b = ent->colormod[2] * colorscale;
- a = texture->currentalpha;
- base = r_ambient.value * (1.0f / 64.0f);
- for (i = 0, v = m.pointer_vertex, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- c[0] = base;
- c[1] = base;
- c[2] = base;
- if (surface->dlightframe == r_framecount)
- {
- // TODO: make this work with autosprite which uses identitymatrix
- Matrix4x4_Transform(&ent->matrix, v, worldvertex);
- for (l = 0;l < r_numdlights;l++)
- {
- if (surface->dlightbits[l >> 5] & (1 << (l & 31)))
- {
- float f2;
- dlight_t *light = &r_dlight[l];
- f2 = VectorDistance2(worldvertex, light->origin) + LIGHTOFFSET;
- if (f2 < light->rtlight.lightmap_cullradius2)
- {
- f2 = (1.0f / f2) - light->rtlight.lightmap_subtract;
- VectorMA(c, f2, light->rtlight.lightmap_light, c);
- }
- }
- }
- }
- c[0] *= r;
- c[1] *= g;
- c[2] *= b;
- if (fogenabled)
- {
- VectorSubtract(v, modelorg, diff);
- f = 1 - exp(fogdensity/DotProduct(diff, diff));
- VectorScale(c, f, c);
- }
- if (surface->mesh.data_lightmapcolor4f)
- c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
- else
- 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
- {
- memset(&m, 0, sizeof(m));
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- m.tex[0] = R_GetTexture(texture->skin.base);
- m.texmatrix[0] = scrollmatrix;
- m.pointer_color = varray_color4f;
- colorscale = 1;
- if (gl_combine.integer)
- {
- m.texrgbscale[0] = 4;
- colorscale *= 0.25f;
- }
- if (doglow)
- {
- doglow = false;
- m.pointer_texcoord[1] = surface->mesh.data_texcoordtexture2f;
- m.tex[1] = R_GetTexture(texture->skin.glow);
- m.texmatrix[1] = scrollmatrix;
- }
- r = ent->colormod[0] * colorscale;
- g = ent->colormod[1] * colorscale;
- b = ent->colormod[2] * colorscale;
- a = texture->currentalpha;
- base = r_ambient.value * (1.0f / 64.0f);
- if ((ent->flags & RENDER_LIGHT) && !(texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT))
- {
- for (i = 0, v = m.pointer_vertex, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
- {
- c[0] = base;
- c[1] = base;
- c[2] = base;
- 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);
- }
- }
- }
- }
- }
- if (surface->dlightframe == r_framecount)
- {
- // TODO: make this work with autosprite which uses identitymatrix
- Matrix4x4_Transform(&ent->matrix, v, worldvertex);
- for (l = 0;l < r_numdlights;l++)
- {
- if (surface->dlightbits[l >> 5] & (1 << (l & 31)))
- {
- float f2;
- dlight_t *light = &r_dlight[l];
- f2 = VectorDistance2(worldvertex, light->origin) + LIGHTOFFSET;
- if (f2 < light->rtlight.lightmap_cullradius2)
- {
- f2 = (1.0f / f2) - light->rtlight.lightmap_subtract;
- VectorMA(c, f2, light->rtlight.lightmap_light, c);
- }
- }
- }
- }
- c[0] *= r;
- c[1] *= g;
- c[2] *= b;
- if (fogenabled)
- {
- VectorSubtract(v, modelorg, diff);
- f = 1 - exp(fogdensity/DotProduct(diff, diff));
- VectorScale(c, f, c);
- }
- if (surface->mesh.data_lightmapcolor4f)
- c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
- else
- c[3] = a;
- }
- }
- else
- {
- if (fogenabled)
- {
- if (surface->mesh.data_lightmapcolor4f)
- {
- for (i = 0, v = m.pointer_vertex, 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
- {
- for (i = 0, v = m.pointer_vertex, 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;
- }
- }
- }
- else
- {
- if (surface->mesh.data_lightmapcolor4f)
- {
- for (i = 0, v = m.pointer_vertex, 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
- {
- m.pointer_color = 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);
- }
- // note: dodetail is never set if transparent
- if (dodetail)
- {
- GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
- GL_DepthMask(false);
- memset(&m, 0, sizeof(m));
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoorddetail2f;
- m.tex[0] = R_GetTexture(texture->skin.detail);
- m.pointer_color = varray_color4f;
- RSurf_FoggedColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, ent->colormod[0], ent->colormod[1], ent->colormod[2], texture->currentalpha, 1, surface->mesh.num_vertices, modelorg);
- 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);
- memset(&m, 0, sizeof(m));
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- m.tex[0] = R_GetTexture(texture->skin.glow);
- m.texmatrix[0] = scrollmatrix;
- m.pointer_color = varray_color4f;
- RSurf_FoggedColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, ent->colormod[0], ent->colormod[1], ent->colormod[2], texture->currentalpha, 1, surface->mesh.num_vertices, modelorg);
- 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 (fogenabled && !(texture->currentmaterialflags & MATERIALFLAG_ADD))
- {
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
- GL_DepthMask(false);
- memset(&m, 0, sizeof(m));
- m.pointer_vertex = RSurf_GetVertexPointer(ent, surface);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
- m.tex[0] = R_GetTexture(texture->skin.fog);
- m.texmatrix[0] = scrollmatrix;
- m.pointer_color = varray_color4f;
- RSurf_FogPassColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], texture->currentalpha, 1, surface->mesh.num_vertices, modelorg);
- 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 (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
- qglEnable(GL_CULL_FACE);
-#endif
-}
-
-#ifdef LHREMOVESOON
-void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenumsurfaces, msurface_t **texturesurfacelist)
-{
- int texturesurfaceindex;
- vec3_t tempcenter, center, modelorg;
- msurface_t *surface;
- qboolean dolightmap;
- qboolean dobase;
- qboolean doambient;
- qboolean dodetail;
- qboolean doglow;
- qboolean dofog;
- rmeshstate_t m;
- Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
- c_faces += texturenumsurfaces;
- // gl_lightmaps debugging mode skips normal texturing
- if (gl_lightmaps.integer)
- {
- GL_BlendFunc(GL_ONE, GL_ZERO);
- GL_DepthMask(true);
- GL_DepthTest(true);
- qglDisable(GL_CULL_FACE);
- GL_Color(1, 1, 1, 1);
- memset(&m, 0, sizeof(m));
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- m.tex[0] = R_GetTexture(surface->lightmaptexture);
- m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
- if (surface->lightmaptexture)
- {
- GL_Color(1, 1, 1, 1);
- m.pointer_color = NULL;
- }
- else
- m.pointer_color = surface->mesh.data_lightmapcolor4f;
- 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);
- }
- qglEnable(GL_CULL_FACE);
- return;
- }
- if (texture->currentmaterialflags & MATERIALFLAG_WALL)
- {
- dolightmap = (ent->flags & RENDER_LIGHT);
- dobase = true;
- doambient = r_ambient.value > 0;
- dodetail = texture->skin.detail != NULL && r_detailtextures.integer != 0;
- doglow = texture->skin.glow != NULL;
- dofog = fogenabled;
- // multitexture cases
- if (r_textureunits.integer >= 2 && gl_combine.integer && dobase && dolightmap)
- {
- GL_BlendFunc(GL_ONE, GL_ZERO);
- GL_DepthMask(true);
- GL_DepthTest(true);
- GL_Color(1, 1, 1, 1);
- 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);
- dobase = false;
- m.texrgbscale[1] = 2;
- dolightmap = false;
- if (r_textureunits.integer >= 4 && !doambient && dodetail && doglow)
- {
- m.tex[2] = R_GetTexture(texture->skin.detail);
- m.texrgbscale[2] = 2;
- dodetail = false;
- m.tex[3] = R_GetTexture(texture->skin.glow);
- m.texcombinergb[3] = GL_ADD;
- doglow = false;
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- 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;
- m.pointer_texcoord[2] = surface->mesh.data_texcoorddetail2f;
- m.pointer_texcoord[3] = 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);
- }
- }
- else if (r_textureunits.integer >= 3 && !doambient && dodetail)
- {
- m.tex[2] = R_GetTexture(texture->skin.detail);
- m.texrgbscale[2] = 2;
- dodetail = false;
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- 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;
- m.pointer_texcoord[2] = 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);
- }
- }
- else if (r_textureunits.integer >= 3 && !doambient && !dodetail && doglow)
- {
- m.tex[2] = R_GetTexture(texture->skin.glow);
- m.texcombinergb[2] = GL_ADD;
- doglow = false;
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- 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;
- m.pointer_texcoord[2] = 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);
- }
- }
- else
- {
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- 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);
- }
- }
- return;
- }
- if (texture->currentmaterialflags & MATERIALFLAG_WATER)
- {
- for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
- {
- surface = texturesurfacelist[texturesurfaceindex];
- RSurfShader_Transparent_Callback(ent, surface - ent->model->brush.data_surfaces);
- }
- return;
- }
- if (texture->currentmaterialflags & MATERIALFLAG_SKY)
- {
- 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);
- }
- return;
- }
-}
-#endif
-
-void R_QueueSurfaceList(entity_render_t *ent, texture_t *texture, int texturenumsurfaces, const msurface_t **texturesurfacelist, const vec3_t modelorg)
-{
- int texturesurfaceindex;
- const msurface_t *surface;
- vec3_t tempcenter, center;
- if (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT)