#include "quakedef.h"
+#include "r_shadow.h"
-// LordHavoc: vertex array
-float *aliasvert;
-float *aliasvertnorm;
-byte *aliasvertcolor;
-byte *aliasvertcolor2;
-
-int chrometexture;
-
-void makechrometexture()
-{
- int i;
- byte noise[64*64];
- byte data[64*64][4];
-
- fractalnoise(noise, 64, 16);
-
- // convert to RGBA data
- for (i = 0;i < 64*64;i++)
- {
- data[i][0] = data[i][1] = data[i][2] = noise[i];
- data[i][3] = 255;
- }
-
- chrometexture = GL_LoadTexture ("chrometexture", 64, 64, &data[0][0], true, false, 4);
-}
-
-void gl_models_start()
-{
- // allocate vertex processing arrays
- aliasvert = qmalloc(sizeof(float[MD2MAX_VERTS][3]));
- aliasvertnorm = qmalloc(sizeof(float[MD2MAX_VERTS][3]));
- aliasvertcolor = qmalloc(sizeof(byte[MD2MAX_VERTS][4]));
- aliasvertcolor2 = qmalloc(sizeof(byte[MD2MAX_VERTS][4])); // used temporarily for tinted coloring
- makechrometexture();
-}
-
-void gl_models_shutdown()
+void GL_Models_Init(void)
{
- qfree(aliasvert);
- qfree(aliasvertnorm);
- qfree(aliasvertcolor);
- qfree(aliasvertcolor2);
}
-void GL_Models_Init()
+aliaslayer_t r_aliasnoskinlayers[2] = {{ALIASLAYER_DIFFUSE, NULL, NULL}, {ALIASLAYER_FOG | ALIASLAYER_FORCEDRAW_IF_FIRSTPASS, NULL, NULL}};
+aliasskin_t r_aliasnoskin = {0, 2, r_aliasnoskinlayers};
+aliasskin_t *R_FetchAliasSkin(const entity_render_t *ent, const aliasmesh_t *mesh)
{
- R_RegisterModule("GL_Models", gl_models_start, gl_models_shutdown);
-}
-
-extern vec3_t softwaretransform_x;
-extern vec3_t softwaretransform_y;
-extern vec3_t softwaretransform_z;
-extern vec_t softwaretransform_scale;
-extern vec3_t softwaretransform_offset;
-void R_AliasLerpVerts(int vertcount, float lerp, trivert2 *verts1, vec3_t scale1, vec3_t translate1, trivert2 *verts2, vec3_t scale2, vec3_t translate2)
-{
- int i;
- vec3_t point, matrix_x, matrix_y, matrix_z;
- float *av, *avn;
- av = aliasvert;
- avn = aliasvertnorm;
- VectorScale(softwaretransform_x, softwaretransform_scale, matrix_x);
- VectorScale(softwaretransform_y, softwaretransform_scale, matrix_y);
- VectorScale(softwaretransform_z, softwaretransform_scale, matrix_z);
- if (lerp < 0) lerp = 0;
- if (lerp > 1) lerp = 1;
- if (lerp != 0)
- {
- float ilerp, ilerp127, lerp127, scalex1, scalex2, translatex, scaley1, scaley2, translatey, scalez1, scalez2, translatez;
- ilerp = 1 - lerp;
- ilerp127 = ilerp * (1.0 / 127.0);
- lerp127 = lerp * (1.0 / 127.0);
- // calculate combined interpolation variables
- scalex1 = scale1[0] * ilerp;scalex2 = scale2[0] * lerp;translatex = translate1[0] * ilerp + translate2[0] * lerp;
- scaley1 = scale1[1] * ilerp;scaley2 = scale2[1] * lerp;translatey = translate1[1] * ilerp + translate2[1] * lerp;
- scalez1 = scale1[2] * ilerp;scalez2 = scale2[2] * lerp;translatez = translate1[2] * ilerp + translate2[2] * lerp;
- // generate vertices
- for (i = 0;i < vertcount;i++)
- {
- // rotate, scale, and translate the vertex locations
- point[0] = verts1->v[0] * scalex1 + verts2->v[0] * scalex2 + translatex;
- point[1] = verts1->v[1] * scaley1 + verts2->v[1] * scaley2 + translatey;
- point[2] = verts1->v[2] * scalez1 + verts2->v[2] * scalez2 + translatez;
- *av++ = point[0] * matrix_x[0] + point[1] * matrix_y[0] + point[2] * matrix_z[0] + softwaretransform_offset[0];
- *av++ = point[0] * matrix_x[1] + point[1] * matrix_y[1] + point[2] * matrix_z[1] + softwaretransform_offset[1];
- *av++ = point[0] * matrix_x[2] + point[1] * matrix_y[2] + point[2] * matrix_z[2] + softwaretransform_offset[2];
- // rotate the normals
- point[0] = verts1->n[0] * ilerp127 + verts2->n[0] * lerp127;
- point[1] = verts1->n[1] * ilerp127 + verts2->n[1] * lerp127;
- point[2] = verts1->n[2] * ilerp127 + verts2->n[2] * lerp127;
- *avn++ = point[0] * softwaretransform_x[0] + point[1] * softwaretransform_y[0] + point[2] * softwaretransform_z[0];
- *avn++ = point[0] * softwaretransform_x[1] + point[1] * softwaretransform_y[1] + point[2] * softwaretransform_z[1];
- *avn++ = point[0] * softwaretransform_x[2] + point[1] * softwaretransform_y[2] + point[2] * softwaretransform_z[2];
- verts1++;verts2++;
- }
- }
- else
+ model_t *model = ent->model;
+ if (model->numskins)
{
- // generate vertices
- for (i = 0;i < vertcount;i++)
- {
- // rotate, scale, and translate the vertex locations
- point[0] = verts1->v[0] * scale1[0] + translate1[0];
- point[1] = verts1->v[1] * scale1[1] + translate1[1];
- point[2] = verts1->v[2] * scale1[2] + translate1[2];
- *av++ = point[0] * matrix_x[0] + point[1] * matrix_y[0] + point[2] * matrix_z[0] + softwaretransform_offset[0];
- *av++ = point[0] * matrix_x[1] + point[1] * matrix_y[1] + point[2] * matrix_z[1] + softwaretransform_offset[1];
- *av++ = point[0] * matrix_x[2] + point[1] * matrix_y[2] + point[2] * matrix_z[2] + softwaretransform_offset[2];
- // rotate the normals
- point[0] = verts1->n[0] * (1.0f / 127.0f);
- point[1] = verts1->n[1] * (1.0f / 127.0f);
- point[2] = verts1->n[2] * (1.0f / 127.0f);
- *avn++ = point[0] * softwaretransform_x[0] + point[1] * softwaretransform_y[0] + point[2] * softwaretransform_z[0];
- *avn++ = point[0] * softwaretransform_x[1] + point[1] * softwaretransform_y[1] + point[2] * softwaretransform_z[1];
- *avn++ = point[0] * softwaretransform_x[2] + point[1] * softwaretransform_y[2] + point[2] * softwaretransform_z[2];
- verts1++;
- }
- }
-}
-
-float R_CalcAnimLerp(entity_t *ent, int pose, float lerpscale)
-{
- if (ent->draw_lastmodel == ent->model && ent->draw_lerpstart <= cl.time)
- {
- if (pose != ent->draw_pose)
- {
- ent->draw_lastpose = ent->draw_pose;
- ent->draw_pose = pose;
- ent->draw_lerpstart = cl.time;
- return 0;
- }
- else
- return ((cl.time - ent->draw_lerpstart) * lerpscale);
- }
- else // uninitialized
- {
- ent->draw_lastmodel = ent->model;
- ent->draw_lastpose = ent->draw_pose = pose;
- ent->draw_lerpstart = cl.time;
- return 0;
- }
-}
-
-void GL_DrawModelMesh(int skin, byte *colors, maliashdr_t *maliashdr)
-{
- int i;
- if (!r_render.value)
- return;
- glBindTexture(GL_TEXTURE_2D, skin);
- if (!colors)
- {
- if (lighthalf)
- glColor3f(0.5f, 0.5f, 0.5f);
+ int s = ent->skinnum;
+ if ((unsigned int)s >= (unsigned int)model->numskins)
+ s = 0;
+ if (model->skinscenes[s].framecount > 1)
+ s = model->skinscenes[s].firstframe + (int) (cl.time * model->skinscenes[s].framerate) % model->skinscenes[s].framecount;
else
- glColor3f(1.0f, 1.0f, 1.0f);
- }
- if (gl_vertexarrays.value)
- {
- if (colors)
- {
- qglColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
- glEnableClientState(GL_COLOR_ARRAY);
- }
-
- qglTexCoordPointer(2, GL_FLOAT, 0, (void *)((int) maliashdr->texdata + (int) maliashdr));
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- qglDrawElements(GL_TRIANGLES, maliashdr->numtris * 3, GL_UNSIGNED_SHORT, (void *)((int) maliashdr + maliashdr->tridata));
-
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
- if (colors)
- glDisableClientState(GL_COLOR_ARRAY);
+ s = model->skinscenes[s].firstframe;
+ if (s >= mesh->num_skins)
+ s = 0;
+ return mesh->data_skins + s;
}
else
{
- unsigned short *in, index;
- float *tex;
- in = (void *)((int) maliashdr + maliashdr->tridata);
- glBegin(GL_TRIANGLES);
- tex = (void *)((int) maliashdr + maliashdr->texdata);
- for (i = 0;i < maliashdr->numtris * 3;i++)
- {
- index = *in++;
- glTexCoord2f(tex[index*2], tex[index*2+1]);
- if (colors)
- glColor4f(colors[index*4] * (1.0f / 255.0f), colors[index*4+1] * (1.0f / 255.0f), colors[index*4+2] * (1.0f / 255.0f), colors[index*4+3] * (1.0f / 255.0f));
- glVertex3fv(&aliasvert[index*3]);
- }
- glEnd();
- }
- // leave it in a state for additional passes
- glDepthMask(0);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE); // additive
-}
-
-void R_TintModel(byte *in, byte *out, int verts, byte *color)
-{
- int i;
- byte r = color[0];
- byte g = color[1];
- byte b = color[2];
- for (i = 0;i < verts;i++)
- {
- out[0] = (byte) ((in[0] * r) >> 8);
- out[1] = (byte) ((in[1] * g) >> 8);
- out[2] = (byte) ((in[2] * b) >> 8);
- out[3] = in[3];
- in += 4;
- out += 4;
+ r_aliasnoskinlayers[0].texture = r_notexture;
+ return &r_aliasnoskin;
}
}
-/*
-=================
-R_DrawAliasFrame
-
-=================
-*/
-extern vec3_t lightspot;
-void R_LightModel(int numverts, vec3_t center, vec3_t basecolor);
-void R_DrawAliasFrame (maliashdr_t *maliashdr, float alpha, vec3_t color, entity_t *ent, int shadow, vec3_t org, int frame, int *skin, int colormap, int effects, int flags)
+void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
{
- int i, pose;
- float lerpscale, lerp;
- maliasframe_t *frameinfo;
-
- softwaretransformforentity(ent);
-
- if ((frame >= maliashdr->numframes) || (frame < 0))
- {
- Con_DPrintf ("R_AliasSetupFrame: no such frame %d\n", frame);
- frame = 0;
- }
-
- frameinfo = ((maliasframe_t *)((int) maliashdr + maliashdr->framedata)) + frame;
- pose = frameinfo->start;
-
- if (frameinfo->length > 1)
- {
- lerpscale = frameinfo->rate;
- pose += (int)(cl.time * frameinfo->rate) % frameinfo->length;
- }
- else
- lerpscale = 10.0f;
-
- lerp = R_CalcAnimLerp(ent, pose, lerpscale);
-
- R_AliasLerpVerts(maliashdr->numverts, lerp, (trivert2 *)((int) maliashdr + maliashdr->posedata) + ent->draw_lastpose * maliashdr->numverts, maliashdr->scale, maliashdr->scale_origin, (trivert2 *)((int) maliashdr + maliashdr->posedata) + ent->draw_pose * maliashdr->numverts, maliashdr->scale, maliashdr->scale_origin);
-
- // prep the vertex array as early as possible
- if (r_render.value)
+ int c, fullbright, layernum, firstpass;
+ float tint[3], fog, ifog, colorscale, ambientcolor4f[4], diffusecolor[3], diffusenormal[3];
+ float *vertex3f, *normal3f;
+ vec3_t diff;
+ qbyte *bcolor;
+ rmeshstate_t m;
+ const entity_render_t *ent = calldata1;
+ aliasmesh_t *mesh = ent->model->alias.aliasdata_meshes + calldata2;
+ aliaslayer_t *layer;
+ aliasskin_t *skin;
+
+ R_Mesh_Matrix(&ent->matrix);
+
+ fog = 0;
+ if (fogenabled)
{
- if (gl_vertexarrays.value)
- {
- qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
- glEnableClientState(GL_VERTEX_ARRAY);
- }
+ VectorSubtract(ent->origin, r_vieworigin, diff);
+ fog = DotProduct(diff,diff);
+ if (fog < 0.01f)
+ fog = 0.01f;
+ fog = exp(fogdensity/fog);
+ if (fog > 1)
+ fog = 1;
+ if (fog < 0.01f)
+ fog = 0;
+ // fog method: darken, additive fog
+ // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
+ // 2. render fog as additive
}
+ ifog = 1 - fog;
- R_LightModel(maliashdr->numverts, org, color);
+ firstpass = true;
+ skin = R_FetchAliasSkin(ent, mesh);
- if (!r_render.value)
- return;
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glShadeModel(GL_SMOOTH);
- if (effects & EF_ADDITIVE)
+ if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
{
- glBlendFunc(GL_SRC_ALPHA, GL_ONE); // additive rendering
- glEnable(GL_BLEND);
- glDepthMask(0);
- }
- else if (alpha != 1.0)
- {
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- glDepthMask(0);
+ vertex3f = mesh->data_basevertex3f;
+ normal3f = mesh->data_basenormal3f;
}
else
{
- glDisable(GL_BLEND);
- glDepthMask(1);
+ vertex3f = varray_vertex3f;
+ Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
+ normal3f = NULL;
}
-
- if (colormap >= 0)
+ for (layernum = 0, layer = skin->data_layers;layernum < skin->num_layers;layernum++, layer++)
{
- if (!skin[0] && !skin[1] && !skin[2] && !skin[3])
- GL_DrawModelMesh(0, NULL, maliashdr);
- else
+ if (!(layer->flags & ALIASLAYER_FORCEDRAW_IF_FIRSTPASS) || !firstpass)
{
- int c;
- if (skin[0])
- GL_DrawModelMesh(skin[0], aliasvertcolor, maliashdr);
- if (skin[1])
- {
- c = (colormap & 0xF) << 4;c += (c >= 128 && c < 224) ? 4 : 12; // 128-224 are backwards ranges
- R_TintModel(aliasvertcolor, aliasvertcolor2, maliashdr->numverts, (byte *) (&d_8to24table[c]));
- GL_DrawModelMesh(skin[1], aliasvertcolor2, maliashdr);
- }
- if (skin[2])
- {
- c = colormap & 0xF0 ;c += (c >= 128 && c < 224) ? 4 : 12; // 128-224 are backwards ranges
- R_TintModel(aliasvertcolor, aliasvertcolor2, maliashdr->numverts, (byte *) (&d_8to24table[c]));
- GL_DrawModelMesh(skin[2], aliasvertcolor2, maliashdr);
- }
- if (skin[3]) GL_DrawModelMesh(skin[3], NULL, maliashdr);
+ if (((layer->flags & ALIASLAYER_NODRAW_IF_NOTCOLORMAPPED) && ent->colormap < 0)
+ || ((layer->flags & ALIASLAYER_NODRAW_IF_COLORMAPPED) && ent->colormap >= 0)
+ || ((layer->flags & ALIASLAYER_FOG) && !fogenabled)
+ || (layer->flags & ALIASLAYER_SPECULAR)
+ || ((layer->flags & ALIASLAYER_DIFFUSE) && (ent->flags & RENDER_LIGHT) && r_lightmapintensity <= 0 && !(ent->flags & RENDER_TRANSPARENT) && r_ambient.integer <= 0))
+ continue;
}
- }
- else
- {
- if (!skin[3] && !skin[4])
- GL_DrawModelMesh(0, NULL, maliashdr);
- else
+ if (!firstpass || (ent->effects & EF_ADDITIVE))
{
- if (skin[4]) GL_DrawModelMesh(skin[4], aliasvertcolor, maliashdr);
- if (skin[3]) GL_DrawModelMesh(skin[3], NULL, maliashdr);
+ GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
+ GL_DepthMask(false);
}
- }
-
- if (fogenabled)
- {
- vec3_t diff;
- glDisable (GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable (GL_BLEND);
- glDepthMask(0); // disable zbuffer updates
-
- VectorSubtract(org, r_refdef.vieworg, diff);
- glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], exp(fogdensity/DotProduct(diff,diff)));
-
- if (gl_vertexarrays.value)
+ else if ((skin->flags & ALIASSKIN_TRANSPARENT) || ent->alpha != 1.0)
{
- qglDrawElements(GL_TRIANGLES, maliashdr->numtris * 3, GL_UNSIGNED_SHORT, (void *)((int) maliashdr + maliashdr->tridata));
+ GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ GL_DepthMask(false);
}
else
{
- unsigned short *in;
- in = (void *)((int) maliashdr + maliashdr->tridata);
- glBegin(GL_TRIANGLES);
- for (i = 0;i < maliashdr->numtris * 3;i++)
- glVertex3fv(&aliasvert[*in++ * 3]);
- glEnd();
+ GL_BlendFunc(GL_ONE, GL_ZERO);
+ GL_DepthMask(true);
}
+ GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
+ firstpass = false;
+ colorscale = 1.0f;
- glEnable (GL_TEXTURE_2D);
- glColor3f (1,1,1);
- }
- if (gl_vertexarrays.value)
- glDisableClientState(GL_VERTEX_ARRAY);
-
- if (!fogenabled && r_shadows.value && !(effects & EF_ADDITIVE) && shadow)
- {
- // flatten it to make a shadow
- float *av = aliasvert + 2, l = lightspot[2] + 0.125;
- av = aliasvert + 2;
- for (i = 0;i < maliashdr->numverts;i++, av+=3)
- if (*av > l)
- *av = l;
- glDisable (GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable (GL_BLEND);
- glDepthMask(0); // disable zbuffer updates
- glColor4f (0,0,0,0.5 * alpha);
+ memset(&m, 0, sizeof(m));
+ if (layer->texture != NULL)
+ {
+ m.tex[0] = R_GetTexture(layer->texture);
+ m.pointer_texcoord[0] = mesh->data_texcoord2f;
+ if (gl_combine.integer && layer->flags & (ALIASLAYER_DIFFUSE | ALIASLAYER_SPECULAR))
+ {
+ colorscale *= 0.25f;
+ m.texrgbscale[0] = 4;
+ }
+ }
+ m.pointer_vertex = vertex3f;
- if (gl_vertexarrays.value)
+ c_alias_polys += mesh->num_triangles;
+ if (layer->flags & ALIASLAYER_FOG)
{
- qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
- glEnableClientState(GL_VERTEX_ARRAY);
- qglDrawElements(GL_TRIANGLES, maliashdr->numtris * 3, GL_UNSIGNED_SHORT, (void *)((int) maliashdr + maliashdr->tridata));
- glDisableClientState(GL_VERTEX_ARRAY);
+ colorscale *= fog;
+ GL_Color(fogcolor[0] * colorscale, fogcolor[1] * colorscale, fogcolor[2] * colorscale, ent->alpha);
}
else
{
- unsigned short *in;
- in = (void *)((int) maliashdr + maliashdr->tridata);
- glBegin(GL_TRIANGLES);
- for (i = 0;i < maliashdr->numtris * 3;i++)
- glVertex3fv(&aliasvert[*in++ * 3]);
- glEnd();
+ fullbright = !(layer->flags & ALIASLAYER_DIFFUSE) || !(ent->flags & RENDER_LIGHT);
+ if (layer->flags & (ALIASLAYER_COLORMAP_PANTS | ALIASLAYER_COLORMAP_SHIRT))
+ {
+ // 128-224 are backwards ranges
+ if (layer->flags & ALIASLAYER_COLORMAP_PANTS)
+ c = (ent->colormap & 0xF) << 4;
+ else //if (layer->flags & ALIASLAYER_COLORMAP_SHIRT)
+ c = (ent->colormap & 0xF0);
+ c += (c >= 128 && c < 224) ? 4 : 12;
+ bcolor = (qbyte *) (&palette_complete[c]);
+ fullbright = fullbright || c >= 224;
+ VectorScale(bcolor, (1.0f / 255.0f), tint);
+ }
+ else
+ tint[0] = tint[1] = tint[2] = 1;
+ tint[0] *= ent->colormod[0];
+ tint[1] *= ent->colormod[1];
+ tint[2] *= ent->colormod[2];
+ if (!fullbright && !(ent->flags & RENDER_TRANSPARENT))
+ colorscale *= r_lightmapintensity;
+ colorscale *= ifog;
+ if (fullbright)
+ GL_Color(tint[0] * colorscale, tint[1] * colorscale, tint[2] * colorscale, ent->alpha);
+ else if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0] * colorscale, tint[1] * colorscale, tint[2] * colorscale, ent->alpha, false))
+ {
+ m.pointer_color = varray_color4f;
+ if (normal3f == NULL)
+ {
+ normal3f = varray_normal3f;
+ Mod_BuildNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
+ }
+ R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f);
+ }
+ else
+ GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]);
}
-
- glEnable (GL_TEXTURE_2D);
- glColor3f (1,1,1);
+ R_Mesh_State(&m);
+ GL_LockArrays(0, mesh->num_vertices);
+ R_Mesh_Draw(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
+ GL_LockArrays(0, 0);
}
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable (GL_BLEND);
- glDepthMask(1);
}
-/*
-=================
-R_DrawQ2AliasFrame
-
-=================
-*/
-void R_DrawQ2AliasFrame (md2mem_t *pheader, float alpha, vec3_t color, entity_t *ent, int shadow, vec3_t org, int frame, int skin, int effects, int flags)
+void R_Model_Alias_Draw(entity_render_t *ent)
{
- int *order, count;
- float lerp;
- md2memframe_t *frame1, *frame2;
-
- if (r_render.value)
- glBindTexture(GL_TEXTURE_2D, skin);
+ int meshnum;
+ aliasmesh_t *mesh;
+ if (ent->alpha < (1.0f / 64.0f))
+ return; // basically completely transparent
- softwaretransformforentity(ent);
+ c_models++;
- if ((frame >= pheader->num_frames) || (frame < 0))
+ for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++)
{
- Con_DPrintf ("R_SetupQ2AliasFrame: no such frame %d\n", frame);
- frame = 0;
+ if (ent->effects & EF_ADDITIVE || ent->alpha != 1.0 || R_FetchAliasSkin(ent, mesh)->flags & ALIASSKIN_TRANSPARENT)
+ R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : ent->origin, R_DrawAliasModelCallback, ent, meshnum);
+ else
+ R_DrawAliasModelCallback(ent, meshnum);
}
+}
- lerp = R_CalcAnimLerp(ent, frame, 10);
-
- frame1 = (void *)((int) pheader + pheader->ofs_frames + (pheader->framesize * ent->draw_lastpose));
- frame2 = (void *)((int) pheader + pheader->ofs_frames + (pheader->framesize * ent->draw_pose));
- R_AliasLerpVerts(pheader->num_xyz, lerp, frame1->verts, frame1->scale, frame1->translate, frame2->verts, frame2->scale, frame2->translate);
-
- R_LightModel(pheader->num_xyz, org, color);
-
- if (!r_render.value)
+void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius)
+{
+ int meshnum;
+ vec3_t lightmins, lightmaxs;
+ aliasmesh_t *mesh;
+ aliasskin_t *skin;
+ float projectdistance, *vertex3f;
+ if (!(ent->flags & RENDER_SHADOW))
return;
- if (gl_vertexarrays.value)
- {
- // LordHavoc: big mess...
- // using arrays only slightly, although it is enough to prevent duplicates
- // (saving half the transforms)
- qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
- qglColorPointer(4, GL_UNSIGNED_BYTE, 0, aliasvertcolor);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
-
- order = (int *)((int)pheader + pheader->ofs_glcmds);
- while(1)
- {
- if (!(count = *order++))
- break;
- if (count > 0)
- glBegin(GL_TRIANGLE_STRIP);
- else
- {
- glBegin(GL_TRIANGLE_FAN);
- count = -count;
- }
- do
- {
- glTexCoord2f(((float *)order)[0], ((float *)order)[1]);
- qglArrayElement(order[2]);
- order += 3;
- }
- while (count--);
- }
-
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
- }
- else
+ lightmins[0] = relativelightorigin[0] - lightradius;
+ lightmins[1] = relativelightorigin[1] - lightradius;
+ lightmins[2] = relativelightorigin[2] - lightradius;
+ lightmaxs[0] = relativelightorigin[0] + lightradius;
+ lightmaxs[1] = relativelightorigin[1] + lightradius;
+ lightmaxs[2] = relativelightorigin[2] + lightradius;
+ // check the box in modelspace, it was already checked in worldspace
+ if (!BoxesOverlap(ent->model->normalmins, ent->model->normalmaxs, lightmins, lightmaxs))
+ return;
+ projectdistance = lightradius + ent->model->radius;// - sqrt(DotProduct(relativelightorigin, relativelightorigin));
+ if (projectdistance > 0.1)
{
- order = (int *)((int)pheader + pheader->ofs_glcmds);
- while(1)
+ R_Mesh_Matrix(&ent->matrix);
+ for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++)
{
- if (!(count = *order++))
- break;
- if (count > 0)
- glBegin(GL_TRIANGLE_STRIP);
+ skin = R_FetchAliasSkin(ent, mesh);
+ if (skin->flags & ALIASSKIN_TRANSPARENT)
+ continue;
+ if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
+ vertex3f = mesh->data_basevertex3f;
else
{
- glBegin(GL_TRIANGLE_FAN);
- count = -count;
+ vertex3f = varray_vertex3f;
+ Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
}
- do
- {
- glTexCoord2f(((float *)order)[0], ((float *)order)[1]);
- glColor4f(aliasvertcolor[order[2] * 4] * (1.0f / 255.0f), aliasvertcolor[order[2] * 4 + 1] * (1.0f / 255.0f), aliasvertcolor[order[2] * 4 + 2] * (1.0f / 255.0f), aliasvertcolor[order[2] * 4 + 3] * (1.0f / 255.0f));
- glVertex3fv(&aliasvert[order[2] * 3]);
- order += 3;
- }
- while (count--);
+ // identify lit faces within the bounding box
+ R_Shadow_PrepareShadowMark(mesh->num_triangles);
+ R_Shadow_MarkVolumeFromBox(0, mesh->num_triangles, vertex3f, mesh->data_element3i, relativelightorigin, lightmins, lightmaxs, ent->model->normalmins, ent->model->normalmaxs);
+ R_Shadow_VolumeFromList(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, mesh->data_neighbor3i, relativelightorigin, projectdistance, numshadowmark, shadowmarklist);
}
}
+}
+void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist)
+{
+ int c, meshnum, layernum;
+ float fog, ifog, lightcolor2[3];
+ float *vertex3f, *svector3f, *tvector3f, *normal3f;
+ vec3_t diff;
+ qbyte *bcolor;
+ aliasmesh_t *mesh;
+ aliaslayer_t *layer;
+ aliasskin_t *skin;
+
+ R_Mesh_Matrix(&ent->matrix);
+
+ fog = 0;
if (fogenabled)
{
- glDisable (GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable (GL_BLEND);
- glDepthMask(0); // disable zbuffer updates
- {
- vec3_t diff;
- VectorSubtract(org, r_refdef.vieworg, diff);
- glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], exp(fogdensity/DotProduct(diff,diff)));
- }
+ VectorSubtract(ent->origin, r_vieworigin, diff);
+ fog = DotProduct(diff,diff);
+ if (fog < 0.01f)
+ fog = 0.01f;
+ fog = exp(fogdensity/fog);
+ if (fog > 1)
+ fog = 1;
+ if (fog < 0.01f)
+ fog = 0;
+ // fog method: darken, additive fog
+ // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
+ // 2. render fog as additive
+ }
+ ifog = 1 - fog;
- if (gl_vertexarrays.value)
+ for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++)
+ {
+ skin = R_FetchAliasSkin(ent, mesh);
+ // FIXME: transparent skins need to be lit during the transparent render
+ if (skin->flags & ALIASSKIN_TRANSPARENT)
+ continue;
+ if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
{
- // LordHavoc: big mess...
- // using arrays only slightly, although it is enough to prevent duplicates
- // (saving half the transforms)
- qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
- glEnableClientState(GL_VERTEX_ARRAY);
-
- order = (int *)((int)pheader + pheader->ofs_glcmds);
- while(1)
- {
- if (!(count = *order++))
- break;
- if (count > 0)
- glBegin(GL_TRIANGLE_STRIP);
- else
- {
- glBegin(GL_TRIANGLE_FAN);
- count = -count;
- }
- do
- {
- qglArrayElement(order[2]);
- order += 3;
- }
- while (count--);
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
+ vertex3f = mesh->data_basevertex3f;
+ svector3f = mesh->data_basesvector3f;
+ tvector3f = mesh->data_basetvector3f;
+ normal3f = mesh->data_basenormal3f;
}
else
{
- order = (int *)((int)pheader + pheader->ofs_glcmds);
- while(1)
- {
- if (!(count = *order++))
- break;
- if (count > 0)
- glBegin(GL_TRIANGLE_STRIP);
- else
- {
- glBegin(GL_TRIANGLE_FAN);
- count = -count;
- }
- do
- {
- glVertex3fv(&aliasvert[order[2] * 3]);
- order += 3;
- }
- while (count--);
- }
+ vertex3f = varray_vertex3f;
+ svector3f = varray_svector3f;
+ tvector3f = varray_tvector3f;
+ normal3f = varray_normal3f;
+ Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
+ Mod_BuildTextureVectorsAndNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_texcoord2f, mesh->data_element3i, svector3f, tvector3f, normal3f);
}
-
- glEnable (GL_TEXTURE_2D);
- glColor3f (1,1,1);
- }
-
- if (!fogenabled && r_shadows.value && !(effects & EF_ADDITIVE) && shadow)
- {
- int i;
- float *av = aliasvert + 2, l = lightspot[2] + 0.125;
- av = aliasvert + 2;
- for (i = 0;i < pheader->num_xyz;i++, av+=3)
- if (*av > l)
- *av = l;
- glDisable (GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable (GL_BLEND);
- glDepthMask(0); // disable zbuffer updates
- glColor4f (0,0,0,0.5 * alpha);
-
- if (gl_vertexarrays.value)
+ for (layernum = 0, layer = skin->data_layers;layernum < skin->num_layers;layernum++, layer++)
{
- qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
- glEnableClientState(GL_VERTEX_ARRAY);
-
- while(1)
+ if (!(layer->flags & (ALIASLAYER_DIFFUSE | ALIASLAYER_SPECULAR))
+ || ((layer->flags & ALIASLAYER_NODRAW_IF_NOTCOLORMAPPED) && ent->colormap < 0)
+ || ((layer->flags & ALIASLAYER_NODRAW_IF_COLORMAPPED) && ent->colormap >= 0))
+ continue;
+ lightcolor2[0] = lightcolor[0] * ifog;
+ lightcolor2[1] = lightcolor[1] * ifog;
+ lightcolor2[2] = lightcolor[2] * ifog;
+ if (layer->flags & ALIASLAYER_SPECULAR)
{
- if (!(count = *order++))
- break;
- if (count > 0)
- glBegin(GL_TRIANGLE_STRIP);
- else
- {
- glBegin(GL_TRIANGLE_FAN);
- count = -count;
- }
- do
- {
- qglArrayElement(order[2]);
- order += 3;
- }
- while (count--);
+ c_alias_polys += mesh->num_triangles;
+ R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, 0, 0, specularscale);
}
-
- glDisableClientState(GL_VERTEX_ARRAY);
- }
- else
- {
- while(1)
+ else if (layer->flags & ALIASLAYER_DIFFUSE)
{
- if (!(count = *order++))
- break;
- if (count > 0)
- glBegin(GL_TRIANGLE_STRIP);
- else
+ if (layer->flags & ALIASLAYER_COLORMAP_PANTS)
{
- glBegin(GL_TRIANGLE_FAN);
- count = -count;
+ // 128-224 are backwards ranges
+ c = (ent->colormap & 0xF) << 4;c += (c >= 128 && c < 224) ? 4 : 12;
+ // fullbright passes were already taken care of, so skip them in realtime lighting passes
+ if (c >= 224)
+ continue;
+ bcolor = (qbyte *) (&palette_complete[c]);
+ lightcolor2[0] *= bcolor[0] * (1.0f / 255.0f);
+ lightcolor2[1] *= bcolor[1] * (1.0f / 255.0f);
+ lightcolor2[2] *= bcolor[2] * (1.0f / 255.0f);
}
- do
+ else if (layer->flags & ALIASLAYER_COLORMAP_SHIRT)
{
- glVertex3fv(&aliasvert[order[2] * 3]);
- order += 3;
+ // 128-224 are backwards ranges
+ c = (ent->colormap & 0xF0);c += (c >= 128 && c < 224) ? 4 : 12;
+ // fullbright passes were already taken care of, so skip them in realtime lighting passes
+ if (c >= 224)
+ continue;
+ bcolor = (qbyte *) (&palette_complete[c]);
+ lightcolor2[0] *= bcolor[0] * (1.0f / 255.0f);
+ lightcolor2[1] *= bcolor[1] * (1.0f / 255.0f);
+ lightcolor2[2] *= bcolor[2] * (1.0f / 255.0f);
}
- while (count--);
+ c_alias_polys += mesh->num_triangles;
+ R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, ambientscale, diffusescale, 0);
}
}
-
- glEnable (GL_TEXTURE_2D);
- glColor3f (1,1,1);
}
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable (GL_BLEND);
- glDepthMask(1);
}
-int modeldlightbits[8];
-extern int r_dlightframecount;
-
-/*
-=================
-R_DrawAliasModel
-
-=================
-*/
-void R_DrawAliasModel (entity_t *ent, int cull, float alpha, model_t *clmodel, int frame, int skin, vec3_t org, int effects, int flags, int colormap)
-{
- int i;
- vec3_t mins, maxs, color;
- mleaf_t *leaf;
- void *modelheader;
- int *skinset;
-
- if (alpha < (1.0 / 64.0))
- return; // basically completely transparent
-
- VectorAdd (org, clmodel->mins, mins);
- VectorAdd (org, clmodel->maxs, maxs);
-
- if (cull && R_CullBox (mins, maxs))
- return;
-
- c_models++;
-
- leaf = Mod_PointInLeaf (org, cl.worldmodel);
- if (leaf->dlightframe == r_dlightframecount)
- for (i = 0;i < 8;i++)
- modeldlightbits[i] = leaf->dlightbits[i];
- else
- for (i = 0;i < 8;i++)
- modeldlightbits[i] = 0;
-
- // get lighting information
-
- if ((flags & EF_FULLBRIGHT) || (effects & EF_FULLBRIGHT))
- color[0] = color[1] = color[2] = 256;
- else
- R_LightPoint (color, org);
-
- if (r_render.value)
- glDisable(GL_ALPHA_TEST);
-
- if (frame < 0 || frame >= clmodel->numframes)
- {
- frame = 0;
- Con_DPrintf("invalid skin number %d for model %s\n", frame, clmodel->name);
- }
-
- if (skin < 0 || skin >= clmodel->numskins)
- {
- skin = 0;
- Con_DPrintf("invalid skin number %d for model %s\n", skin, clmodel->name);
- }
-
- modelheader = Mod_Extradata (clmodel);
-
- {
-// int *skinanimrange = (int *) (clmodel->skinanimrange + (int) modelheader) + skin * 2;
-// int *skinanim = (int *) (clmodel->skinanim + (int) modelheader);
- int *skinanimrange = clmodel->skinanimrange + skin * 2;
- int *skinanim = clmodel->skinanim;
- i = skinanimrange[0];
- if (skinanimrange[1] > 1) // animated
- i += ((int) (cl.time * 10) % skinanimrange[1]);
- skinset = skinanim + i*5;
- }
-
- if (r_render.value)
- glEnable (GL_TEXTURE_2D);
-
- c_alias_polys += clmodel->numtris;
- if (clmodel->aliastype == ALIASTYPE_MD2)
- R_DrawQ2AliasFrame (modelheader, alpha, color, ent, ent != &cl.viewent, org, frame, skinset[0], effects, flags);
- else
- R_DrawAliasFrame (modelheader, alpha, color, ent, ent != &cl.viewent, org, frame, skinset, colormap, effects, flags);
-}