2003-01-17 21:18:53 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001-2002 Charles Hollemeersch
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
PENTA: the whole file is freakin penta...
|
|
|
|
|
|
|
|
Abstracts the different paths that exist for different 3d-cards.
|
|
|
|
|
|
|
|
Idea: Write a new R_DrawLightEntitys* and do whatever you want in it.
|
|
|
|
adapt R_DrawLightEntitys to call your new code if the requirements are met.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
DrawLightEntities, draws lit bumpmapped entities, calls apropriate function for the user's 3d card.
|
|
|
|
|
|
|
|
NOTE: This should not draw sprites, sprites are drawn separately.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#include "quakedef.h"
|
|
|
|
|
2003-02-15 18:53:11 +00:00
|
|
|
bumpdriver_t gl_bumpdriver;
|
|
|
|
|
2003-01-17 21:18:53 +00:00
|
|
|
/* Some material definitions. */
|
2003-08-20 20:51:23 +00:00
|
|
|
float gl_Light_Ambience2[4] = {0.03f,0.03f,0.03f,0.03f};
|
|
|
|
float gl_Light_Diffuse2[4] = {0.03f,0.03f,0.03f,0.03f};
|
2003-01-17 21:18:53 +00:00
|
|
|
float gl_Light_Specular2[4] = {0,0,0,0};
|
2003-08-20 20:51:23 +00:00
|
|
|
float gl_Material_Color2[4] = {0.9f, 0.9f, 0.9f, 0.9f};
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
void R_DrawLightEntitiesGF3 (shadowlight_t *l);
|
|
|
|
void R_DrawLightEntitiesGF (shadowlight_t *l);
|
|
|
|
void R_DrawLightEntitiesGEN (shadowlight_t *l);
|
|
|
|
void R_DrawLightEntitiesRadeon (shadowlight_t *l); //PA:
|
|
|
|
void R_DrawLightEntitiesParhelia (shadowlight_t *l); //PA:
|
|
|
|
void R_DrawLightEntitiesARB (shadowlight_t *l); //PA:
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
/************************
|
|
|
|
|
|
|
|
Shader utility routines: For use by drivers
|
|
|
|
|
|
|
|
*************************/
|
|
|
|
|
|
|
|
void SH_SetupTcMod(tcmod_t *tc)
|
|
|
|
{
|
|
|
|
switch (tc->type)
|
|
|
|
{
|
|
|
|
case TCMOD_ROTATE:
|
|
|
|
glTranslatef(0.5,0.5,0.0);
|
|
|
|
glRotatef(realtime * tc->params[0],0,0,1);
|
|
|
|
glTranslatef(-0.5, -0.5, 0.0);
|
|
|
|
break;
|
|
|
|
case TCMOD_SCROLL:
|
|
|
|
glTranslatef(realtime * tc->params[0], realtime * tc->params[1], 0.0);
|
|
|
|
break;
|
|
|
|
case TCMOD_SCALE:
|
|
|
|
glScalef(tc->params[0],tc->params[1],1.0);
|
|
|
|
break;
|
|
|
|
case TCMOD_STRETCH:
|
|
|
|
//PENTA: fixme
|
|
|
|
glScalef(1.0, 1.0, 1.0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SH_SetupTcMods(stage_t *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < s->numtcmods; i++)
|
|
|
|
SH_SetupTcMod(&s->tcmods[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SH_SetupSimpleStage(stage_t *s)
|
|
|
|
{
|
|
|
|
tcmod_t *tc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (s->type != STAGE_SIMPLE)
|
|
|
|
{
|
|
|
|
Con_Printf("Non simple stage, in simple stage list");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glPushMatrix();
|
|
|
|
|
|
|
|
for (i=0; i<s->numtcmods; i++)
|
|
|
|
{
|
|
|
|
SH_SetupTcMod(&s->tcmods[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->src_blend > -1)
|
|
|
|
{
|
|
|
|
glBlendFunc(s->src_blend, s->dst_blend);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->alphatresh > 0)
|
|
|
|
{
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
glAlphaFunc(GL_GREATER, s->alphatresh);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s->numtextures > 0) && (s->texture[0]))
|
|
|
|
GL_BindAdvanced(s->texture[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SH_BindBumpmap(shader_t *shader, int index) {
|
|
|
|
if (shader->numbumpstages) {
|
|
|
|
if (shader->bumpstages[index].numtextures)
|
|
|
|
GL_BindAdvanced(shader->bumpstages[index].texture[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SH_BindColormap(shader_t *shader, int index) {
|
|
|
|
if (shader->numbumpstages) {
|
|
|
|
if (shader->colorstages[index].numtextures)
|
|
|
|
GL_BindAdvanced(shader->colorstages[index].texture[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SH_SetupAlphaTest(shader_t *shader) {
|
|
|
|
if (shader->numcolorstages)
|
|
|
|
{
|
|
|
|
if (shader->colorstages[0].alphatresh > 0)
|
|
|
|
{
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
glAlphaFunc(GL_GEQUAL, shader->colorstages[0].alphatresh);
|
|
|
|
} else {
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-18 10:15:33 +00:00
|
|
|
/**
|
2003-02-15 18:53:11 +00:00
|
|
|
|
2003-08-18 10:15:33 +00:00
|
|
|
Draw tangent space for a vertexdef
|
2003-02-15 18:53:11 +00:00
|
|
|
|
2003-08-18 10:15:33 +00:00
|
|
|
*/
|
2003-06-25 09:59:55 +00:00
|
|
|
void R_DrawTangents (vertexdef_t *def, int num)
|
|
|
|
{
|
|
|
|
float* vert;
|
|
|
|
float* normal;
|
|
|
|
float* binormal;
|
|
|
|
float* tangent;
|
|
|
|
int vstr, nstr, tstr, bstr;
|
|
|
|
vec3_t extr;
|
|
|
|
int i;
|
2004-02-08 09:49:53 +00:00
|
|
|
/*
|
2003-06-25 09:59:55 +00:00
|
|
|
vert = def->vertices;
|
|
|
|
normal = def->normals;
|
|
|
|
binormal = def->binormals;
|
|
|
|
tangent = def->tangents;
|
|
|
|
|
|
|
|
vstr = (def->vertexstride == 0) ? 3 : def->vertexstride/4;
|
|
|
|
nstr = (def->normalstride == 0) ? 3 : def->normalstride/4;
|
|
|
|
tstr = (def->tangentstride == 0) ? 3 : def->tangentstride/4;
|
|
|
|
bstr = (def->binormalstride == 0) ? 3 : def->binormalstride/4;
|
|
|
|
|
|
|
|
for (i=0; i<num; i++, vert+=vstr, normal+=nstr, binormal+=bstr, tangent+=tstr) {
|
|
|
|
|
|
|
|
glColor3ub(255,0,0);
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3fv(&vert[0]);
|
|
|
|
VectorMA(vert,1,normal,extr);
|
|
|
|
glVertex3fv(&extr[0]);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glColor3ub(0,255,0);
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3fv(&vert[0]);
|
|
|
|
VectorMA(vert,1,tangent,extr);
|
|
|
|
glVertex3fv(&extr[0]);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glColor3ub(0,0,255);
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3fv(&vert[0]);
|
|
|
|
VectorMA(vert,1,binormal,extr);
|
|
|
|
glVertex3fv(&extr[0]);
|
|
|
|
glEnd();
|
|
|
|
}
|
2004-02-08 09:49:53 +00:00
|
|
|
*/
|
2003-06-25 09:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 18:53:11 +00:00
|
|
|
void R_DrawMeshAmbient(mesh_t *mesh) {
|
|
|
|
|
|
|
|
vertexdef_t def;
|
2003-05-04 21:53:50 +00:00
|
|
|
int res;
|
2003-02-15 18:53:11 +00:00
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.vertices = mesh->vertices;
|
2003-02-15 18:53:11 +00:00
|
|
|
def.vertexstride = sizeof(mmvertex_t);
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.texcoords = GL_OffsetDriverPtr(mesh->vertices, 12);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.texcoordstride = sizeof(mmvertex_t);
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.tangents = mesh->tangents;
|
2003-02-15 18:53:11 +00:00
|
|
|
def.tangentstride = 0;
|
2003-03-15 19:50:16 +00:00
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.binormals = mesh->binormals;
|
2003-02-15 18:53:11 +00:00
|
|
|
def.binormalstride = 0;
|
2003-03-15 19:50:16 +00:00
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.normals = mesh->normals;
|
2003-02-15 18:53:11 +00:00
|
|
|
def.normalstride = 0;
|
2003-03-15 19:50:16 +00:00
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.lightmapcoords = GL_OffsetDriverPtr(mesh->vertices, 20);
|
2003-03-15 19:50:16 +00:00
|
|
|
def.lightmapstride = sizeof(mmvertex_t);
|
2003-02-15 18:53:11 +00:00
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.colors = GL_OffsetDriverPtr(mesh->vertices, 28);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.colorstride = sizeof(mmvertex_t);
|
|
|
|
|
2003-05-04 21:53:50 +00:00
|
|
|
c_alias_polys += mesh->numtriangles;
|
|
|
|
|
|
|
|
if (gl_occlusiontest && sh_occlusiontest.value) {
|
|
|
|
glEnable(GL_OCCLUSION_TEST_HP);
|
|
|
|
gl_bumpdriver.drawTriangleListBase(&def, mesh->indecies, mesh->numindecies, mesh->shader->shader, mesh->lightmapIndex);
|
|
|
|
glDisable(GL_OCCLUSION_TEST_HP);
|
|
|
|
glGetIntegerv(GL_OCCLUSION_TEST_RESULT_HP,&res);
|
|
|
|
if (!res) {
|
|
|
|
mesh->visframe = r_framecount - 10; //make it invisible this frame
|
|
|
|
occlusion_cut_meshes++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gl_bumpdriver.drawTriangleListBase(&def, mesh->indecies, mesh->numindecies, mesh->shader->shader, mesh->lightmapIndex);
|
|
|
|
}
|
2003-06-25 09:59:55 +00:00
|
|
|
|
|
|
|
if (sh_showtangent.value) {
|
|
|
|
R_DrawTangents(&def, mesh->numvertices);
|
|
|
|
}
|
2003-02-15 18:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void R_DrawMeshBumped(mesh_t *mesh) {
|
|
|
|
|
|
|
|
vertexdef_t def;
|
2003-08-18 10:15:33 +00:00
|
|
|
lightobject_t lo;
|
2003-02-15 18:53:11 +00:00
|
|
|
|
|
|
|
if (mesh->visframe != r_framecount)
|
|
|
|
return;
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.vertices = mesh->vertices;
|
2003-02-15 18:53:11 +00:00
|
|
|
def.vertexstride = sizeof(mmvertex_t);
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.texcoords = GL_OffsetDriverPtr(mesh->vertices, 12);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.texcoordstride = sizeof(mmvertex_t);
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.tangents = mesh->tangents;
|
2003-02-15 18:53:11 +00:00
|
|
|
def.tangentstride = 0;
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.binormals = mesh->binormals;
|
2003-02-15 18:53:11 +00:00
|
|
|
def.binormalstride = 0;
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.normals = mesh->normals;
|
2003-02-15 18:53:11 +00:00
|
|
|
def.normalstride = 0;
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.lightmapcoords = DRVNULL; // no lightmaps on aliasses
|
2003-02-15 18:53:11 +00:00
|
|
|
|
2003-08-18 10:15:33 +00:00
|
|
|
VectorCopy(currentshadowlight->origin, lo.objectorigin);
|
|
|
|
VectorCopy(r_refdef.vieworg, lo.objectvieworg);
|
|
|
|
|
2003-05-04 21:53:50 +00:00
|
|
|
c_alias_polys += mesh->numtriangles;
|
|
|
|
|
2003-08-18 10:15:33 +00:00
|
|
|
gl_bumpdriver.drawTriangleListBump(&def, mesh->indecies, mesh->numindecies, mesh->shader->shader, &mesh->trans, &lo);
|
2003-02-15 18:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void R_DrawAliasAmbient(aliashdr_t *paliashdr, aliasframeinstant_t *instant) {
|
|
|
|
|
|
|
|
vertexdef_t def;
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.vertices = GL_WrapUserPointer(&instant->vertices[0][0]);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.vertexstride = 0;
|
2004-02-08 09:49:53 +00:00
|
|
|
def.texcoords = GL_WrapUserPointer((byte *)paliashdr + paliashdr->texcoords);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.texcoordstride = 0;
|
2004-02-08 09:49:53 +00:00
|
|
|
def.tangents = GL_WrapUserPointer(&instant->tangents[0][0]);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.tangentstride = 0;
|
2004-02-08 09:49:53 +00:00
|
|
|
def.binormals = GL_WrapUserPointer(&instant->binomials[0][0]);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.binormalstride = 0;
|
2004-02-08 09:49:53 +00:00
|
|
|
def.normals = GL_WrapUserPointer(&instant->normals[0][0]);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.normalstride = 0;
|
2004-02-08 09:49:53 +00:00
|
|
|
def.lightmapcoords = DRVNULL; // no lightmaps on aliasses
|
|
|
|
def.colors = DRVNULL;
|
2003-02-15 18:53:11 +00:00
|
|
|
def.colorstride = 0;
|
|
|
|
|
2003-05-04 21:53:50 +00:00
|
|
|
c_alias_polys += paliashdr->numtris;
|
|
|
|
|
2003-03-15 19:50:16 +00:00
|
|
|
gl_bumpdriver.drawTriangleListBase(&def, (int *)((byte *)paliashdr + paliashdr->indecies),paliashdr->numtris*3,paliashdr->shader, -1);
|
2003-06-25 09:59:55 +00:00
|
|
|
|
|
|
|
if (sh_showtangent.value) {
|
|
|
|
R_DrawTangents(&def, paliashdr->numtris*3);
|
|
|
|
}
|
2003-02-15 18:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void R_DrawAliasBumped(aliashdr_t *paliashdr, aliasframeinstant_t *instant) {
|
|
|
|
|
|
|
|
vertexdef_t def;
|
|
|
|
transform_t trans;
|
|
|
|
aliaslightinstant_t *linstant = instant->lightinstant;
|
2003-08-18 10:15:33 +00:00
|
|
|
lightobject_t lo;
|
2003-02-15 18:53:11 +00:00
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
def.vertices = GL_WrapUserPointer(&instant->vertices[0][0]);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.vertexstride = 0;
|
2004-02-08 09:49:53 +00:00
|
|
|
def.texcoords = GL_WrapUserPointer((byte *)paliashdr + paliashdr->texcoords);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.texcoordstride = 0;
|
2004-02-08 09:49:53 +00:00
|
|
|
def.tangents = GL_WrapUserPointer(&instant->tangents[0][0]);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.tangentstride = 0;
|
2004-02-08 09:49:53 +00:00
|
|
|
def.binormals = GL_WrapUserPointer(&instant->binomials[0][0]);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.binormalstride = 0;
|
2004-02-08 09:49:53 +00:00
|
|
|
def.normals = GL_WrapUserPointer(&instant->normals[0][0]);
|
2003-02-15 18:53:11 +00:00
|
|
|
def.normalstride = 0;
|
2004-02-08 09:49:53 +00:00
|
|
|
def.colors = DRVNULL;
|
2003-02-15 18:53:11 +00:00
|
|
|
def.colorstride = 0;
|
|
|
|
|
|
|
|
VectorCopy(currententity->origin,trans.origin);
|
|
|
|
VectorCopy(currententity->angles,trans.angles);
|
|
|
|
trans.scale[0] = trans.scale[1] = trans.scale[2] = 1.0f;
|
2003-05-04 21:53:50 +00:00
|
|
|
|
2003-08-18 10:15:33 +00:00
|
|
|
VectorCopy(linstant->lightpos, lo.objectorigin);
|
|
|
|
VectorCopy(linstant->vieworg, lo.objectvieworg);
|
2003-05-04 21:53:50 +00:00
|
|
|
c_alias_polys += paliashdr->numtris;
|
|
|
|
|
2003-08-18 10:15:33 +00:00
|
|
|
gl_bumpdriver.drawTriangleListBump(&def,&linstant->indecies[0],linstant->numtris*3,paliashdr->shader, &trans, &lo);
|
2003-02-15 18:53:11 +00:00
|
|
|
}
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
msurface_t *lightmapSurfs[MAX_LIGHTMAPS];
|
|
|
|
//Batches are almost never larger than about 300 indexes in a normal map
|
|
|
|
#define MAX_BATCH_SIZE 512
|
|
|
|
int indexList[MAX_BATCH_SIZE];
|
2003-02-15 18:53:11 +00:00
|
|
|
|
|
|
|
void R_DrawBrushAmbient (entity_t *e) {
|
2004-02-08 09:49:53 +00:00
|
|
|
int numsurf;
|
|
|
|
msurface_t *s;
|
|
|
|
glpoly_t *p;
|
|
|
|
int freeIndex, i;
|
|
|
|
shader_t *lastShader;
|
2003-02-15 18:53:11 +00:00
|
|
|
model_t *model;
|
|
|
|
|
|
|
|
model = e->model;
|
2004-02-08 09:49:53 +00:00
|
|
|
memset(lightmapSurfs, 0, sizeof(msurface_t*)*cl.worldmodel->numlightmaps);
|
|
|
|
//Sort per lightmap
|
|
|
|
s = &model->surfaces[model->firstmodelsurface];
|
|
|
|
for (i=0; i<model->nummodelsurfaces; i++, s++) {
|
|
|
|
if (!s->polys) { continue; }
|
|
|
|
s->lightmapchain = lightmapSurfs[s->lightmaptexturenum];
|
|
|
|
lightmapSurfs[s->lightmaptexturenum] = s;
|
|
|
|
}
|
2003-02-15 18:53:11 +00:00
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
//Dump to index array
|
|
|
|
for (i=0; i<cl.worldmodel->numlightmaps; i++) {
|
|
|
|
s = lightmapSurfs[i];
|
|
|
|
freeIndex = 0;
|
|
|
|
if (!s) continue;
|
|
|
|
lastShader = s->shader->shader;
|
|
|
|
while (s) {
|
|
|
|
p = s->polys;
|
|
|
|
//Space left in this batch?
|
|
|
|
if (((freeIndex + p->numindecies) >= MAX_BATCH_SIZE) || (s->shader->shader != lastShader)) {
|
|
|
|
gl_bumpdriver.drawTriangleListBase(&worldVertexDef, indexList, freeIndex, lastShader, i);
|
|
|
|
freeIndex = 0;
|
2003-02-15 18:53:11 +00:00
|
|
|
}
|
2004-02-08 09:49:53 +00:00
|
|
|
memcpy(&indexList[freeIndex],p->indecies,sizeof(int)*p->numindecies);
|
|
|
|
freeIndex += p->numindecies;
|
|
|
|
lastShader = s->shader->shader;
|
|
|
|
s = s->lightmapchain;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Draw the last batch
|
|
|
|
if (freeIndex) {
|
|
|
|
gl_bumpdriver.drawTriangleListBase(&worldVertexDef, indexList, freeIndex, lastShader, i);
|
|
|
|
//Con_Printf("DrawBatch %i\n", freeIndex/3);
|
2003-02-15 18:53:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_DrawBrushBumped (entity_t *e) {
|
|
|
|
transform_t trans;
|
2004-02-08 09:49:53 +00:00
|
|
|
int freeIndex, i;
|
2003-08-18 10:15:33 +00:00
|
|
|
lightobject_t lo;
|
2004-02-08 09:49:53 +00:00
|
|
|
shader_t *lastShader;
|
|
|
|
msurface_t *s;
|
|
|
|
glpoly_t *p;
|
|
|
|
model_t *model;
|
2003-02-15 18:53:11 +00:00
|
|
|
|
|
|
|
VectorCopy(e->origin,trans.origin);
|
|
|
|
VectorCopy(e->angles,trans.angles);
|
|
|
|
trans.scale[0] = trans.scale[1] = trans.scale[2] = 1.0f;
|
2003-08-18 10:15:33 +00:00
|
|
|
|
|
|
|
VectorCopy(((brushlightinstant_t *)e->brushlightinstant)->lightpos, lo.objectorigin);
|
|
|
|
VectorCopy(((brushlightinstant_t *)e->brushlightinstant)->vieworg, lo.objectvieworg);
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
model = e->model;
|
|
|
|
s = &model->surfaces[model->firstmodelsurface];
|
|
|
|
lastShader = s->shader->shader;
|
|
|
|
freeIndex = 0;
|
|
|
|
for (i=0; i<model->nummodelsurfaces; i++, s++) {
|
|
|
|
p = s->polys;
|
|
|
|
if (!p) continue;
|
|
|
|
//Shader has changed, end this batch and start a new one
|
|
|
|
if ((s->shader->shader != lastShader) || ((freeIndex + p->numindecies) >= MAX_BATCH_SIZE)) {
|
|
|
|
gl_bumpdriver.drawTriangleListBump(&worldVertexDef, indexList, freeIndex, lastShader, &trans, &lo);
|
|
|
|
//Con_Printf("BumpDrawBatch %i\n", freeIndex/3);
|
|
|
|
freeIndex = 0;
|
|
|
|
}
|
|
|
|
lastShader = s->shader->shader;
|
|
|
|
memcpy(&indexList[freeIndex],p->indecies,sizeof(int)*p->numindecies);
|
|
|
|
freeIndex += p->numindecies;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (freeIndex) {
|
|
|
|
gl_bumpdriver.drawTriangleListBump(&worldVertexDef, indexList, freeIndex, lastShader, &trans, &lo);
|
|
|
|
//Con_Printf("BumpDrawBatch %i\n", freeIndex/3);
|
|
|
|
}
|
2003-02-15 18:53:11 +00:00
|
|
|
}
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
/**
|
|
|
|
All surfaces have the same shader but may have different lightmaps
|
|
|
|
*/
|
2003-02-15 18:53:11 +00:00
|
|
|
void R_DrawWorldAmbientChain(msurface_t *first) {
|
|
|
|
int numsurf;
|
|
|
|
msurface_t *s;
|
2004-02-08 09:49:53 +00:00
|
|
|
glpoly_t *p;
|
|
|
|
int freeIndex, i;
|
2003-02-15 18:53:11 +00:00
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
memset(lightmapSurfs, 0, sizeof(msurface_t*)*cl.worldmodel->numlightmaps);
|
|
|
|
//Sort per lightmap
|
2003-02-15 18:53:11 +00:00
|
|
|
s = first;
|
|
|
|
while (s) {
|
2004-02-08 09:49:53 +00:00
|
|
|
if (!s->polys) { s = s->texturechain; continue; }
|
|
|
|
s->lightmapchain = lightmapSurfs[s->lightmaptexturenum];
|
|
|
|
lightmapSurfs[s->lightmaptexturenum] = s;
|
2003-02-15 18:53:11 +00:00
|
|
|
s = s->texturechain;
|
|
|
|
}
|
|
|
|
|
2004-02-08 09:49:53 +00:00
|
|
|
//Dump to index array
|
|
|
|
for (i=0; i<cl.worldmodel->numlightmaps; i++) {
|
|
|
|
s = lightmapSurfs[i];
|
|
|
|
freeIndex = 0;
|
|
|
|
while (s) {
|
|
|
|
p = s->polys;
|
|
|
|
//Space left in this batch?
|
|
|
|
if ((freeIndex + p->numindecies) >= MAX_BATCH_SIZE) {
|
|
|
|
gl_bumpdriver.drawTriangleListBase(&worldVertexDef, indexList, freeIndex, first->shader->shader, i);
|
|
|
|
//Con_Printf("DrawBatch %i\n", freeIndex/3);
|
|
|
|
freeIndex = 0;
|
|
|
|
}
|
|
|
|
memcpy(&indexList[freeIndex],p->indecies,sizeof(int)*p->numindecies);
|
|
|
|
freeIndex += p->numindecies;
|
|
|
|
s = s->lightmapchain;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Draw the last batch
|
|
|
|
if (freeIndex) {
|
|
|
|
gl_bumpdriver.drawTriangleListBase(&worldVertexDef, indexList, freeIndex, first->shader->shader, i);
|
|
|
|
//Con_Printf("DrawBatch %i\n", freeIndex/3);
|
|
|
|
}
|
2003-02-15 18:53:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_DrawWorldBumped() {
|
|
|
|
|
|
|
|
transform_t trans;
|
2004-02-08 09:49:53 +00:00
|
|
|
int freeIndex, i;
|
2003-08-18 10:15:33 +00:00
|
|
|
lightobject_t lo;
|
2004-02-08 09:49:53 +00:00
|
|
|
shader_t *lastShader;
|
|
|
|
msurface_t *s;
|
|
|
|
glpoly_t *p;
|
2003-02-15 18:53:11 +00:00
|
|
|
|
|
|
|
if (!currentshadowlight->visible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
glDepthMask (0);
|
|
|
|
glShadeModel (GL_SMOOTH);
|
|
|
|
glDepthFunc(GL_EQUAL);
|
|
|
|
|
|
|
|
trans.angles[0] = trans.angles[1] = trans.angles[2] = 0.0f;
|
|
|
|
trans.origin[0] = trans.origin[1] = trans.origin[2] = 0.0f;
|
|
|
|
trans.scale[0] = trans.scale[1] = trans.scale[2] = 1.0f;
|
|
|
|
|
2003-08-18 10:15:33 +00:00
|
|
|
VectorCopy(currentshadowlight->origin, lo.objectorigin);
|
|
|
|
VectorCopy(r_refdef.vieworg, lo.objectvieworg);
|
|
|
|
|
2003-02-15 18:53:11 +00:00
|
|
|
for (i=0; i<currentshadowlight->numlightcmdsmesh-1; i++) {
|
|
|
|
R_DrawMeshBumped((mesh_t *)currentshadowlight->lightCmdsMesh[i].asVoid);
|
|
|
|
}
|
2004-02-08 09:49:53 +00:00
|
|
|
|
|
|
|
lastShader = ((msurface_t *)currentshadowlight->lightCmds[0].asVoid)->shader->shader;
|
|
|
|
freeIndex = 0;
|
|
|
|
for (i=0; i<currentshadowlight->numlightcmds-1; i++) {
|
|
|
|
s = (msurface_t *)currentshadowlight->lightCmds[i].asVoid;
|
|
|
|
p = s->polys;
|
|
|
|
if (!p) continue;
|
|
|
|
//Shader has changed, end this batch and start a new one
|
|
|
|
if ((s->shader->shader != lastShader) || ((freeIndex + p->numindecies) >= MAX_BATCH_SIZE)) {
|
|
|
|
gl_bumpdriver.drawTriangleListBump(&worldVertexDef, indexList, freeIndex, lastShader, &trans, &lo);
|
|
|
|
//Con_Printf("BumpDrawBatch %i\n", freeIndex/3);
|
|
|
|
freeIndex = 0;
|
|
|
|
}
|
|
|
|
lastShader = s->shader->shader;
|
|
|
|
memcpy(&indexList[freeIndex],p->indecies,sizeof(int)*p->numindecies);
|
|
|
|
freeIndex += p->numindecies;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (freeIndex) {
|
|
|
|
gl_bumpdriver.drawTriangleListBump(&worldVertexDef, indexList, freeIndex, lastShader, &trans, &lo);
|
|
|
|
//Con_Printf("BumpDrawBatch %i\n", freeIndex/3);
|
|
|
|
}
|
2003-02-15 18:53:11 +00:00
|
|
|
|
|
|
|
glColor3f (1,1,1);
|
|
|
|
glDisable (GL_BLEND);
|
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
glDepthMask (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
void R_DrawWorldBumped () // <AWE> Function should not have parameters.
|
2003-01-17 21:18:53 +00:00
|
|
|
{
|
|
|
|
switch(gl_cardtype )
|
|
|
|
{
|
|
|
|
case GEFORCE3:
|
2003-02-15 18:53:11 +00:00
|
|
|
R_DrawWorldBumpedGF3(); // <AWE> Function has no parameters.
|
2003-01-17 21:18:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GEFORCE:
|
2003-02-15 18:53:11 +00:00
|
|
|
R_DrawWorldBumpedGF(); // <AWE> Function has no parameters.
|
2003-01-17 21:18:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RADEON:
|
2003-02-15 18:53:11 +00:00
|
|
|
R_DrawWorldBumpedRadeon();
|
2003-01-17 21:18:53 +00:00
|
|
|
break;
|
|
|
|
#ifndef __glx__
|
|
|
|
case PARHELIA:
|
2003-02-15 18:53:11 +00:00
|
|
|
R_DrawWorldBumpedParhelia();
|
2003-01-17 21:18:53 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case ARB:
|
2003-02-15 18:53:11 +00:00
|
|
|
R_DrawWorldBumpedARB();
|
2003-01-17 21:18:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-02-15 18:53:11 +00:00
|
|
|
R_DrawWorldBumpedGEN();
|
2003-01-17 21:18:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-02-15 18:53:11 +00:00
|
|
|
*//*
|
2003-01-17 21:18:53 +00:00
|
|
|
void R_DrawLightEntities (shadowlight_t *l)
|
|
|
|
{
|
|
|
|
switch(gl_cardtype )
|
|
|
|
{
|
|
|
|
case GEFORCE3:
|
|
|
|
R_DrawLightEntitiesGF3( l );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEFORCE:
|
|
|
|
R_DrawLightEntitiesGF( l );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RADEON:
|
|
|
|
R_DrawLightEntitiesRadeon( l );
|
|
|
|
break;
|
|
|
|
#ifndef __glx__
|
|
|
|
case PARHELIA:
|
|
|
|
R_DrawLightEntitiesParhelia( l );
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case ARB:
|
|
|
|
R_DrawLightEntitiesARB( l );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
R_DrawLightEntitiesGEN( l );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-02-15 18:53:11 +00:00
|
|
|
*/
|
|
|
|
/*
|
2003-01-17 21:18:53 +00:00
|
|
|
void R_DrawLightEntitiesGF (shadowlight_t *l)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
float pos[4];
|
|
|
|
if (!cg_showentities.value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!currentshadowlight->visible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
glDepthMask (0);
|
|
|
|
glShadeModel (GL_SMOOTH);
|
|
|
|
|
|
|
|
//Meshes: Atten & selfshadow via vertex ligting
|
|
|
|
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
glEnable(GL_NORMALIZE);
|
|
|
|
|
|
|
|
pos[0] = l->origin[0];
|
|
|
|
pos[1] = l->origin[1];
|
|
|
|
pos[2] = l->origin[2];
|
|
|
|
pos[3] = 1;
|
|
|
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION,&pos[0]);
|
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, &l->color[0]);
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, &gl_Light_Ambience2[0]);
|
|
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, &gl_Light_Specular2[0]);
|
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
|
|
|
|
|
|
|
|
for (i=0 ; i<cl_numlightvisedicts ; i++)
|
|
|
|
{
|
|
|
|
currententity = cl_lightvisedicts[i];
|
|
|
|
|
|
|
|
if (currententity->model->type == mod_alias)
|
|
|
|
{
|
|
|
|
//these models are full bright
|
|
|
|
if (currententity->model->flags & EF_FULLBRIGHT) continue;
|
|
|
|
if (!currententity->aliasframeinstant) continue;
|
|
|
|
if ( ((aliasframeinstant_t *)currententity->aliasframeinstant)->shadowonly) continue;
|
|
|
|
|
|
|
|
R_DrawAliasObjectLight(currententity, R_DrawAliasBumped);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (R_ShouldDrawViewModel())
|
|
|
|
{
|
|
|
|
R_DrawAliasObjectLight(&cl.viewent, R_DrawAliasBumped);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
glDisable(GL_COLOR_MATERIAL);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_LIGHT0);
|
|
|
|
|
2003-02-15 18:53:11 +00:00
|
|
|
|
|
|
|
// Brushes: we use the same thecnique as the world
|
|
|
|
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
//glEnable(GL_TEXTURE_2D);
|
|
|
|
//GL_Bind(glow_texture_object);
|
|
|
|
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
//glShadeModel (GL_SMOOTH);
|
|
|
|
//glEnable(GL_ALPHA_TEST);
|
|
|
|
//glAlphaFunc(GL_GREATER,0.2);
|
|
|
|
for (i=0 ; i<cl_numlightvisedicts ; i++)
|
|
|
|
{
|
|
|
|
currententity = cl_lightvisedicts[i];
|
|
|
|
|
|
|
|
if (currententity->model->type == mod_brush)
|
|
|
|
{
|
|
|
|
if (!currententity->brushlightinstant) continue;
|
|
|
|
if ( ((brushlightinstant_t *)currententity->brushlightinstant)->shadowonly) continue;
|
|
|
|
R_DrawBrushObjectLight(currententity, R_DrawBrushBumped);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//reset gl state
|
|
|
|
|
|
|
|
//glAlphaFunc(GL_GREATER,0.666);//Satan!
|
|
|
|
//glDisable(GL_ALPHA_TEST);
|
|
|
|
glColor3f (1,1,1);
|
|
|
|
glDepthMask (1);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
glDisable (GL_BLEND);
|
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_DrawLightEntitiesGEN (shadowlight_t *l)
|
|
|
|
{
|
|
|
|
//Currently this is merged with the geforce2 path
|
|
|
|
R_DrawLightEntitiesGF(l);
|
|
|
|
}
|
2003-02-15 18:53:11 +00:00
|
|
|
*/
|
|
|
|
void R_DrawLightEntities (shadowlight_t *l)
|
2003-01-17 21:18:53 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!cg_showentities.value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!currentshadowlight->visible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
glDepthMask (0);
|
|
|
|
glShadeModel (GL_SMOOTH);
|
|
|
|
|
|
|
|
//Alias models
|
|
|
|
|
|
|
|
for (i=0 ; i<cl_numlightvisedicts ; i++)
|
|
|
|
{
|
2003-02-15 18:53:11 +00:00
|
|
|
currententity = cl_lightvisedicts[i];
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-02-15 18:53:11 +00:00
|
|
|
if (currententity->model->type == mod_alias)
|
|
|
|
{
|
|
|
|
//these models are full bright
|
|
|
|
if (currententity->model->flags & EF_FULLBRIGHT) continue;
|
|
|
|
if (!currententity->aliasframeinstant) continue;
|
|
|
|
if ( ((aliasframeinstant_t *)currententity->aliasframeinstant)->shadowonly) continue;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-02-15 18:53:11 +00:00
|
|
|
R_DrawAliasObjectLight(currententity, R_DrawAliasBumped);
|
|
|
|
}
|
2003-01-17 21:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (R_ShouldDrawViewModel()) {
|
2003-02-15 18:53:11 +00:00
|
|
|
R_DrawAliasObjectLight(&cl.viewent, R_DrawAliasBumped);
|
2003-01-17 21:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Brush models
|
|
|
|
for (i=0 ; i<cl_numlightvisedicts ; i++)
|
|
|
|
{
|
2003-02-15 18:53:11 +00:00
|
|
|
currententity = cl_lightvisedicts[i];
|
|
|
|
|
|
|
|
if (currententity->model->type == mod_brush)
|
|
|
|
{
|
|
|
|
if (!currententity->brushlightinstant) continue;
|
|
|
|
if ( ((brushlightinstant_t *)currententity->brushlightinstant)->shadowonly) continue;
|
|
|
|
R_DrawBrushObjectLight(currententity, R_DrawBrushBumped);
|
|
|
|
}
|
2003-01-17 21:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Cleanup state
|
|
|
|
glColor3f (1,1,1);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
glDisable (GL_BLEND);
|
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glDepthMask (1);
|
|
|
|
}
|