diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 4e7a4010e..8f3de0098 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -627,7 +627,7 @@ void CL_CheckForResend (void) Cvar_ForceSet(&cl_servername, cls.servername); #ifdef Q3CLIENT - //Q3 clients send thier cdkey to the q3 authorize server. + //Q3 clients send their cdkey to the q3 authorize server. //they send this packet with the challenge. //and the server will refuse the client if it hasn't sent it. CLQ3_SendAuthPacket(adr); @@ -2004,7 +2004,7 @@ void CL_ConnectionlessPacket (void) { //ack needs two parameters to work with realip properly. //firstly it needs an auth message, so it can't be spoofed. - //secondly, it needs a copy of the realip ident, so you can't report a different player's client (you would need access to thier ip). + //secondly, it needs a copy of the realip ident, so you can't report a different player's client (you would need access to their ip). data[5] = ' '; sprintf(data+6, "%i %i", atoi(MSG_ReadString()), cls.realip_ident); } @@ -3520,7 +3520,7 @@ void Host_Init (quakeparms_t *parms) Cbuf_Execute (); //if the server initialisation causes a problem, give it a place to abort to - //assuming they didn't use any waits in thier config (fools) + //assuming they didn't use any waits in their config (fools) //the configs should be fully loaded. //so convert the backwards compable commandline parameters in cvar sets. diff --git a/engine/client/m_master.c b/engine/client/m_master.c index 6d519abf6..cae0b511b 100644 --- a/engine/client/m_master.c +++ b/engine/client/m_master.c @@ -1517,7 +1517,7 @@ void M_QuickConnect_PreDraw(menu_t *menu) if (s->players == s->maxplayers) continue; //server is full already if (s->special & SS_PROXY) - continue; //don't quickconnect to a proxy. thier player counts are often wrong (especially with qtv) + continue; //don't quickconnect to a proxy. their player counts are often wrong (especially with qtv) if (s->ping < 50) //don't like servers with too high a ping { if (s->players > 0) diff --git a/engine/client/pr_csqc.c b/engine/client/pr_csqc.c index 34e51644b..91543fa63 100644 --- a/engine/client/pr_csqc.c +++ b/engine/client/pr_csqc.c @@ -170,7 +170,7 @@ static void CSQC_FindGlobals(void) fieldvector(velocity); \ fieldfloat(alpha); /*transparency*/ \ fieldfloat(scale); /*model scale*/ \ - fieldfloat(fatness); /*expand models X units along thier normals.*/ \ + fieldfloat(fatness); /*expand models X units along their normals.*/ \ fieldfloat(skin); \ fieldfloat(colormap); \ fieldfloat(flags); \ diff --git a/engine/client/teamplay.c b/engine/client/teamplay.c index 8cbee932f..9e082f58c 100644 --- a/engine/client/teamplay.c +++ b/engine/client/teamplay.c @@ -353,7 +353,7 @@ qboolean TP_SoundTrigger(char *message) //if there is a trigger there, play it. if (*strip == '#') filter++; if (*strip == ':') - break; //if someone says just one word, we can take any tidles in thier name to be a voice command + break; //if someone says just one word, we can take any tidles in their name to be a voice command if (*strip == '\n') lineend = strip; else if (*strip <= ' ') diff --git a/engine/common/q3common.c b/engine/common/q3common.c index 0a0d574e4..3d7724625 100644 --- a/engine/common/q3common.c +++ b/engine/common/q3common.c @@ -517,7 +517,7 @@ void MSG_WriteBits(sizebuf_t *msg, int value, int bits) //////////////////////////////////////////////////////////////////////////////// //q3 netchan -//note that the sv and cl both have thier own wrappers, to handle encryption. +//note that the sv and cl both have their own wrappers, to handle encryption. diff --git a/engine/common/translate.c b/engine/common/translate.c index 102bd21d9..74ac65aaa 100644 --- a/engine/common/translate.c +++ b/engine/common/translate.c @@ -39,7 +39,7 @@ static char *defaultlanguagetext = "STL_CLIENTISSTILLMUTED \"%s is muted (still)\\n\"\n" "STL_YOUAREMUTED \"%s is muted\\n\"\n" "STL_YOUARNTMUTED \"You are no longer muted\\n\"\n" -"STL_NONAMEASMUTE \"Muted players may not change thier names\\n\"\n" +"STL_NONAMEASMUTE \"Muted players may not change their names\\n\"\n" "STL_MUTEDVOTE \"Sorry, you cannot vote when muted as it may allow you to send a message.\\n\"\n" "STL_MUTEDCHAT \"You cannot chat while muted\\n\"\n" "STL_FLOODPROTACTIVE \"floodprot: You can't talk for %i seconds\\n\"\n" @@ -52,7 +52,7 @@ static char *defaultlanguagetext = "STL_MAPCHEAT \"Map model file does not match (%s), %i != %i/%i.\\nYou may need a new version of the map, or the proper install files.\\n\"\n" "STL_INVALIDTRACKCLIENT \"invalid player to track\\n\"\n" "STL_BADNAME \"Can't change name - new is invalid\\n\"\n" -"STL_CLIENTNAMECHANGE \"%s changed thier name to %s\\n\"\n" +"STL_CLIENTNAMECHANGE \"%s changed their name to %s\\n\"\n" "STL_SERVERPAUSED \"server is paused\\n\"\n" "STL_UPLOADDENIED \"Upload denied\\n\"\n" "STL_NAMEDCLIENTDOESNTEXIST \"client does not exist\\n\"\n" diff --git a/engine/d3d/d3d_rsurf.c b/engine/d3d/d3d_rsurf.c index 9ded98f3f..dd9cd79ec 100644 --- a/engine/d3d/d3d_rsurf.c +++ b/engine/d3d/d3d_rsurf.c @@ -1,1368 +1,1368 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "d3dquake.h" - -int numlightmaps; - -mvertex_t *r_pcurrentvertbase; - -#define LMBLOCK_WIDTH 128 -#define LMBLOCK_HEIGHT LMBLOCK_WIDTH - -LPDIRECTDRAWSURFACE7 *lightmap_d3dtextures; -LPDIRECTDRAWSURFACE7 *deluxmap_d3dtextures; -lightmapinfo_t **lightmap; - - - -void D3D_BuildSurfaceDisplayList (msurface_t *fa) -{ - int i, lindex, lnumverts; - medge_t *pedges, *r_pedge; - int vertpage; - float *vec; - float s, t; - int lm; - - int size; - mesh_t *mesh; - -// reconstruct the polygon - pedges = currentmodel->edges; - lnumverts = fa->numedges; - vertpage = 0; - - - if (lnumverts<3) - return; //q3 map. - - size = sizeof(mesh_t) + sizeof(index_t)*(lnumverts-2)*3 + (sizeof(vec3_t) + sizeof(vec3_t) + 2*sizeof(vec2_t) + sizeof(byte_vec4_t))*lnumverts; - - fa->mesh = mesh = Hunk_Alloc(size); - mesh->xyz_array = (vec3_t*)(mesh + 1); - mesh->normals_array = (vec3_t*)(mesh->xyz_array + lnumverts); - mesh->st_array = (vec2_t*)(mesh->normals_array + lnumverts); - mesh->lmst_array = (vec2_t*)(mesh->st_array + lnumverts); - mesh->colors_array = (byte_vec4_t*)(mesh->lmst_array + lnumverts); - mesh->indexes = (index_t*)(mesh->colors_array + lnumverts); - - mesh->numindexes = (lnumverts-2)*3; - mesh->numvertexes = lnumverts; - mesh->patchWidth = mesh->patchHeight = 1; - - for (i=0 ; iindexes[i*3] = 0; - mesh->indexes[i*3+1] = i+1; - mesh->indexes[i*3+2] = i+2; - } - - for (i=0 ; isurfedges[fa->firstedge + i]; - - if (lindex > 0) - { - r_pedge = &pedges[lindex]; - vec = r_pcurrentvertbase[r_pedge->v[0]].position; - } - else - { - r_pedge = &pedges[-lindex]; - vec = r_pcurrentvertbase[r_pedge->v[1]].position; - } - - s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3]; - t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3]; - - VectorCopy (vec, mesh->xyz_array[i]); - mesh->xyz_array[i][3] = 1; - mesh->st_array[i][0] = s/fa->texinfo->texture->width; - mesh->st_array[i][1] = t/fa->texinfo->texture->height; - - s -= fa->texturemins[0]; - lm = s*fa->light_t; - s += fa->light_s*16; - s += 8; - s /= LMBLOCK_WIDTH*16; - - t -= fa->texturemins[1]; - lm += t; - t += fa->light_t*16; - t += 8; - t /= LMBLOCK_HEIGHT*16; - - mesh->lmst_array[i][0] = s; - mesh->lmst_array[i][1] = t; - - if (fa->flags & SURF_PLANEBACK) - VectorNegate(fa->plane->normal, mesh->normals_array[i]); - else - VectorCopy(fa->plane->normal, mesh->normals_array[i]); - - mesh->colors_array[i][0] = 255; - mesh->colors_array[i][1] = 255; - mesh->colors_array[i][2] = 255; - mesh->colors_array[i][3] = 255; - } -} - - - - - - - -#define MAX_LIGHTMAP_SIZE 18 - -vec3_t blocknormals[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; -unsigned blocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; - -unsigned greenblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; -unsigned blueblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; - -void D3DR_BuildLightMap (msurface_t *surf, qbyte *dest, qbyte *deluxdest, stmap *stainsrc, int shift) -{ - int smax, tmax; - int t; - int i, j, size; - qbyte *lightmap; - unsigned scale; - int maps; - unsigned *bl; - qboolean isstained; - extern cvar_t r_ambient; - extern cvar_t gl_lightmap_shift; - - unsigned *blg; - unsigned *blb; - - int r, g, b; - int cr, cg, cb; - - int stride = LMBLOCK_WIDTH*lightmap_bytes; - - shift += 7; // increase to base value - surf->cached_dlight = (surf->dlightframe == r_framecount); - - smax = (surf->extents[0]>>4)+1; - tmax = (surf->extents[1]>>4)+1; - size = smax*tmax; - lightmap = surf->samples; - - if (size > MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE) - { //fixme: fill in? - Con_Printf("Lightmap too large\n"); - return; - } - -// if (currentmodel->deluxdata) -// GLR_BuildDeluxMap(surf, deluxdest); - - - - if (true) - { - // set to full bright if no light data - if (r_fullbright.value>0) //not qw - { - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - } - goto store; - } - if (!currentmodel->lightdata) - { - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - goto store; - } - -// clear to no light - t = r_ambient.value*255; - for (i=0 ; ifromgame == fg_quake3) //rgb - { - /* for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) //no light styles in q3 apparently. - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - } - */ - for (i = 0; i < tmax; i++) //q3 maps store thier light in a block fashion, q1/q2/hl store it in a linear fashion. - { - for (j = 0; j < smax; j++) - { - blocklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3]; - greenblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+1]; - blueblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+2]; - } - } -// memset(blocklights, 255, sizeof(blocklights)); - } - else if (currentmodel->engineflags & MDLF_RGBLIGHTING) //rgb - { - for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - - - if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. - { - for (i=0 ; istyles[maps]].colour & 1) - for (i=0 ; istyles[maps]].colour & 2) - for (i=0 ; istyles[maps]].colour & 4) - for (i=0 ; istyles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - - if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. - { - for (i=0 ; istyles[maps]].colour & 1) - for (i=0 ; istyles[maps]].colour & 2) - for (i=0 ; istyles[maps]].colour & 4) - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - } - else - { - // set to full bright if no light data - if (r_fullbright.value || !currentmodel->lightdata) - { - for (i=0 ; iengineflags & MDLF_RGBLIGHTING) //rgb - for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]/3; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - for (i=0 ; istyles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLights (surf); - } - -// bound, invert, and shift -store: -#define INVERTLIGHTMAPS -#ifdef INVERTLIGHTMAPS - switch (lightmap_bytes) - { - case 4: - stride -= (smax<<2); - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; - dest += 4; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - /* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[2] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -//*/ - - - - dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! - dest += 4; - } - } - } - break; - - case 3: - stride -= smax*3; - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest += 3; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - /* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[2] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -// */ - dest += 3; - } - } - } - break; - default: - Sys_Error ("Bad lightmap format"); - } -#else - switch (lightmap_bytes) - { - case 4: - stride -= (smax<<2); - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; - dest += 4; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - //* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[0] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[0] = 0; - else - dest[0] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[2] = 255; - else if ((b+cb) < 0) - dest[2] = 0; - else - dest[2] = (b+cb); -*/ - - - - dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! - dest += 4; - } - } - } - break; - - case 3: - stride -= smax*3; - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 255; - else if (t < 0) - dest[0] = 0; - else - dest[0] = t; - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 255; - else if (t < 0) - dest[1] = 0; - else - dest[1] = t; - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 255; - else if (t < 0) - dest[2] = 0; - else - dest[2] = t; - - dest += 3; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - //* - if ((r+cr) > 255) - dest[2] = 255; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -/*/ - if ((r+cr) > 255) - dest[0] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[0] = 0; - else - dest[0] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[2] = 255; - else if ((b+cb) < 0) - dest[2] = 0; - else - dest[2] = (b+cb); -// */ - dest += 3; - } - } - } - break; - default: - Sys_Error ("Bad lightmap format"); - } -#endif -} - - - -int D3DFillBlock (int texnum, int w, int h, int x, int y) -{ - int i, l; - while (texnum >= numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. - { - lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); - lightmap_d3dtextures = BZ_Realloc(lightmap_d3dtextures, sizeof(*lightmap_d3dtextures)*(numlightmaps+4)); -// lightmap_textures[numlightmaps+0] = texture_extension_number++; -// lightmap_textures[numlightmaps+1] = texture_extension_number++; -// lightmap_textures[numlightmaps+2] = texture_extension_number++; -// lightmap_textures[numlightmaps+3] = texture_extension_number++; - - deluxmap_d3dtextures = BZ_Realloc(deluxmap_d3dtextures, sizeof(*deluxmap_d3dtextures)*(numlightmaps+4)); -// deluxmap_textures[numlightmaps+0] = texture_extension_number++; -// deluxmap_textures[numlightmaps+1] = texture_extension_number++; -// deluxmap_textures[numlightmaps+2] = texture_extension_number++; -// deluxmap_textures[numlightmaps+3] = texture_extension_number++; - numlightmaps+=4; - } - for (i = texnum; i >= 0; i--) - { - if (!lightmap[i]) - { - lightmap[i] = BZ_Malloc(sizeof(*lightmap[i])); - for (l=0 ; lallocated[l] = LMBLOCK_HEIGHT; - } - - //maybe someone screwed with my lightmap... - memset(lightmap[i]->lightmaps, 255, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); - if (cl.worldmodel->lightdata) - memcpy(lightmap[i]->lightmaps, cl.worldmodel->lightdata+3*LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*i, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); - - } - else - break; - } - return texnum; -} - -int D3D7_AllocBlock (int w, int h, int *x, int *y) -{ - int i, j; - int best, best2; - int texnum; - - for (texnum=0 ; ; texnum++) - { - if (texnum == numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. - { - lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); - lightmap_d3dtextures = BZ_Realloc(lightmap_d3dtextures, sizeof(*lightmap_d3dtextures)*(numlightmaps+4)); -// lightmap_textures[numlightmaps+0] = texture_extension_number++; -// lightmap_textures[numlightmaps+1] = texture_extension_number++; -// lightmap_textures[numlightmaps+2] = texture_extension_number++; -// lightmap_textures[numlightmaps+3] = texture_extension_number++; - - deluxmap_d3dtextures = BZ_Realloc(deluxmap_d3dtextures, sizeof(*deluxmap_d3dtextures)*(numlightmaps+4)); -// deluxmap_textures[numlightmaps+0] = texture_extension_number++; -// deluxmap_textures[numlightmaps+1] = texture_extension_number++; -// deluxmap_textures[numlightmaps+2] = texture_extension_number++; -// deluxmap_textures[numlightmaps+3] = texture_extension_number++; - numlightmaps+=4; - } - if (!lightmap[texnum]) - { - lightmap[texnum] = Z_Malloc(sizeof(*lightmap[texnum])); - // reset stainmap since it now starts at 255 - memset(lightmap[texnum]->stainmaps, 255, sizeof(lightmap[texnum]->stainmaps)); - } - - - best = LMBLOCK_HEIGHT; - - for (i=0 ; iallocated[i+j] >= best) - break; - if (lightmap[texnum]->allocated[i+j] > best2) - best2 = lightmap[texnum]->allocated[i+j]; - } - if (j == w) - { // this is a valid spot - *x = i; - *y = best = best2; - } - } - - if (best + h > LMBLOCK_HEIGHT) - continue; - - for (i=0 ; iallocated[*x + i] = best + h; - - return texnum; - } - - Sys_Error ("AllocBlock: full"); - return 0; -} - - -void D3D_CreateSurfaceLightmap (msurface_t *surf, int shift) -{ - int smax, tmax; - qbyte *base, *luxbase; stmap *stainbase; - - if (surf->flags & (SURF_DRAWSKY|SURF_DRAWTURB)) - surf->lightmaptexturenum = -1; - if (surf->texinfo->flags & TEX_SPECIAL) - surf->lightmaptexturenum = -1; - if (surf->lightmaptexturenum<0) - return; - - smax = (surf->extents[0]>>4)+1; - tmax = (surf->extents[1]>>4)+1; - - if (smax > LMBLOCK_WIDTH || tmax > LMBLOCK_HEIGHT || smax < 0 || tmax < 0) - { //whoa, buggy. - surf->lightmaptexturenum = -1; - return; - } - - if (currentmodel->fromgame == fg_quake3) - D3DFillBlock(surf->lightmaptexturenum, smax, tmax, surf->light_s, surf->light_t); - else - surf->lightmaptexturenum = D3D7_AllocBlock (smax, tmax, &surf->light_s, &surf->light_t); - base = lightmap[surf->lightmaptexturenum]->lightmaps; - base += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; - - luxbase = lightmap[surf->lightmaptexturenum]->deluxmaps; - luxbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; - - stainbase = lightmap[surf->lightmaptexturenum]->stainmaps; - stainbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * 3; - - D3DR_BuildLightMap (surf, base, luxbase, stainbase, shift); -} - - -void D3DR_RenderDynamicLightmaps (msurface_t *fa, int shift) -{ - qbyte *base, *luxbase; - stmap *stainbase; - int maps; - glRect_t *theRect; - int smax, tmax; - - if (!fa->mesh) - return; - -// c_brush_polys++; - - if (fa->lightmaptexturenum<0) - return; - - if (fa->flags & ( SURF_DRAWSKY | SURF_DRAWTURB) ) - return; - - if (fa->texinfo->flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP)) - return; - - if (fa->texinfo->flags & (TEX_SPECIAL)) - { - if (cl.worldmodel->fromgame == fg_halflife) - return; //some textures do this. - } - -// fa->polys->chain = lightmap[fa->lightmaptexturenum]->polys; -// lightmap[fa->lightmaptexturenum]->polys = fa->polys; - - // check for lightmap modification -// if (cl.worldmodel->fromgame != fg_quake3) //no lightstyles on q3 maps - { - for (maps = 0 ; maps < MAXLIGHTMAPS && fa->styles[maps] != 255 ; - maps++) - if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps] - #ifdef PEXT_LIGHTSTYLECOL - || cl_lightstyle[fa->styles[maps]].colour != fa->cached_colour[maps] - #endif - ) - { - goto dynamic; - } - } - - if (fa->dlightframe == r_framecount // dynamic this frame - || fa->cached_dlight) // dynamic previously - { - RSpeedLocals(); -dynamic: - RSpeedRemark(); - - lightmap[fa->lightmaptexturenum]->modified = true; - - smax = (fa->extents[0]>>4)+1; - tmax = (fa->extents[1]>>4)+1; - - theRect = &lightmap[fa->lightmaptexturenum]->rectchange; - if (fa->light_t < theRect->t) { - if (theRect->h) - theRect->h += theRect->t - fa->light_t; - theRect->t = fa->light_t; - } - if (fa->light_s < theRect->l) { - if (theRect->w) - theRect->w += theRect->l - fa->light_s; - theRect->l = fa->light_s; - } - if ((theRect->w + theRect->l) < (fa->light_s + smax)) - theRect->w = (fa->light_s-theRect->l)+smax; - if ((theRect->h + theRect->t) < (fa->light_t + tmax)) - theRect->h = (fa->light_t-theRect->t)+tmax; - - lightmap[fa->lightmaptexturenum]->deluxmodified = true; - theRect = &lightmap[fa->lightmaptexturenum]->deluxrectchange; - if (fa->light_t < theRect->t) { - if (theRect->h) - theRect->h += theRect->t - fa->light_t; - theRect->t = fa->light_t; - } - if (fa->light_s < theRect->l) { - if (theRect->w) - theRect->w += theRect->l - fa->light_s; - theRect->l = fa->light_s; - } - - if ((theRect->w + theRect->l) < (fa->light_s + smax)) - theRect->w = (fa->light_s-theRect->l)+smax; - if ((theRect->h + theRect->t) < (fa->light_t + tmax)) - theRect->h = (fa->light_t-theRect->t)+tmax; - - - base = lightmap[fa->lightmaptexturenum]->lightmaps; - base += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; - luxbase = lightmap[fa->lightmaptexturenum]->deluxmaps; - luxbase += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; - stainbase = lightmap[fa->lightmaptexturenum]->stainmaps; - stainbase += (fa->light_t * LMBLOCK_WIDTH + fa->light_s) * 3; - D3DR_BuildLightMap (fa, base, luxbase, stainbase, shift); - - RSpeedEnd(RSPEED_DYNAMIC); - } -} - - - -LPDIRECTDRAWSURFACE7 D3D_NewLightmap(void) -{ - DWORD tflags = D3DX_TEXTURE_NOMIPMAP; //for now - DWORD twidth = LMBLOCK_WIDTH; - DWORD theight = LMBLOCK_HEIGHT; - D3DX_SURFACEFORMAT tformat = D3DX_SF_A8R8G8B8; - LPDIRECTDRAWSURFACE7 newsurf; - DWORD nummips; - - D3DXCreateTexture(pD3DDev, &tflags, &twidth, &theight, &tformat, NULL, &newsurf, &nummips); - if (!newsurf) - return NULL; - - return newsurf; -} - -void D3D_BuildLightmaps (void) -{ - DDSURFACEDESC2 desc; - - int i, j; - model_t *m; - int shift; - - r_framecount = 1; // no dlightcache -/* - for (i = 0; i < numlightmaps; i++) - { - if (!lightmap[i]) - break; - BZ_Free(lightmap[i]); - lightmap[i] = NULL; - } - - if (cl.worldmodel->fromgame == fg_doom) - return; //no lightmaps. - - if ((cl.worldmodel->engineflags & MDLF_RGBLIGHTING) || cl.worldmodel->deluxdata || r_loadlits.value) - gl_lightmap_format = GL_RGB; - else - gl_lightmap_format = GL_LUMINANCE; - - - if (cl.worldmodel->fromgame == fg_quake3 && gl_lightmap_format != GL_RGB && gl_lightmap_format != GL_RGBA) - gl_lightmap_format = GL_RGB; - - - switch (gl_lightmap_format) - { - case GL_RGBA: - lightmap_bytes = 4; - break; - case GL_RGB: - lightmap_bytes = 3; - break; - case GL_LUMINANCE: - case GL_INTENSITY: - case GL_ALPHA: - lightmap_bytes = 1; - break; - } -*/ - for (j=1 ; jname[0] == '*') - continue; - - r_pcurrentvertbase = m->vertexes; - currentmodel = m; - shift = 0;//GLR_LightmapShift(currentmodel); - - for (i=0 ; inumsurfaces ; i++) - { - D3D_CreateSurfaceLightmap (m->surfaces + i, shift); - P_EmitSkyEffectTris(m, &m->surfaces[i]); - if (m->surfaces[i].mesh) //there are some surfaces that have a display list already (the subdivided ones) - continue; - D3D_BuildSurfaceDisplayList (m->surfaces + i); - } - } - - // - // upload all lightmaps that were filled - // - for (i=0 ; imodified = false; - lightmap[i]->rectchange.l = LMBLOCK_WIDTH; - lightmap[i]->rectchange.t = LMBLOCK_HEIGHT; - lightmap[i]->rectchange.w = 0; - lightmap[i]->rectchange.h = 0; - - if (!lightmap_d3dtextures[i]) - { - lightmap_d3dtextures[i] = D3D_NewLightmap(); - - if (!lightmap_d3dtextures[i]) - { - Con_Printf("Couldn't create new lightmap\n"); - return; - } - } - - desc.dwSize = sizeof(desc); - lightmap_d3dtextures[i]->lpVtbl->Lock(lightmap_d3dtextures[i], NULL, &desc, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS, NULL); - memcpy(desc.lpSurface, lightmap[i]->lightmaps, sizeof(lightmap[i]->lightmaps)); - /* memset(desc.lpSurface, 0, sizeof(lightmap[i]->lightmaps)); - { - int i; - unsigned char *c; - c = desc.lpSurface; - for (i = 0; i < sizeof(lightmap[i]->lightmaps); i++) - *c++ = rand(); - }*/ - lightmap_d3dtextures[i]->lpVtbl->Unlock(lightmap_d3dtextures[i], NULL); - - if (deluxmap_d3dtextures[i]) - { - deluxmap_d3dtextures[i]->lpVtbl->Lock(deluxmap_d3dtextures[i], NULL, &desc, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS, NULL); - memcpy(desc.lpSurface, lightmap[i]->lightmaps, sizeof(lightmap[i]->deluxmaps)); - deluxmap_d3dtextures[i]->lpVtbl->Unlock(deluxmap_d3dtextures[i], NULL); - } - } - -} -#endif +#include "quakedef.h" +#ifdef D3DQUAKE +#include "d3dquake.h" + +int numlightmaps; + +mvertex_t *r_pcurrentvertbase; + +#define LMBLOCK_WIDTH 128 +#define LMBLOCK_HEIGHT LMBLOCK_WIDTH + +LPDIRECTDRAWSURFACE7 *lightmap_d3dtextures; +LPDIRECTDRAWSURFACE7 *deluxmap_d3dtextures; +lightmapinfo_t **lightmap; + + + +void D3D_BuildSurfaceDisplayList (msurface_t *fa) +{ + int i, lindex, lnumverts; + medge_t *pedges, *r_pedge; + int vertpage; + float *vec; + float s, t; + int lm; + + int size; + mesh_t *mesh; + +// reconstruct the polygon + pedges = currentmodel->edges; + lnumverts = fa->numedges; + vertpage = 0; + + + if (lnumverts<3) + return; //q3 map. + + size = sizeof(mesh_t) + sizeof(index_t)*(lnumverts-2)*3 + (sizeof(vec3_t) + sizeof(vec3_t) + 2*sizeof(vec2_t) + sizeof(byte_vec4_t))*lnumverts; + + fa->mesh = mesh = Hunk_Alloc(size); + mesh->xyz_array = (vec3_t*)(mesh + 1); + mesh->normals_array = (vec3_t*)(mesh->xyz_array + lnumverts); + mesh->st_array = (vec2_t*)(mesh->normals_array + lnumverts); + mesh->lmst_array = (vec2_t*)(mesh->st_array + lnumverts); + mesh->colors_array = (byte_vec4_t*)(mesh->lmst_array + lnumverts); + mesh->indexes = (index_t*)(mesh->colors_array + lnumverts); + + mesh->numindexes = (lnumverts-2)*3; + mesh->numvertexes = lnumverts; + mesh->patchWidth = mesh->patchHeight = 1; + + for (i=0 ; iindexes[i*3] = 0; + mesh->indexes[i*3+1] = i+1; + mesh->indexes[i*3+2] = i+2; + } + + for (i=0 ; isurfedges[fa->firstedge + i]; + + if (lindex > 0) + { + r_pedge = &pedges[lindex]; + vec = r_pcurrentvertbase[r_pedge->v[0]].position; + } + else + { + r_pedge = &pedges[-lindex]; + vec = r_pcurrentvertbase[r_pedge->v[1]].position; + } + + s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3]; + t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3]; + + VectorCopy (vec, mesh->xyz_array[i]); + mesh->xyz_array[i][3] = 1; + mesh->st_array[i][0] = s/fa->texinfo->texture->width; + mesh->st_array[i][1] = t/fa->texinfo->texture->height; + + s -= fa->texturemins[0]; + lm = s*fa->light_t; + s += fa->light_s*16; + s += 8; + s /= LMBLOCK_WIDTH*16; + + t -= fa->texturemins[1]; + lm += t; + t += fa->light_t*16; + t += 8; + t /= LMBLOCK_HEIGHT*16; + + mesh->lmst_array[i][0] = s; + mesh->lmst_array[i][1] = t; + + if (fa->flags & SURF_PLANEBACK) + VectorNegate(fa->plane->normal, mesh->normals_array[i]); + else + VectorCopy(fa->plane->normal, mesh->normals_array[i]); + + mesh->colors_array[i][0] = 255; + mesh->colors_array[i][1] = 255; + mesh->colors_array[i][2] = 255; + mesh->colors_array[i][3] = 255; + } +} + + + + + + + +#define MAX_LIGHTMAP_SIZE 18 + +vec3_t blocknormals[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; +unsigned blocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; + +unsigned greenblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; +unsigned blueblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; + +void D3DR_BuildLightMap (msurface_t *surf, qbyte *dest, qbyte *deluxdest, stmap *stainsrc, int shift) +{ + int smax, tmax; + int t; + int i, j, size; + qbyte *lightmap; + unsigned scale; + int maps; + unsigned *bl; + qboolean isstained; + extern cvar_t r_ambient; + extern cvar_t gl_lightmap_shift; + + unsigned *blg; + unsigned *blb; + + int r, g, b; + int cr, cg, cb; + + int stride = LMBLOCK_WIDTH*lightmap_bytes; + + shift += 7; // increase to base value + surf->cached_dlight = (surf->dlightframe == r_framecount); + + smax = (surf->extents[0]>>4)+1; + tmax = (surf->extents[1]>>4)+1; + size = smax*tmax; + lightmap = surf->samples; + + if (size > MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE) + { //fixme: fill in? + Con_Printf("Lightmap too large\n"); + return; + } + +// if (currentmodel->deluxdata) +// GLR_BuildDeluxMap(surf, deluxdest); + + + + if (true) + { + // set to full bright if no light data + if (r_fullbright.value>0) //not qw + { + for (i=0 ; idlightframe == r_framecount) +// GLR_AddDynamicLightsColours (surf); + } + goto store; + } + if (!currentmodel->lightdata) + { + for (i=0 ; idlightframe == r_framecount) +// GLR_AddDynamicLightsColours (surf); + goto store; + } + +// clear to no light + t = r_ambient.value*255; + for (i=0 ; ifromgame == fg_quake3) //rgb + { + /* for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; + maps++) //no light styles in q3 apparently. + { + scale = d_lightstylevalue[surf->styles[maps]]; + surf->cached_light[maps] = scale; // 8.8 fraction + surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; + } + */ + for (i = 0; i < tmax; i++) //q3 maps store their light in a block fashion, q1/q2/hl store it in a linear fashion. + { + for (j = 0; j < smax; j++) + { + blocklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3]; + greenblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+1]; + blueblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+2]; + } + } +// memset(blocklights, 255, sizeof(blocklights)); + } + else if (currentmodel->engineflags & MDLF_RGBLIGHTING) //rgb + { + for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; + maps++) + { + scale = d_lightstylevalue[surf->styles[maps]]; + surf->cached_light[maps] = scale; // 8.8 fraction + surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; + + + if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. + { + for (i=0 ; istyles[maps]].colour & 1) + for (i=0 ; istyles[maps]].colour & 2) + for (i=0 ; istyles[maps]].colour & 4) + for (i=0 ; istyles[maps] != 255 ; + maps++) + { + scale = d_lightstylevalue[surf->styles[maps]]; + surf->cached_light[maps] = scale; // 8.8 fraction + surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; + + if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. + { + for (i=0 ; istyles[maps]].colour & 1) + for (i=0 ; istyles[maps]].colour & 2) + for (i=0 ; istyles[maps]].colour & 4) + for (i=0 ; idlightframe == r_framecount) +// GLR_AddDynamicLightsColours (surf); + } + else + { + // set to full bright if no light data + if (r_fullbright.value || !currentmodel->lightdata) + { + for (i=0 ; iengineflags & MDLF_RGBLIGHTING) //rgb + for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; + maps++) + { + scale = d_lightstylevalue[surf->styles[maps]]/3; + surf->cached_light[maps] = scale; // 8.8 fraction + surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; + for (i=0 ; istyles[maps] != 255 ; + maps++) + { + scale = d_lightstylevalue[surf->styles[maps]]; + surf->cached_light[maps] = scale; // 8.8 fraction + surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; + for (i=0 ; idlightframe == r_framecount) +// GLR_AddDynamicLights (surf); + } + +// bound, invert, and shift +store: +#define INVERTLIGHTMAPS +#ifdef INVERTLIGHTMAPS + switch (lightmap_bytes) + { + case 4: + stride -= (smax<<2); + bl = blocklights; + blg = greenblklights; + blb = blueblklights; + +// if (!r_stains.value) + isstained = false; +// else +// isstained = surf->stained; + +/* if (!gl_lightcomponantreduction.value) + { + for (i=0 ; i>= 7; + if (t > 255) + dest[0] = 0; + else if (t < 0) + dest[0] = 256; + else + dest[0] = (255-t); + + t = *blg++; + t >>= 7; + if (t > 255) + dest[1] = 0; + else if (t < 0) + dest[1] = 256; + else + dest[1] = (255-t); + + t = *blb++; + t >>= 7; + if (t > 255) + dest[2] = 0; + else if (t < 0) + dest[2] = 256; + else + dest[2] = (255-t); + + dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; + dest += 4; + } + } + } + else +*/ { + stmap *stain; + for (i=0 ; i>= shift; + g >>= shift; + b >>= shift; + + if (isstained) // merge in stain + { + r = (127+r*(*stain++)) >> 8; + g = (127+g*(*stain++)) >> 8; + b = (127+b*(*stain++)) >> 8; + } + + cr = 0; + cg = 0; + cb = 0; + + if (r > 255) //ak too much red + { + cr -= (255-r)/2; + cg += (255-r)/4; //reduce it, and indicate to drop the others too. + cb += (255-r)/4; + r = 255; + } +// else if (r < 0) +// r = 0; + + if (g > 255) + { + cr += (255-g)/4; + cg -= (255-g)/2; + cb += (255-g)/4; + g = 255; + } +// else if (g < 0) +// g = 0; + + if (b > 255) + { + cr += (255-b)/4; + cg += (255-b)/4; + cb -= (255-b)/2; + b = 255; + } +// else if (b < 0) +// b = 0; + /* + if ((r+cr) > 255) + dest[2] = 0; //inverse lighting + else if ((r+cr) < 0) + dest[2] = 255; + else + dest[2] = 255-(r+cr); + + if ((g+cg) > 255) + dest[1] = 0; + else if ((g+cg) < 0) + dest[1] = 255; + else + dest[1] = 255-(g+cg); + + if ((b+cb) > 255) + dest[0] = 0; + else if ((b+cb) < 0) + dest[0] = 255; + else + dest[0] = 255-(b+cb); +/*/ + if ((r+cr) > 255) + dest[2] = 255; //non-inverse lighting + else if ((r+cr) < 0) + dest[2] = 0; + else + dest[2] = (r+cr); + + if ((g+cg) > 255) + dest[1] = 255; + else if ((g+cg) < 0) + dest[1] = 0; + else + dest[1] = (g+cg); + + if ((b+cb) > 255) + dest[0] = 255; + else if ((b+cb) < 0) + dest[0] = 0; + else + dest[0] = (b+cb); +//*/ + + + + dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! + dest += 4; + } + } + } + break; + + case 3: + stride -= smax*3; + bl = blocklights; + blg = greenblklights; + blb = blueblklights; + +// if (!r_stains.value) + isstained = false; +// else +// isstained = surf->stained; + +/* if (!gl_lightcomponantreduction.value) + { + for (i=0 ; i>= 7; + if (t > 255) + dest[0] = 0; + else if (t < 0) + dest[0] = 256; + else + dest[0] = (255-t); + + t = *blg++; + t >>= 7; + if (t > 255) + dest[1] = 0; + else if (t < 0) + dest[1] = 256; + else + dest[1] = (255-t); + + t = *blb++; + t >>= 7; + if (t > 255) + dest[2] = 0; + else if (t < 0) + dest[2] = 256; + else + dest[2] = (255-t); + + dest += 3; + } + } + } + else +*/ { + stmap *stain; + for (i=0 ; i>= shift; + g >>= shift; + b >>= shift; + + if (isstained) // merge in stain + { + r = (127+r*(*stain++)) >> 8; + g = (127+g*(*stain++)) >> 8; + b = (127+b*(*stain++)) >> 8; + } + + cr = 0; + cg = 0; + cb = 0; + + if (r > 255) //ak too much red + { + cr -= (255-r)/2; + cg += (255-r)/4; //reduce it, and indicate to drop the others too. + cb += (255-r)/4; + r = 255; + } +// else if (r < 0) +// r = 0; + + if (g > 255) + { + cr += (255-g)/4; + cg -= (255-g)/2; + cb += (255-g)/4; + g = 255; + } +// else if (g < 0) +// g = 0; + + if (b > 255) + { + cr += (255-b)/4; + cg += (255-b)/4; + cb -= (255-b)/2; + b = 255; + } +// else if (b < 0) +// b = 0; + /* + if ((r+cr) > 255) + dest[2] = 0; //inverse lighting + else if ((r+cr) < 0) + dest[2] = 255; + else + dest[2] = 255-(r+cr); + + if ((g+cg) > 255) + dest[1] = 0; + else if ((g+cg) < 0) + dest[1] = 255; + else + dest[1] = 255-(g+cg); + + if ((b+cb) > 255) + dest[0] = 0; + else if ((b+cb) < 0) + dest[0] = 255; + else + dest[0] = 255-(b+cb); +/*/ + if ((r+cr) > 255) + dest[2] = 255; //non-inverse lighting + else if ((r+cr) < 0) + dest[2] = 0; + else + dest[2] = (r+cr); + + if ((g+cg) > 255) + dest[1] = 255; + else if ((g+cg) < 0) + dest[1] = 0; + else + dest[1] = (g+cg); + + if ((b+cb) > 255) + dest[0] = 255; + else if ((b+cb) < 0) + dest[0] = 0; + else + dest[0] = (b+cb); +// */ + dest += 3; + } + } + } + break; + default: + Sys_Error ("Bad lightmap format"); + } +#else + switch (lightmap_bytes) + { + case 4: + stride -= (smax<<2); + bl = blocklights; + blg = greenblklights; + blb = blueblklights; + +// if (!r_stains.value) + isstained = false; +// else +// isstained = surf->stained; + +/* if (!gl_lightcomponantreduction.value) + { + for (i=0 ; i>= 7; + if (t > 255) + dest[0] = 0; + else if (t < 0) + dest[0] = 256; + else + dest[0] = (255-t); + + t = *blg++; + t >>= 7; + if (t > 255) + dest[1] = 0; + else if (t < 0) + dest[1] = 256; + else + dest[1] = (255-t); + + t = *blb++; + t >>= 7; + if (t > 255) + dest[2] = 0; + else if (t < 0) + dest[2] = 256; + else + dest[2] = (255-t); + + dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; + dest += 4; + } + } + } + else +*/ { + stmap *stain; + for (i=0 ; i>= shift; + g >>= shift; + b >>= shift; + + if (isstained) // merge in stain + { + r = (127+r*(*stain++)) >> 8; + g = (127+g*(*stain++)) >> 8; + b = (127+b*(*stain++)) >> 8; + } + + cr = 0; + cg = 0; + cb = 0; + + if (r > 255) //ak too much red + { + cr -= (255-r)/2; + cg += (255-r)/4; //reduce it, and indicate to drop the others too. + cb += (255-r)/4; + r = 255; + } +// else if (r < 0) +// r = 0; + + if (g > 255) + { + cr += (255-g)/4; + cg -= (255-g)/2; + cb += (255-g)/4; + g = 255; + } +// else if (g < 0) +// g = 0; + + if (b > 255) + { + cr += (255-b)/4; + cg += (255-b)/4; + cb -= (255-b)/2; + b = 255; + } +// else if (b < 0) +// b = 0; + //* + if ((r+cr) > 255) + dest[2] = 0; //inverse lighting + else if ((r+cr) < 0) + dest[2] = 255; + else + dest[2] = 255-(r+cr); + + if ((g+cg) > 255) + dest[1] = 0; + else if ((g+cg) < 0) + dest[1] = 255; + else + dest[1] = 255-(g+cg); + + if ((b+cb) > 255) + dest[0] = 0; + else if ((b+cb) < 0) + dest[0] = 255; + else + dest[0] = 255-(b+cb); +/*/ + if ((r+cr) > 255) + dest[0] = 255; //non-inverse lighting + else if ((r+cr) < 0) + dest[0] = 0; + else + dest[0] = (r+cr); + + if ((g+cg) > 255) + dest[1] = 255; + else if ((g+cg) < 0) + dest[1] = 0; + else + dest[1] = (g+cg); + + if ((b+cb) > 255) + dest[2] = 255; + else if ((b+cb) < 0) + dest[2] = 0; + else + dest[2] = (b+cb); +*/ + + + + dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! + dest += 4; + } + } + } + break; + + case 3: + stride -= smax*3; + bl = blocklights; + blg = greenblklights; + blb = blueblklights; + +// if (!r_stains.value) + isstained = false; +// else +// isstained = surf->stained; + +/* if (!gl_lightcomponantreduction.value) + { + for (i=0 ; i>= 7; + if (t > 255) + dest[0] = 255; + else if (t < 0) + dest[0] = 0; + else + dest[0] = t; + + t = *blg++; + t >>= 7; + if (t > 255) + dest[1] = 255; + else if (t < 0) + dest[1] = 0; + else + dest[1] = t; + + t = *blb++; + t >>= 7; + if (t > 255) + dest[2] = 255; + else if (t < 0) + dest[2] = 0; + else + dest[2] = t; + + dest += 3; + } + } + } + else +*/ { + stmap *stain; + for (i=0 ; i>= shift; + g >>= shift; + b >>= shift; + + if (isstained) // merge in stain + { + r = (127+r*(*stain++)) >> 8; + g = (127+g*(*stain++)) >> 8; + b = (127+b*(*stain++)) >> 8; + } + + cr = 0; + cg = 0; + cb = 0; + + if (r > 255) //ak too much red + { + cr -= (255-r)/2; + cg += (255-r)/4; //reduce it, and indicate to drop the others too. + cb += (255-r)/4; + r = 255; + } +// else if (r < 0) +// r = 0; + + if (g > 255) + { + cr += (255-g)/4; + cg -= (255-g)/2; + cb += (255-g)/4; + g = 255; + } +// else if (g < 0) +// g = 0; + + if (b > 255) + { + cr += (255-b)/4; + cg += (255-b)/4; + cb -= (255-b)/2; + b = 255; + } +// else if (b < 0) +// b = 0; + //* + if ((r+cr) > 255) + dest[2] = 255; //inverse lighting + else if ((r+cr) < 0) + dest[2] = 0; + else + dest[2] = (r+cr); + + if ((g+cg) > 255) + dest[1] = 255; + else if ((g+cg) < 0) + dest[1] = 0; + else + dest[1] = (g+cg); + + if ((b+cb) > 255) + dest[0] = 255; + else if ((b+cb) < 0) + dest[0] = 0; + else + dest[0] = (b+cb); +/*/ + if ((r+cr) > 255) + dest[0] = 255; //non-inverse lighting + else if ((r+cr) < 0) + dest[0] = 0; + else + dest[0] = (r+cr); + + if ((g+cg) > 255) + dest[1] = 255; + else if ((g+cg) < 0) + dest[1] = 0; + else + dest[1] = (g+cg); + + if ((b+cb) > 255) + dest[2] = 255; + else if ((b+cb) < 0) + dest[2] = 0; + else + dest[2] = (b+cb); +// */ + dest += 3; + } + } + } + break; + default: + Sys_Error ("Bad lightmap format"); + } +#endif +} + + + +int D3DFillBlock (int texnum, int w, int h, int x, int y) +{ + int i, l; + while (texnum >= numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. + { + lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); + lightmap_d3dtextures = BZ_Realloc(lightmap_d3dtextures, sizeof(*lightmap_d3dtextures)*(numlightmaps+4)); +// lightmap_textures[numlightmaps+0] = texture_extension_number++; +// lightmap_textures[numlightmaps+1] = texture_extension_number++; +// lightmap_textures[numlightmaps+2] = texture_extension_number++; +// lightmap_textures[numlightmaps+3] = texture_extension_number++; + + deluxmap_d3dtextures = BZ_Realloc(deluxmap_d3dtextures, sizeof(*deluxmap_d3dtextures)*(numlightmaps+4)); +// deluxmap_textures[numlightmaps+0] = texture_extension_number++; +// deluxmap_textures[numlightmaps+1] = texture_extension_number++; +// deluxmap_textures[numlightmaps+2] = texture_extension_number++; +// deluxmap_textures[numlightmaps+3] = texture_extension_number++; + numlightmaps+=4; + } + for (i = texnum; i >= 0; i--) + { + if (!lightmap[i]) + { + lightmap[i] = BZ_Malloc(sizeof(*lightmap[i])); + for (l=0 ; lallocated[l] = LMBLOCK_HEIGHT; + } + + //maybe someone screwed with my lightmap... + memset(lightmap[i]->lightmaps, 255, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); + if (cl.worldmodel->lightdata) + memcpy(lightmap[i]->lightmaps, cl.worldmodel->lightdata+3*LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*i, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); + + } + else + break; + } + return texnum; +} + +int D3D7_AllocBlock (int w, int h, int *x, int *y) +{ + int i, j; + int best, best2; + int texnum; + + for (texnum=0 ; ; texnum++) + { + if (texnum == numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. + { + lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); + lightmap_d3dtextures = BZ_Realloc(lightmap_d3dtextures, sizeof(*lightmap_d3dtextures)*(numlightmaps+4)); +// lightmap_textures[numlightmaps+0] = texture_extension_number++; +// lightmap_textures[numlightmaps+1] = texture_extension_number++; +// lightmap_textures[numlightmaps+2] = texture_extension_number++; +// lightmap_textures[numlightmaps+3] = texture_extension_number++; + + deluxmap_d3dtextures = BZ_Realloc(deluxmap_d3dtextures, sizeof(*deluxmap_d3dtextures)*(numlightmaps+4)); +// deluxmap_textures[numlightmaps+0] = texture_extension_number++; +// deluxmap_textures[numlightmaps+1] = texture_extension_number++; +// deluxmap_textures[numlightmaps+2] = texture_extension_number++; +// deluxmap_textures[numlightmaps+3] = texture_extension_number++; + numlightmaps+=4; + } + if (!lightmap[texnum]) + { + lightmap[texnum] = Z_Malloc(sizeof(*lightmap[texnum])); + // reset stainmap since it now starts at 255 + memset(lightmap[texnum]->stainmaps, 255, sizeof(lightmap[texnum]->stainmaps)); + } + + + best = LMBLOCK_HEIGHT; + + for (i=0 ; iallocated[i+j] >= best) + break; + if (lightmap[texnum]->allocated[i+j] > best2) + best2 = lightmap[texnum]->allocated[i+j]; + } + if (j == w) + { // this is a valid spot + *x = i; + *y = best = best2; + } + } + + if (best + h > LMBLOCK_HEIGHT) + continue; + + for (i=0 ; iallocated[*x + i] = best + h; + + return texnum; + } + + Sys_Error ("AllocBlock: full"); + return 0; +} + + +void D3D_CreateSurfaceLightmap (msurface_t *surf, int shift) +{ + int smax, tmax; + qbyte *base, *luxbase; stmap *stainbase; + + if (surf->flags & (SURF_DRAWSKY|SURF_DRAWTURB)) + surf->lightmaptexturenum = -1; + if (surf->texinfo->flags & TEX_SPECIAL) + surf->lightmaptexturenum = -1; + if (surf->lightmaptexturenum<0) + return; + + smax = (surf->extents[0]>>4)+1; + tmax = (surf->extents[1]>>4)+1; + + if (smax > LMBLOCK_WIDTH || tmax > LMBLOCK_HEIGHT || smax < 0 || tmax < 0) + { //whoa, buggy. + surf->lightmaptexturenum = -1; + return; + } + + if (currentmodel->fromgame == fg_quake3) + D3DFillBlock(surf->lightmaptexturenum, smax, tmax, surf->light_s, surf->light_t); + else + surf->lightmaptexturenum = D3D7_AllocBlock (smax, tmax, &surf->light_s, &surf->light_t); + base = lightmap[surf->lightmaptexturenum]->lightmaps; + base += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; + + luxbase = lightmap[surf->lightmaptexturenum]->deluxmaps; + luxbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; + + stainbase = lightmap[surf->lightmaptexturenum]->stainmaps; + stainbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * 3; + + D3DR_BuildLightMap (surf, base, luxbase, stainbase, shift); +} + + +void D3DR_RenderDynamicLightmaps (msurface_t *fa, int shift) +{ + qbyte *base, *luxbase; + stmap *stainbase; + int maps; + glRect_t *theRect; + int smax, tmax; + + if (!fa->mesh) + return; + +// c_brush_polys++; + + if (fa->lightmaptexturenum<0) + return; + + if (fa->flags & ( SURF_DRAWSKY | SURF_DRAWTURB) ) + return; + + if (fa->texinfo->flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP)) + return; + + if (fa->texinfo->flags & (TEX_SPECIAL)) + { + if (cl.worldmodel->fromgame == fg_halflife) + return; //some textures do this. + } + +// fa->polys->chain = lightmap[fa->lightmaptexturenum]->polys; +// lightmap[fa->lightmaptexturenum]->polys = fa->polys; + + // check for lightmap modification +// if (cl.worldmodel->fromgame != fg_quake3) //no lightstyles on q3 maps + { + for (maps = 0 ; maps < MAXLIGHTMAPS && fa->styles[maps] != 255 ; + maps++) + if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps] + #ifdef PEXT_LIGHTSTYLECOL + || cl_lightstyle[fa->styles[maps]].colour != fa->cached_colour[maps] + #endif + ) + { + goto dynamic; + } + } + + if (fa->dlightframe == r_framecount // dynamic this frame + || fa->cached_dlight) // dynamic previously + { + RSpeedLocals(); +dynamic: + RSpeedRemark(); + + lightmap[fa->lightmaptexturenum]->modified = true; + + smax = (fa->extents[0]>>4)+1; + tmax = (fa->extents[1]>>4)+1; + + theRect = &lightmap[fa->lightmaptexturenum]->rectchange; + if (fa->light_t < theRect->t) { + if (theRect->h) + theRect->h += theRect->t - fa->light_t; + theRect->t = fa->light_t; + } + if (fa->light_s < theRect->l) { + if (theRect->w) + theRect->w += theRect->l - fa->light_s; + theRect->l = fa->light_s; + } + if ((theRect->w + theRect->l) < (fa->light_s + smax)) + theRect->w = (fa->light_s-theRect->l)+smax; + if ((theRect->h + theRect->t) < (fa->light_t + tmax)) + theRect->h = (fa->light_t-theRect->t)+tmax; + + lightmap[fa->lightmaptexturenum]->deluxmodified = true; + theRect = &lightmap[fa->lightmaptexturenum]->deluxrectchange; + if (fa->light_t < theRect->t) { + if (theRect->h) + theRect->h += theRect->t - fa->light_t; + theRect->t = fa->light_t; + } + if (fa->light_s < theRect->l) { + if (theRect->w) + theRect->w += theRect->l - fa->light_s; + theRect->l = fa->light_s; + } + + if ((theRect->w + theRect->l) < (fa->light_s + smax)) + theRect->w = (fa->light_s-theRect->l)+smax; + if ((theRect->h + theRect->t) < (fa->light_t + tmax)) + theRect->h = (fa->light_t-theRect->t)+tmax; + + + base = lightmap[fa->lightmaptexturenum]->lightmaps; + base += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; + luxbase = lightmap[fa->lightmaptexturenum]->deluxmaps; + luxbase += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; + stainbase = lightmap[fa->lightmaptexturenum]->stainmaps; + stainbase += (fa->light_t * LMBLOCK_WIDTH + fa->light_s) * 3; + D3DR_BuildLightMap (fa, base, luxbase, stainbase, shift); + + RSpeedEnd(RSPEED_DYNAMIC); + } +} + + + +LPDIRECTDRAWSURFACE7 D3D_NewLightmap(void) +{ + DWORD tflags = D3DX_TEXTURE_NOMIPMAP; //for now + DWORD twidth = LMBLOCK_WIDTH; + DWORD theight = LMBLOCK_HEIGHT; + D3DX_SURFACEFORMAT tformat = D3DX_SF_A8R8G8B8; + LPDIRECTDRAWSURFACE7 newsurf; + DWORD nummips; + + D3DXCreateTexture(pD3DDev, &tflags, &twidth, &theight, &tformat, NULL, &newsurf, &nummips); + if (!newsurf) + return NULL; + + return newsurf; +} + +void D3D_BuildLightmaps (void) +{ + DDSURFACEDESC2 desc; + + int i, j; + model_t *m; + int shift; + + r_framecount = 1; // no dlightcache +/* + for (i = 0; i < numlightmaps; i++) + { + if (!lightmap[i]) + break; + BZ_Free(lightmap[i]); + lightmap[i] = NULL; + } + + if (cl.worldmodel->fromgame == fg_doom) + return; //no lightmaps. + + if ((cl.worldmodel->engineflags & MDLF_RGBLIGHTING) || cl.worldmodel->deluxdata || r_loadlits.value) + gl_lightmap_format = GL_RGB; + else + gl_lightmap_format = GL_LUMINANCE; + + + if (cl.worldmodel->fromgame == fg_quake3 && gl_lightmap_format != GL_RGB && gl_lightmap_format != GL_RGBA) + gl_lightmap_format = GL_RGB; + + + switch (gl_lightmap_format) + { + case GL_RGBA: + lightmap_bytes = 4; + break; + case GL_RGB: + lightmap_bytes = 3; + break; + case GL_LUMINANCE: + case GL_INTENSITY: + case GL_ALPHA: + lightmap_bytes = 1; + break; + } +*/ + for (j=1 ; jname[0] == '*') + continue; + + r_pcurrentvertbase = m->vertexes; + currentmodel = m; + shift = 0;//GLR_LightmapShift(currentmodel); + + for (i=0 ; inumsurfaces ; i++) + { + D3D_CreateSurfaceLightmap (m->surfaces + i, shift); + P_EmitSkyEffectTris(m, &m->surfaces[i]); + if (m->surfaces[i].mesh) //there are some surfaces that have a display list already (the subdivided ones) + continue; + D3D_BuildSurfaceDisplayList (m->surfaces + i); + } + } + + // + // upload all lightmaps that were filled + // + for (i=0 ; imodified = false; + lightmap[i]->rectchange.l = LMBLOCK_WIDTH; + lightmap[i]->rectchange.t = LMBLOCK_HEIGHT; + lightmap[i]->rectchange.w = 0; + lightmap[i]->rectchange.h = 0; + + if (!lightmap_d3dtextures[i]) + { + lightmap_d3dtextures[i] = D3D_NewLightmap(); + + if (!lightmap_d3dtextures[i]) + { + Con_Printf("Couldn't create new lightmap\n"); + return; + } + } + + desc.dwSize = sizeof(desc); + lightmap_d3dtextures[i]->lpVtbl->Lock(lightmap_d3dtextures[i], NULL, &desc, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS, NULL); + memcpy(desc.lpSurface, lightmap[i]->lightmaps, sizeof(lightmap[i]->lightmaps)); + /* memset(desc.lpSurface, 0, sizeof(lightmap[i]->lightmaps)); + { + int i; + unsigned char *c; + c = desc.lpSurface; + for (i = 0; i < sizeof(lightmap[i]->lightmaps); i++) + *c++ = rand(); + }*/ + lightmap_d3dtextures[i]->lpVtbl->Unlock(lightmap_d3dtextures[i], NULL); + + if (deluxmap_d3dtextures[i]) + { + deluxmap_d3dtextures[i]->lpVtbl->Lock(deluxmap_d3dtextures[i], NULL, &desc, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS, NULL); + memcpy(desc.lpSurface, lightmap[i]->lightmaps, sizeof(lightmap[i]->deluxmaps)); + deluxmap_d3dtextures[i]->lpVtbl->Unlock(deluxmap_d3dtextures[i], NULL); + } + } + +} +#endif diff --git a/engine/d3d9/d3d9_rsurf.c b/engine/d3d9/d3d9_rsurf.c index d98379227..4076527cc 100644 --- a/engine/d3d9/d3d9_rsurf.c +++ b/engine/d3d9/d3d9_rsurf.c @@ -1,1411 +1,1411 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "winquake.h" -#include "d3d9quake.h" - -int numlightmaps; - -mvertex_t *r_pcurrentvertbase; - -#define LMBLOCK_WIDTH 128 -#define LMBLOCK_HEIGHT LMBLOCK_WIDTH - -LPDIRECT3DTEXTURE9 *lightmap_d3d9textures; -LPDIRECT3DTEXTURE9 *deluxmap_d3d9textures; -lightmapinfo_t **lightmap; - - - -void D3D9_BuildSurfaceDisplayList (msurface_t *fa) -{ - int i, lindex, lnumverts; - medge_t *pedges, *r_pedge; - int vertpage; - float *vec; - float s, t; - int lm; - - int size; - mesh_t *mesh; - -// reconstruct the polygon - pedges = currentmodel->edges; - lnumverts = fa->numedges; - vertpage = 0; - - - if (lnumverts<3) - return; //q3 map. - - size = sizeof(mesh_t) + sizeof(index_t)*(lnumverts-2)*3 + (sizeof(vec3_t) + sizeof(vec3_t) + 2*sizeof(vec2_t) + sizeof(byte_vec4_t))*lnumverts; - - fa->mesh = mesh = Hunk_Alloc(size); - mesh->xyz_array = (vec3_t*)(mesh + 1); - mesh->normals_array = (vec3_t*)(mesh->xyz_array + lnumverts); - mesh->st_array = (vec2_t*)(mesh->normals_array + lnumverts); - mesh->lmst_array = (vec2_t*)(mesh->st_array + lnumverts); - mesh->colors_array = (byte_vec4_t*)(mesh->lmst_array + lnumverts); - mesh->indexes = (index_t*)(mesh->colors_array + lnumverts); - - mesh->numindexes = (lnumverts-2)*3; - mesh->numvertexes = lnumverts; - mesh->patchWidth = mesh->patchHeight = 1; - - for (i=0 ; iindexes[i*3] = 0; - mesh->indexes[i*3+1] = i+1; - mesh->indexes[i*3+2] = i+2; - } - - for (i=0 ; isurfedges[fa->firstedge + i]; - - if (lindex > 0) - { - r_pedge = &pedges[lindex]; - vec = r_pcurrentvertbase[r_pedge->v[0]].position; - } - else - { - r_pedge = &pedges[-lindex]; - vec = r_pcurrentvertbase[r_pedge->v[1]].position; - } - - s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3]; - t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3]; - - VectorCopy (vec, mesh->xyz_array[i]); - mesh->xyz_array[i][3] = 1; - mesh->st_array[i][0] = s/fa->texinfo->texture->width; - mesh->st_array[i][1] = t/fa->texinfo->texture->height; - - s -= fa->texturemins[0]; - lm = s*fa->light_t; - s += fa->light_s*16; - s += 8; - s /= LMBLOCK_WIDTH*16; - - t -= fa->texturemins[1]; - lm += t; - t += fa->light_t*16; - t += 8; - t /= LMBLOCK_HEIGHT*16; - - mesh->lmst_array[i][0] = s; - mesh->lmst_array[i][1] = t; - - if (fa->flags & SURF_PLANEBACK) - VectorNegate(fa->plane->normal, mesh->normals_array[i]); - else - VectorCopy(fa->plane->normal, mesh->normals_array[i]); - - mesh->colors_array[i][0] = 255; - mesh->colors_array[i][1] = 255; - mesh->colors_array[i][2] = 255; - mesh->colors_array[i][3] = 255; - } -} - - - - - - - -#define MAX_LIGHTMAP_SIZE LMBLOCK_WIDTH - -vec3_t blocknormals[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; -unsigned blocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; - -unsigned greenblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; -unsigned blueblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; - -void D3D9R_BuildLightMap (msurface_t *surf, qbyte *dest, qbyte *deluxdest, stmap *stainsrc, int shift) -{ - int smax, tmax; - int t; - int i, j, size; - qbyte *lightmap; - unsigned scale; - int maps; - unsigned *bl; - qboolean isstained; - extern cvar_t r_ambient; - extern cvar_t gl_lightmap_shift; - - unsigned *blg; - unsigned *blb; - - int r, g, b; - int cr, cg, cb; - - int stride = LMBLOCK_WIDTH*lightmap_bytes; - - shift += 7; // increase to base value - surf->cached_dlight = (surf->dlightframe == r_framecount); - - smax = (surf->extents[0]>>4)+1; - tmax = (surf->extents[1]>>4)+1; - size = smax*tmax; - lightmap = surf->samples; - - if (size > MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE) - { //fixme: fill in? - Con_Printf("Lightmap too large\n"); - return; - } - -// if (currentmodel->deluxdata) -// GLR_BuildDeluxMap(surf, deluxdest); - - - - if (true) - { - // set to full bright if no light data - if (r_fullbright.value>0) //not qw - { - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - } - goto store; - } - if (!currentmodel->lightdata) - { - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - goto store; - } - -// clear to no light - t = r_ambient.value*255; - for (i=0 ; ifromgame == fg_quake3) //rgb - { - /* for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) //no light styles in q3 apparently. - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - } - */ - for (i = 0; i < tmax; i++) //q3 maps store thier light in a block fashion, q1/q2/hl store it in a linear fashion. - { - for (j = 0; j < smax; j++) - { - blocklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3]; - greenblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+1]; - blueblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+2]; - } - } -// memset(blocklights, 255, sizeof(blocklights)); - } - else if (currentmodel->engineflags & MDLF_RGBLIGHTING) //rgb - { - for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - - - if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. - { - for (i=0 ; istyles[maps]].colour & 1) - for (i=0 ; istyles[maps]].colour & 2) - for (i=0 ; istyles[maps]].colour & 4) - for (i=0 ; istyles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - - if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. - { - for (i=0 ; istyles[maps]].colour & 1) - for (i=0 ; istyles[maps]].colour & 2) - for (i=0 ; istyles[maps]].colour & 4) - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - } - else - { - // set to full bright if no light data - if (r_fullbright.value || !currentmodel->lightdata) - { - for (i=0 ; iengineflags & MDLF_RGBLIGHTING) //rgb - for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]/3; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - for (i=0 ; istyles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLights (surf); - } - -// bound, invert, and shift -store: -#define INVERTLIGHTMAPS -#ifdef INVERTLIGHTMAPS - switch (lightmap_bytes) - { - case 4: - stride -= (smax<<2); - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; - dest += 4; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - /* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[2] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -//*/ - - - - dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! - dest += 4; - } - } - } - break; - - case 3: - stride -= smax*3; - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest += 3; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - /* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[2] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -// */ - dest += 3; - } - } - } - break; - default: - Sys_Error ("Bad lightmap format"); - } -#else - switch (lightmap_bytes) - { - case 4: - stride -= (smax<<2); - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; - dest += 4; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - //* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[0] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[0] = 0; - else - dest[0] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[2] = 255; - else if ((b+cb) < 0) - dest[2] = 0; - else - dest[2] = (b+cb); -*/ - - - - dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! - dest += 4; - } - } - } - break; - - case 3: - stride -= smax*3; - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 255; - else if (t < 0) - dest[0] = 0; - else - dest[0] = t; - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 255; - else if (t < 0) - dest[1] = 0; - else - dest[1] = t; - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 255; - else if (t < 0) - dest[2] = 0; - else - dest[2] = t; - - dest += 3; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - //* - if ((r+cr) > 255) - dest[2] = 255; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -/*/ - if ((r+cr) > 255) - dest[0] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[0] = 0; - else - dest[0] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[2] = 255; - else if ((b+cb) < 0) - dest[2] = 0; - else - dest[2] = (b+cb); -// */ - dest += 3; - } - } - } - break; - default: - Sys_Error ("Bad lightmap format"); - } -#endif -} - - - -int D3D9_FillBlock (int texnum, int w, int h, int x, int y) -{ - int i, l; - while (texnum >= numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. - { - lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); - lightmap_d3d9textures = BZ_Realloc(lightmap_d3d9textures, sizeof(*lightmap_d3d9textures)*(numlightmaps+4)); -// lightmap_textures[numlightmaps+0] = texture_extension_number++; -// lightmap_textures[numlightmaps+1] = texture_extension_number++; -// lightmap_textures[numlightmaps+2] = texture_extension_number++; -// lightmap_textures[numlightmaps+3] = texture_extension_number++; - - deluxmap_d3d9textures = BZ_Realloc(deluxmap_d3d9textures, sizeof(*deluxmap_d3d9textures)*(numlightmaps+4)); -// deluxmap_textures[numlightmaps+0] = texture_extension_number++; -// deluxmap_textures[numlightmaps+1] = texture_extension_number++; -// deluxmap_textures[numlightmaps+2] = texture_extension_number++; -// deluxmap_textures[numlightmaps+3] = texture_extension_number++; - numlightmaps+=4; - } - for (i = texnum; i >= 0; i--) - { - if (!lightmap[i]) - { - lightmap[i] = BZ_Malloc(sizeof(*lightmap[i])); - for (l=0 ; lallocated[l] = LMBLOCK_HEIGHT; - } - - //maybe someone screwed with my lightmap... - memset(lightmap[i]->lightmaps, 255, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); -// if (cl.worldmodel->lightdata) -// memcpy(lightmap[i]->lightmaps, cl.worldmodel->lightdata+3*LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*i, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); - - } - else - break; - } - return texnum; -} - -int D3D9_AllocBlock (int w, int h, int *x, int *y) -{ - int i, j; - int best, best2; - int texnum; - - for (texnum=0 ; ; texnum++) - { - if (texnum == numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. - { - lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); - lightmap_d3d9textures = BZ_Realloc(lightmap_d3d9textures, sizeof(*lightmap_d3d9textures)*(numlightmaps+4)); -// lightmap_textures[numlightmaps+0] = texture_extension_number++; -// lightmap_textures[numlightmaps+1] = texture_extension_number++; -// lightmap_textures[numlightmaps+2] = texture_extension_number++; -// lightmap_textures[numlightmaps+3] = texture_extension_number++; - - deluxmap_d3d9textures = BZ_Realloc(deluxmap_d3d9textures, sizeof(*deluxmap_d3d9textures)*(numlightmaps+4)); -// deluxmap_textures[numlightmaps+0] = texture_extension_number++; -// deluxmap_textures[numlightmaps+1] = texture_extension_number++; -// deluxmap_textures[numlightmaps+2] = texture_extension_number++; -// deluxmap_textures[numlightmaps+3] = texture_extension_number++; - numlightmaps+=4; - } - if (!lightmap[texnum]) - { - lightmap[texnum] = Z_Malloc(sizeof(*lightmap[texnum])); - // reset stainmap since it now starts at 255 - memset(lightmap[texnum]->stainmaps, 255, sizeof(lightmap[texnum]->stainmaps)); - } - - - best = LMBLOCK_HEIGHT; - - for (i=0 ; iallocated[i+j] >= best) - break; - if (lightmap[texnum]->allocated[i+j] > best2) - best2 = lightmap[texnum]->allocated[i+j]; - } - if (j == w) - { // this is a valid spot - *x = i; - *y = best = best2; - } - } - - if (best + h > LMBLOCK_HEIGHT) - continue; - - for (i=0 ; iallocated[*x + i] = best + h; - - return texnum; - } - - Sys_Error ("AllocBlock: full"); - return 0; -} - - -void D3D9_CreateSurfaceLightmap (msurface_t *surf, int shift) -{ - int smax, tmax; - qbyte *base, *luxbase; stmap *stainbase; - - if (surf->flags & (SURF_DRAWSKY|SURF_DRAWTURB)) - surf->lightmaptexturenum = -1; - if (surf->texinfo->flags & TEX_SPECIAL) - surf->lightmaptexturenum = -1; - if (surf->lightmaptexturenum<0) - return; - - smax = (surf->extents[0]>>4)+1; - tmax = (surf->extents[1]>>4)+1; - - if (smax > LMBLOCK_WIDTH || tmax > LMBLOCK_HEIGHT || smax < 0 || tmax < 0) - { //whoa, buggy. - surf->lightmaptexturenum = -1; - return; - } - - if (currentmodel->fromgame == fg_quake3) - D3D9_FillBlock(surf->lightmaptexturenum, smax, tmax, surf->light_s, surf->light_t); - else - surf->lightmaptexturenum = D3D9_AllocBlock (smax, tmax, &surf->light_s, &surf->light_t); - base = lightmap[surf->lightmaptexturenum]->lightmaps; - base += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; - - luxbase = lightmap[surf->lightmaptexturenum]->deluxmaps; - luxbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; - - stainbase = lightmap[surf->lightmaptexturenum]->stainmaps; - stainbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * 3; - - D3D9R_BuildLightMap (surf, base, luxbase, stainbase, shift); -} - - -void D3D9R_RenderDynamicLightmaps (msurface_t *fa, int shift) -{ - qbyte *base, *luxbase; - stmap *stainbase; - int maps; - glRect_t *theRect; - int smax, tmax; - - if (!fa->mesh) - return; - -// c_brush_polys++; - - if (fa->lightmaptexturenum<0) - return; - - if (fa->flags & ( SURF_DRAWSKY | SURF_DRAWTURB) ) - return; - - if (fa->texinfo->flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP)) - return; - - if (fa->texinfo->flags & (TEX_SPECIAL)) - { - if (cl.worldmodel->fromgame == fg_halflife) - return; //some textures do this. - } - -// fa->polys->chain = lightmap[fa->lightmaptexturenum]->polys; -// lightmap[fa->lightmaptexturenum]->polys = fa->polys; - - // check for lightmap modification -// if (cl.worldmodel->fromgame != fg_quake3) //no lightstyles on q3 maps - { - for (maps = 0 ; maps < MAXLIGHTMAPS && fa->styles[maps] != 255 ; - maps++) - if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps] - #ifdef PEXT_LIGHTSTYLECOL - || cl_lightstyle[fa->styles[maps]].colour != fa->cached_colour[maps] - #endif - ) - { - goto dynamic; - } - } - - if (fa->dlightframe == r_framecount // dynamic this frame - || fa->cached_dlight) // dynamic previously - { - RSpeedLocals(); -dynamic: - RSpeedRemark(); - - lightmap[fa->lightmaptexturenum]->modified = true; - - smax = (fa->extents[0]>>4)+1; - tmax = (fa->extents[1]>>4)+1; - - theRect = &lightmap[fa->lightmaptexturenum]->rectchange; - if (fa->light_t < theRect->t) { - if (theRect->h) - theRect->h += theRect->t - fa->light_t; - theRect->t = fa->light_t; - } - if (fa->light_s < theRect->l) { - if (theRect->w) - theRect->w += theRect->l - fa->light_s; - theRect->l = fa->light_s; - } - if ((theRect->w + theRect->l) < (fa->light_s + smax)) - theRect->w = (fa->light_s-theRect->l)+smax; - if ((theRect->h + theRect->t) < (fa->light_t + tmax)) - theRect->h = (fa->light_t-theRect->t)+tmax; - - lightmap[fa->lightmaptexturenum]->deluxmodified = true; - theRect = &lightmap[fa->lightmaptexturenum]->deluxrectchange; - if (fa->light_t < theRect->t) { - if (theRect->h) - theRect->h += theRect->t - fa->light_t; - theRect->t = fa->light_t; - } - if (fa->light_s < theRect->l) { - if (theRect->w) - theRect->w += theRect->l - fa->light_s; - theRect->l = fa->light_s; - } - - if ((theRect->w + theRect->l) < (fa->light_s + smax)) - theRect->w = (fa->light_s-theRect->l)+smax; - if ((theRect->h + theRect->t) < (fa->light_t + tmax)) - theRect->h = (fa->light_t-theRect->t)+tmax; - - - base = lightmap[fa->lightmaptexturenum]->lightmaps; - base += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; - luxbase = lightmap[fa->lightmaptexturenum]->deluxmaps; - luxbase += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; - stainbase = lightmap[fa->lightmaptexturenum]->stainmaps; - stainbase += (fa->light_t * LMBLOCK_WIDTH + fa->light_s) * 3; - D3D9R_BuildLightMap (fa, base, luxbase, stainbase, shift); - - RSpeedEnd(RSPEED_DYNAMIC); - } -} - - - -LPDIRECT3DTEXTURE9 D3D9_NewLightmap(void) -{ - LPDIRECT3DTEXTURE9 newsurf; - IDirect3DDevice9_CreateTexture(pD3DDev9, LMBLOCK_WIDTH, LMBLOCK_WIDTH, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &newsurf, NULL); - - if (!newsurf) - return NULL; - - return newsurf; -} - -void D3D9_BuildLightmaps (void) -{ - D3DLOCKED_RECT desc; - - int i, j; - model_t *m; - int shift; - - r_framecount = 1; // no dlightcache -/* - for (i = 0; i < numlightmaps; i++) - { - if (!lightmap[i]) - break; - BZ_Free(lightmap[i]); - lightmap[i] = NULL; - } - - if (cl.worldmodel->fromgame == fg_doom) - return; //no lightmaps. - - if ((cl.worldmodel->engineflags & MDLF_RGBLIGHTING) || cl.worldmodel->deluxdata || r_loadlits.value) - gl_lightmap_format = GL_RGB; - else - gl_lightmap_format = GL_LUMINANCE; - - - if (cl.worldmodel->fromgame == fg_quake3 && gl_lightmap_format != GL_RGB && gl_lightmap_format != GL_RGBA) - gl_lightmap_format = GL_RGB; - - - switch (gl_lightmap_format) - { - case GL_RGBA: - lightmap_bytes = 4; - break; - case GL_RGB: - lightmap_bytes = 3; - break; - case GL_LUMINANCE: - case GL_INTENSITY: - case GL_ALPHA: - lightmap_bytes = 1; - break; - } -*/ - for (j=1 ; jname[0] == '*') - continue; - - r_pcurrentvertbase = m->vertexes; - currentmodel = m; - shift = 0;//GLR_LightmapShift(currentmodel); - - for (i=0 ; inumsurfaces ; i++) - { - D3D9_CreateSurfaceLightmap (m->surfaces + i, shift); - P_EmitSkyEffectTris(m, &m->surfaces[i]); - if (m->surfaces[i].mesh) //there are some surfaces that have a display list already (the subdivided ones) - continue; - D3D9_BuildSurfaceDisplayList (m->surfaces + i); - } - } - - // - // upload all lightmaps that were filled - // - for (i=0 ; imodified = false; - lightmap[i]->rectchange.l = LMBLOCK_WIDTH; - lightmap[i]->rectchange.t = LMBLOCK_HEIGHT; - lightmap[i]->rectchange.w = 0; - lightmap[i]->rectchange.h = 0; - - if (!lightmap_d3d9textures[i]) - { - lightmap_d3d9textures[i] = D3D9_NewLightmap(); - - if (!lightmap_d3d9textures[i]) - { - Con_Printf("Couldn't create new lightmap\n"); - return; - } - } - - IDirect3DTexture9_LockRect(lightmap_d3d9textures[i], 0, &desc, NULL, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS); - memcpy(desc.pBits, lightmap[i]->lightmaps, sizeof(lightmap[i]->lightmaps)); - /* memset(desc.lpSurface, 0, sizeof(lightmap[i]->lightmaps)); - { - int i; - unsigned char *c; - c = desc.lpSurface; - for (i = 0; i < sizeof(lightmap[i]->lightmaps); i++) - *c++ = rand(); - }*/ - IDirect3DTexture9_UnlockRect(lightmap_d3d9textures[i], 0); - - if (deluxmap_d3d9textures[i]) - { - IDirect3DTexture9_LockRect(deluxmap_d3d9textures[i], 0, &desc, NULL, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS); - memcpy(desc.pBits, lightmap[i]->lightmaps, sizeof(lightmap[i]->deluxmaps)); - IDirect3DTexture9_UnlockRect(deluxmap_d3d9textures[i], 0); - } - } - -} - - - - - - -void D3D9_DrawSkyMesh(int pass, int texture, void *verts, int numverts, void *indicies, int numelements) -{ - if (pass == 0) - { - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, FALSE ); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, (LPDIRECT3DBASETEXTURE9)texture); - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, numverts, numelements, indicies, D3DFMT_QINDEX, verts, 20); - } - - if (pass == 1) - { - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, TRUE); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_CURRENT); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, (LPDIRECT3DBASETEXTURE9)texture); - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, numverts, numelements, indicies, D3DFMT_QINDEX, verts, 20); - - - - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, FALSE); - } -} - -#endif +#include "quakedef.h" +#ifdef D3DQUAKE +#include "winquake.h" +#include "d3d9quake.h" + +int numlightmaps; + +mvertex_t *r_pcurrentvertbase; + +#define LMBLOCK_WIDTH 128 +#define LMBLOCK_HEIGHT LMBLOCK_WIDTH + +LPDIRECT3DTEXTURE9 *lightmap_d3d9textures; +LPDIRECT3DTEXTURE9 *deluxmap_d3d9textures; +lightmapinfo_t **lightmap; + + + +void D3D9_BuildSurfaceDisplayList (msurface_t *fa) +{ + int i, lindex, lnumverts; + medge_t *pedges, *r_pedge; + int vertpage; + float *vec; + float s, t; + int lm; + + int size; + mesh_t *mesh; + +// reconstruct the polygon + pedges = currentmodel->edges; + lnumverts = fa->numedges; + vertpage = 0; + + + if (lnumverts<3) + return; //q3 map. + + size = sizeof(mesh_t) + sizeof(index_t)*(lnumverts-2)*3 + (sizeof(vec3_t) + sizeof(vec3_t) + 2*sizeof(vec2_t) + sizeof(byte_vec4_t))*lnumverts; + + fa->mesh = mesh = Hunk_Alloc(size); + mesh->xyz_array = (vec3_t*)(mesh + 1); + mesh->normals_array = (vec3_t*)(mesh->xyz_array + lnumverts); + mesh->st_array = (vec2_t*)(mesh->normals_array + lnumverts); + mesh->lmst_array = (vec2_t*)(mesh->st_array + lnumverts); + mesh->colors_array = (byte_vec4_t*)(mesh->lmst_array + lnumverts); + mesh->indexes = (index_t*)(mesh->colors_array + lnumverts); + + mesh->numindexes = (lnumverts-2)*3; + mesh->numvertexes = lnumverts; + mesh->patchWidth = mesh->patchHeight = 1; + + for (i=0 ; iindexes[i*3] = 0; + mesh->indexes[i*3+1] = i+1; + mesh->indexes[i*3+2] = i+2; + } + + for (i=0 ; isurfedges[fa->firstedge + i]; + + if (lindex > 0) + { + r_pedge = &pedges[lindex]; + vec = r_pcurrentvertbase[r_pedge->v[0]].position; + } + else + { + r_pedge = &pedges[-lindex]; + vec = r_pcurrentvertbase[r_pedge->v[1]].position; + } + + s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3]; + t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3]; + + VectorCopy (vec, mesh->xyz_array[i]); + mesh->xyz_array[i][3] = 1; + mesh->st_array[i][0] = s/fa->texinfo->texture->width; + mesh->st_array[i][1] = t/fa->texinfo->texture->height; + + s -= fa->texturemins[0]; + lm = s*fa->light_t; + s += fa->light_s*16; + s += 8; + s /= LMBLOCK_WIDTH*16; + + t -= fa->texturemins[1]; + lm += t; + t += fa->light_t*16; + t += 8; + t /= LMBLOCK_HEIGHT*16; + + mesh->lmst_array[i][0] = s; + mesh->lmst_array[i][1] = t; + + if (fa->flags & SURF_PLANEBACK) + VectorNegate(fa->plane->normal, mesh->normals_array[i]); + else + VectorCopy(fa->plane->normal, mesh->normals_array[i]); + + mesh->colors_array[i][0] = 255; + mesh->colors_array[i][1] = 255; + mesh->colors_array[i][2] = 255; + mesh->colors_array[i][3] = 255; + } +} + + + + + + + +#define MAX_LIGHTMAP_SIZE LMBLOCK_WIDTH + +vec3_t blocknormals[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; +unsigned blocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; + +unsigned greenblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; +unsigned blueblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; + +void D3D9R_BuildLightMap (msurface_t *surf, qbyte *dest, qbyte *deluxdest, stmap *stainsrc, int shift) +{ + int smax, tmax; + int t; + int i, j, size; + qbyte *lightmap; + unsigned scale; + int maps; + unsigned *bl; + qboolean isstained; + extern cvar_t r_ambient; + extern cvar_t gl_lightmap_shift; + + unsigned *blg; + unsigned *blb; + + int r, g, b; + int cr, cg, cb; + + int stride = LMBLOCK_WIDTH*lightmap_bytes; + + shift += 7; // increase to base value + surf->cached_dlight = (surf->dlightframe == r_framecount); + + smax = (surf->extents[0]>>4)+1; + tmax = (surf->extents[1]>>4)+1; + size = smax*tmax; + lightmap = surf->samples; + + if (size > MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE) + { //fixme: fill in? + Con_Printf("Lightmap too large\n"); + return; + } + +// if (currentmodel->deluxdata) +// GLR_BuildDeluxMap(surf, deluxdest); + + + + if (true) + { + // set to full bright if no light data + if (r_fullbright.value>0) //not qw + { + for (i=0 ; idlightframe == r_framecount) +// GLR_AddDynamicLightsColours (surf); + } + goto store; + } + if (!currentmodel->lightdata) + { + for (i=0 ; idlightframe == r_framecount) +// GLR_AddDynamicLightsColours (surf); + goto store; + } + +// clear to no light + t = r_ambient.value*255; + for (i=0 ; ifromgame == fg_quake3) //rgb + { + /* for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; + maps++) //no light styles in q3 apparently. + { + scale = d_lightstylevalue[surf->styles[maps]]; + surf->cached_light[maps] = scale; // 8.8 fraction + surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; + } + */ + for (i = 0; i < tmax; i++) //q3 maps store their light in a block fashion, q1/q2/hl store it in a linear fashion. + { + for (j = 0; j < smax; j++) + { + blocklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3]; + greenblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+1]; + blueblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+2]; + } + } +// memset(blocklights, 255, sizeof(blocklights)); + } + else if (currentmodel->engineflags & MDLF_RGBLIGHTING) //rgb + { + for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; + maps++) + { + scale = d_lightstylevalue[surf->styles[maps]]; + surf->cached_light[maps] = scale; // 8.8 fraction + surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; + + + if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. + { + for (i=0 ; istyles[maps]].colour & 1) + for (i=0 ; istyles[maps]].colour & 2) + for (i=0 ; istyles[maps]].colour & 4) + for (i=0 ; istyles[maps] != 255 ; + maps++) + { + scale = d_lightstylevalue[surf->styles[maps]]; + surf->cached_light[maps] = scale; // 8.8 fraction + surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; + + if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. + { + for (i=0 ; istyles[maps]].colour & 1) + for (i=0 ; istyles[maps]].colour & 2) + for (i=0 ; istyles[maps]].colour & 4) + for (i=0 ; idlightframe == r_framecount) +// GLR_AddDynamicLightsColours (surf); + } + else + { + // set to full bright if no light data + if (r_fullbright.value || !currentmodel->lightdata) + { + for (i=0 ; iengineflags & MDLF_RGBLIGHTING) //rgb + for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; + maps++) + { + scale = d_lightstylevalue[surf->styles[maps]]/3; + surf->cached_light[maps] = scale; // 8.8 fraction + surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; + for (i=0 ; istyles[maps] != 255 ; + maps++) + { + scale = d_lightstylevalue[surf->styles[maps]]; + surf->cached_light[maps] = scale; // 8.8 fraction + surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; + for (i=0 ; idlightframe == r_framecount) +// GLR_AddDynamicLights (surf); + } + +// bound, invert, and shift +store: +#define INVERTLIGHTMAPS +#ifdef INVERTLIGHTMAPS + switch (lightmap_bytes) + { + case 4: + stride -= (smax<<2); + bl = blocklights; + blg = greenblklights; + blb = blueblklights; + +// if (!r_stains.value) + isstained = false; +// else +// isstained = surf->stained; + +/* if (!gl_lightcomponantreduction.value) + { + for (i=0 ; i>= 7; + if (t > 255) + dest[0] = 0; + else if (t < 0) + dest[0] = 256; + else + dest[0] = (255-t); + + t = *blg++; + t >>= 7; + if (t > 255) + dest[1] = 0; + else if (t < 0) + dest[1] = 256; + else + dest[1] = (255-t); + + t = *blb++; + t >>= 7; + if (t > 255) + dest[2] = 0; + else if (t < 0) + dest[2] = 256; + else + dest[2] = (255-t); + + dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; + dest += 4; + } + } + } + else +*/ { + stmap *stain; + for (i=0 ; i>= shift; + g >>= shift; + b >>= shift; + + if (isstained) // merge in stain + { + r = (127+r*(*stain++)) >> 8; + g = (127+g*(*stain++)) >> 8; + b = (127+b*(*stain++)) >> 8; + } + + cr = 0; + cg = 0; + cb = 0; + + if (r > 255) //ak too much red + { + cr -= (255-r)/2; + cg += (255-r)/4; //reduce it, and indicate to drop the others too. + cb += (255-r)/4; + r = 255; + } +// else if (r < 0) +// r = 0; + + if (g > 255) + { + cr += (255-g)/4; + cg -= (255-g)/2; + cb += (255-g)/4; + g = 255; + } +// else if (g < 0) +// g = 0; + + if (b > 255) + { + cr += (255-b)/4; + cg += (255-b)/4; + cb -= (255-b)/2; + b = 255; + } +// else if (b < 0) +// b = 0; + /* + if ((r+cr) > 255) + dest[2] = 0; //inverse lighting + else if ((r+cr) < 0) + dest[2] = 255; + else + dest[2] = 255-(r+cr); + + if ((g+cg) > 255) + dest[1] = 0; + else if ((g+cg) < 0) + dest[1] = 255; + else + dest[1] = 255-(g+cg); + + if ((b+cb) > 255) + dest[0] = 0; + else if ((b+cb) < 0) + dest[0] = 255; + else + dest[0] = 255-(b+cb); +/*/ + if ((r+cr) > 255) + dest[2] = 255; //non-inverse lighting + else if ((r+cr) < 0) + dest[2] = 0; + else + dest[2] = (r+cr); + + if ((g+cg) > 255) + dest[1] = 255; + else if ((g+cg) < 0) + dest[1] = 0; + else + dest[1] = (g+cg); + + if ((b+cb) > 255) + dest[0] = 255; + else if ((b+cb) < 0) + dest[0] = 0; + else + dest[0] = (b+cb); +//*/ + + + + dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! + dest += 4; + } + } + } + break; + + case 3: + stride -= smax*3; + bl = blocklights; + blg = greenblklights; + blb = blueblklights; + +// if (!r_stains.value) + isstained = false; +// else +// isstained = surf->stained; + +/* if (!gl_lightcomponantreduction.value) + { + for (i=0 ; i>= 7; + if (t > 255) + dest[0] = 0; + else if (t < 0) + dest[0] = 256; + else + dest[0] = (255-t); + + t = *blg++; + t >>= 7; + if (t > 255) + dest[1] = 0; + else if (t < 0) + dest[1] = 256; + else + dest[1] = (255-t); + + t = *blb++; + t >>= 7; + if (t > 255) + dest[2] = 0; + else if (t < 0) + dest[2] = 256; + else + dest[2] = (255-t); + + dest += 3; + } + } + } + else +*/ { + stmap *stain; + for (i=0 ; i>= shift; + g >>= shift; + b >>= shift; + + if (isstained) // merge in stain + { + r = (127+r*(*stain++)) >> 8; + g = (127+g*(*stain++)) >> 8; + b = (127+b*(*stain++)) >> 8; + } + + cr = 0; + cg = 0; + cb = 0; + + if (r > 255) //ak too much red + { + cr -= (255-r)/2; + cg += (255-r)/4; //reduce it, and indicate to drop the others too. + cb += (255-r)/4; + r = 255; + } +// else if (r < 0) +// r = 0; + + if (g > 255) + { + cr += (255-g)/4; + cg -= (255-g)/2; + cb += (255-g)/4; + g = 255; + } +// else if (g < 0) +// g = 0; + + if (b > 255) + { + cr += (255-b)/4; + cg += (255-b)/4; + cb -= (255-b)/2; + b = 255; + } +// else if (b < 0) +// b = 0; + /* + if ((r+cr) > 255) + dest[2] = 0; //inverse lighting + else if ((r+cr) < 0) + dest[2] = 255; + else + dest[2] = 255-(r+cr); + + if ((g+cg) > 255) + dest[1] = 0; + else if ((g+cg) < 0) + dest[1] = 255; + else + dest[1] = 255-(g+cg); + + if ((b+cb) > 255) + dest[0] = 0; + else if ((b+cb) < 0) + dest[0] = 255; + else + dest[0] = 255-(b+cb); +/*/ + if ((r+cr) > 255) + dest[2] = 255; //non-inverse lighting + else if ((r+cr) < 0) + dest[2] = 0; + else + dest[2] = (r+cr); + + if ((g+cg) > 255) + dest[1] = 255; + else if ((g+cg) < 0) + dest[1] = 0; + else + dest[1] = (g+cg); + + if ((b+cb) > 255) + dest[0] = 255; + else if ((b+cb) < 0) + dest[0] = 0; + else + dest[0] = (b+cb); +// */ + dest += 3; + } + } + } + break; + default: + Sys_Error ("Bad lightmap format"); + } +#else + switch (lightmap_bytes) + { + case 4: + stride -= (smax<<2); + bl = blocklights; + blg = greenblklights; + blb = blueblklights; + +// if (!r_stains.value) + isstained = false; +// else +// isstained = surf->stained; + +/* if (!gl_lightcomponantreduction.value) + { + for (i=0 ; i>= 7; + if (t > 255) + dest[0] = 0; + else if (t < 0) + dest[0] = 256; + else + dest[0] = (255-t); + + t = *blg++; + t >>= 7; + if (t > 255) + dest[1] = 0; + else if (t < 0) + dest[1] = 256; + else + dest[1] = (255-t); + + t = *blb++; + t >>= 7; + if (t > 255) + dest[2] = 0; + else if (t < 0) + dest[2] = 256; + else + dest[2] = (255-t); + + dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; + dest += 4; + } + } + } + else +*/ { + stmap *stain; + for (i=0 ; i>= shift; + g >>= shift; + b >>= shift; + + if (isstained) // merge in stain + { + r = (127+r*(*stain++)) >> 8; + g = (127+g*(*stain++)) >> 8; + b = (127+b*(*stain++)) >> 8; + } + + cr = 0; + cg = 0; + cb = 0; + + if (r > 255) //ak too much red + { + cr -= (255-r)/2; + cg += (255-r)/4; //reduce it, and indicate to drop the others too. + cb += (255-r)/4; + r = 255; + } +// else if (r < 0) +// r = 0; + + if (g > 255) + { + cr += (255-g)/4; + cg -= (255-g)/2; + cb += (255-g)/4; + g = 255; + } +// else if (g < 0) +// g = 0; + + if (b > 255) + { + cr += (255-b)/4; + cg += (255-b)/4; + cb -= (255-b)/2; + b = 255; + } +// else if (b < 0) +// b = 0; + //* + if ((r+cr) > 255) + dest[2] = 0; //inverse lighting + else if ((r+cr) < 0) + dest[2] = 255; + else + dest[2] = 255-(r+cr); + + if ((g+cg) > 255) + dest[1] = 0; + else if ((g+cg) < 0) + dest[1] = 255; + else + dest[1] = 255-(g+cg); + + if ((b+cb) > 255) + dest[0] = 0; + else if ((b+cb) < 0) + dest[0] = 255; + else + dest[0] = 255-(b+cb); +/*/ + if ((r+cr) > 255) + dest[0] = 255; //non-inverse lighting + else if ((r+cr) < 0) + dest[0] = 0; + else + dest[0] = (r+cr); + + if ((g+cg) > 255) + dest[1] = 255; + else if ((g+cg) < 0) + dest[1] = 0; + else + dest[1] = (g+cg); + + if ((b+cb) > 255) + dest[2] = 255; + else if ((b+cb) < 0) + dest[2] = 0; + else + dest[2] = (b+cb); +*/ + + + + dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! + dest += 4; + } + } + } + break; + + case 3: + stride -= smax*3; + bl = blocklights; + blg = greenblklights; + blb = blueblklights; + +// if (!r_stains.value) + isstained = false; +// else +// isstained = surf->stained; + +/* if (!gl_lightcomponantreduction.value) + { + for (i=0 ; i>= 7; + if (t > 255) + dest[0] = 255; + else if (t < 0) + dest[0] = 0; + else + dest[0] = t; + + t = *blg++; + t >>= 7; + if (t > 255) + dest[1] = 255; + else if (t < 0) + dest[1] = 0; + else + dest[1] = t; + + t = *blb++; + t >>= 7; + if (t > 255) + dest[2] = 255; + else if (t < 0) + dest[2] = 0; + else + dest[2] = t; + + dest += 3; + } + } + } + else +*/ { + stmap *stain; + for (i=0 ; i>= shift; + g >>= shift; + b >>= shift; + + if (isstained) // merge in stain + { + r = (127+r*(*stain++)) >> 8; + g = (127+g*(*stain++)) >> 8; + b = (127+b*(*stain++)) >> 8; + } + + cr = 0; + cg = 0; + cb = 0; + + if (r > 255) //ak too much red + { + cr -= (255-r)/2; + cg += (255-r)/4; //reduce it, and indicate to drop the others too. + cb += (255-r)/4; + r = 255; + } +// else if (r < 0) +// r = 0; + + if (g > 255) + { + cr += (255-g)/4; + cg -= (255-g)/2; + cb += (255-g)/4; + g = 255; + } +// else if (g < 0) +// g = 0; + + if (b > 255) + { + cr += (255-b)/4; + cg += (255-b)/4; + cb -= (255-b)/2; + b = 255; + } +// else if (b < 0) +// b = 0; + //* + if ((r+cr) > 255) + dest[2] = 255; //inverse lighting + else if ((r+cr) < 0) + dest[2] = 0; + else + dest[2] = (r+cr); + + if ((g+cg) > 255) + dest[1] = 255; + else if ((g+cg) < 0) + dest[1] = 0; + else + dest[1] = (g+cg); + + if ((b+cb) > 255) + dest[0] = 255; + else if ((b+cb) < 0) + dest[0] = 0; + else + dest[0] = (b+cb); +/*/ + if ((r+cr) > 255) + dest[0] = 255; //non-inverse lighting + else if ((r+cr) < 0) + dest[0] = 0; + else + dest[0] = (r+cr); + + if ((g+cg) > 255) + dest[1] = 255; + else if ((g+cg) < 0) + dest[1] = 0; + else + dest[1] = (g+cg); + + if ((b+cb) > 255) + dest[2] = 255; + else if ((b+cb) < 0) + dest[2] = 0; + else + dest[2] = (b+cb); +// */ + dest += 3; + } + } + } + break; + default: + Sys_Error ("Bad lightmap format"); + } +#endif +} + + + +int D3D9_FillBlock (int texnum, int w, int h, int x, int y) +{ + int i, l; + while (texnum >= numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. + { + lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); + lightmap_d3d9textures = BZ_Realloc(lightmap_d3d9textures, sizeof(*lightmap_d3d9textures)*(numlightmaps+4)); +// lightmap_textures[numlightmaps+0] = texture_extension_number++; +// lightmap_textures[numlightmaps+1] = texture_extension_number++; +// lightmap_textures[numlightmaps+2] = texture_extension_number++; +// lightmap_textures[numlightmaps+3] = texture_extension_number++; + + deluxmap_d3d9textures = BZ_Realloc(deluxmap_d3d9textures, sizeof(*deluxmap_d3d9textures)*(numlightmaps+4)); +// deluxmap_textures[numlightmaps+0] = texture_extension_number++; +// deluxmap_textures[numlightmaps+1] = texture_extension_number++; +// deluxmap_textures[numlightmaps+2] = texture_extension_number++; +// deluxmap_textures[numlightmaps+3] = texture_extension_number++; + numlightmaps+=4; + } + for (i = texnum; i >= 0; i--) + { + if (!lightmap[i]) + { + lightmap[i] = BZ_Malloc(sizeof(*lightmap[i])); + for (l=0 ; lallocated[l] = LMBLOCK_HEIGHT; + } + + //maybe someone screwed with my lightmap... + memset(lightmap[i]->lightmaps, 255, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); +// if (cl.worldmodel->lightdata) +// memcpy(lightmap[i]->lightmaps, cl.worldmodel->lightdata+3*LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*i, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); + + } + else + break; + } + return texnum; +} + +int D3D9_AllocBlock (int w, int h, int *x, int *y) +{ + int i, j; + int best, best2; + int texnum; + + for (texnum=0 ; ; texnum++) + { + if (texnum == numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. + { + lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); + lightmap_d3d9textures = BZ_Realloc(lightmap_d3d9textures, sizeof(*lightmap_d3d9textures)*(numlightmaps+4)); +// lightmap_textures[numlightmaps+0] = texture_extension_number++; +// lightmap_textures[numlightmaps+1] = texture_extension_number++; +// lightmap_textures[numlightmaps+2] = texture_extension_number++; +// lightmap_textures[numlightmaps+3] = texture_extension_number++; + + deluxmap_d3d9textures = BZ_Realloc(deluxmap_d3d9textures, sizeof(*deluxmap_d3d9textures)*(numlightmaps+4)); +// deluxmap_textures[numlightmaps+0] = texture_extension_number++; +// deluxmap_textures[numlightmaps+1] = texture_extension_number++; +// deluxmap_textures[numlightmaps+2] = texture_extension_number++; +// deluxmap_textures[numlightmaps+3] = texture_extension_number++; + numlightmaps+=4; + } + if (!lightmap[texnum]) + { + lightmap[texnum] = Z_Malloc(sizeof(*lightmap[texnum])); + // reset stainmap since it now starts at 255 + memset(lightmap[texnum]->stainmaps, 255, sizeof(lightmap[texnum]->stainmaps)); + } + + + best = LMBLOCK_HEIGHT; + + for (i=0 ; iallocated[i+j] >= best) + break; + if (lightmap[texnum]->allocated[i+j] > best2) + best2 = lightmap[texnum]->allocated[i+j]; + } + if (j == w) + { // this is a valid spot + *x = i; + *y = best = best2; + } + } + + if (best + h > LMBLOCK_HEIGHT) + continue; + + for (i=0 ; iallocated[*x + i] = best + h; + + return texnum; + } + + Sys_Error ("AllocBlock: full"); + return 0; +} + + +void D3D9_CreateSurfaceLightmap (msurface_t *surf, int shift) +{ + int smax, tmax; + qbyte *base, *luxbase; stmap *stainbase; + + if (surf->flags & (SURF_DRAWSKY|SURF_DRAWTURB)) + surf->lightmaptexturenum = -1; + if (surf->texinfo->flags & TEX_SPECIAL) + surf->lightmaptexturenum = -1; + if (surf->lightmaptexturenum<0) + return; + + smax = (surf->extents[0]>>4)+1; + tmax = (surf->extents[1]>>4)+1; + + if (smax > LMBLOCK_WIDTH || tmax > LMBLOCK_HEIGHT || smax < 0 || tmax < 0) + { //whoa, buggy. + surf->lightmaptexturenum = -1; + return; + } + + if (currentmodel->fromgame == fg_quake3) + D3D9_FillBlock(surf->lightmaptexturenum, smax, tmax, surf->light_s, surf->light_t); + else + surf->lightmaptexturenum = D3D9_AllocBlock (smax, tmax, &surf->light_s, &surf->light_t); + base = lightmap[surf->lightmaptexturenum]->lightmaps; + base += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; + + luxbase = lightmap[surf->lightmaptexturenum]->deluxmaps; + luxbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; + + stainbase = lightmap[surf->lightmaptexturenum]->stainmaps; + stainbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * 3; + + D3D9R_BuildLightMap (surf, base, luxbase, stainbase, shift); +} + + +void D3D9R_RenderDynamicLightmaps (msurface_t *fa, int shift) +{ + qbyte *base, *luxbase; + stmap *stainbase; + int maps; + glRect_t *theRect; + int smax, tmax; + + if (!fa->mesh) + return; + +// c_brush_polys++; + + if (fa->lightmaptexturenum<0) + return; + + if (fa->flags & ( SURF_DRAWSKY | SURF_DRAWTURB) ) + return; + + if (fa->texinfo->flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP)) + return; + + if (fa->texinfo->flags & (TEX_SPECIAL)) + { + if (cl.worldmodel->fromgame == fg_halflife) + return; //some textures do this. + } + +// fa->polys->chain = lightmap[fa->lightmaptexturenum]->polys; +// lightmap[fa->lightmaptexturenum]->polys = fa->polys; + + // check for lightmap modification +// if (cl.worldmodel->fromgame != fg_quake3) //no lightstyles on q3 maps + { + for (maps = 0 ; maps < MAXLIGHTMAPS && fa->styles[maps] != 255 ; + maps++) + if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps] + #ifdef PEXT_LIGHTSTYLECOL + || cl_lightstyle[fa->styles[maps]].colour != fa->cached_colour[maps] + #endif + ) + { + goto dynamic; + } + } + + if (fa->dlightframe == r_framecount // dynamic this frame + || fa->cached_dlight) // dynamic previously + { + RSpeedLocals(); +dynamic: + RSpeedRemark(); + + lightmap[fa->lightmaptexturenum]->modified = true; + + smax = (fa->extents[0]>>4)+1; + tmax = (fa->extents[1]>>4)+1; + + theRect = &lightmap[fa->lightmaptexturenum]->rectchange; + if (fa->light_t < theRect->t) { + if (theRect->h) + theRect->h += theRect->t - fa->light_t; + theRect->t = fa->light_t; + } + if (fa->light_s < theRect->l) { + if (theRect->w) + theRect->w += theRect->l - fa->light_s; + theRect->l = fa->light_s; + } + if ((theRect->w + theRect->l) < (fa->light_s + smax)) + theRect->w = (fa->light_s-theRect->l)+smax; + if ((theRect->h + theRect->t) < (fa->light_t + tmax)) + theRect->h = (fa->light_t-theRect->t)+tmax; + + lightmap[fa->lightmaptexturenum]->deluxmodified = true; + theRect = &lightmap[fa->lightmaptexturenum]->deluxrectchange; + if (fa->light_t < theRect->t) { + if (theRect->h) + theRect->h += theRect->t - fa->light_t; + theRect->t = fa->light_t; + } + if (fa->light_s < theRect->l) { + if (theRect->w) + theRect->w += theRect->l - fa->light_s; + theRect->l = fa->light_s; + } + + if ((theRect->w + theRect->l) < (fa->light_s + smax)) + theRect->w = (fa->light_s-theRect->l)+smax; + if ((theRect->h + theRect->t) < (fa->light_t + tmax)) + theRect->h = (fa->light_t-theRect->t)+tmax; + + + base = lightmap[fa->lightmaptexturenum]->lightmaps; + base += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; + luxbase = lightmap[fa->lightmaptexturenum]->deluxmaps; + luxbase += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; + stainbase = lightmap[fa->lightmaptexturenum]->stainmaps; + stainbase += (fa->light_t * LMBLOCK_WIDTH + fa->light_s) * 3; + D3D9R_BuildLightMap (fa, base, luxbase, stainbase, shift); + + RSpeedEnd(RSPEED_DYNAMIC); + } +} + + + +LPDIRECT3DTEXTURE9 D3D9_NewLightmap(void) +{ + LPDIRECT3DTEXTURE9 newsurf; + IDirect3DDevice9_CreateTexture(pD3DDev9, LMBLOCK_WIDTH, LMBLOCK_WIDTH, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &newsurf, NULL); + + if (!newsurf) + return NULL; + + return newsurf; +} + +void D3D9_BuildLightmaps (void) +{ + D3DLOCKED_RECT desc; + + int i, j; + model_t *m; + int shift; + + r_framecount = 1; // no dlightcache +/* + for (i = 0; i < numlightmaps; i++) + { + if (!lightmap[i]) + break; + BZ_Free(lightmap[i]); + lightmap[i] = NULL; + } + + if (cl.worldmodel->fromgame == fg_doom) + return; //no lightmaps. + + if ((cl.worldmodel->engineflags & MDLF_RGBLIGHTING) || cl.worldmodel->deluxdata || r_loadlits.value) + gl_lightmap_format = GL_RGB; + else + gl_lightmap_format = GL_LUMINANCE; + + + if (cl.worldmodel->fromgame == fg_quake3 && gl_lightmap_format != GL_RGB && gl_lightmap_format != GL_RGBA) + gl_lightmap_format = GL_RGB; + + + switch (gl_lightmap_format) + { + case GL_RGBA: + lightmap_bytes = 4; + break; + case GL_RGB: + lightmap_bytes = 3; + break; + case GL_LUMINANCE: + case GL_INTENSITY: + case GL_ALPHA: + lightmap_bytes = 1; + break; + } +*/ + for (j=1 ; jname[0] == '*') + continue; + + r_pcurrentvertbase = m->vertexes; + currentmodel = m; + shift = 0;//GLR_LightmapShift(currentmodel); + + for (i=0 ; inumsurfaces ; i++) + { + D3D9_CreateSurfaceLightmap (m->surfaces + i, shift); + P_EmitSkyEffectTris(m, &m->surfaces[i]); + if (m->surfaces[i].mesh) //there are some surfaces that have a display list already (the subdivided ones) + continue; + D3D9_BuildSurfaceDisplayList (m->surfaces + i); + } + } + + // + // upload all lightmaps that were filled + // + for (i=0 ; imodified = false; + lightmap[i]->rectchange.l = LMBLOCK_WIDTH; + lightmap[i]->rectchange.t = LMBLOCK_HEIGHT; + lightmap[i]->rectchange.w = 0; + lightmap[i]->rectchange.h = 0; + + if (!lightmap_d3d9textures[i]) + { + lightmap_d3d9textures[i] = D3D9_NewLightmap(); + + if (!lightmap_d3d9textures[i]) + { + Con_Printf("Couldn't create new lightmap\n"); + return; + } + } + + IDirect3DTexture9_LockRect(lightmap_d3d9textures[i], 0, &desc, NULL, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS); + memcpy(desc.pBits, lightmap[i]->lightmaps, sizeof(lightmap[i]->lightmaps)); + /* memset(desc.lpSurface, 0, sizeof(lightmap[i]->lightmaps)); + { + int i; + unsigned char *c; + c = desc.lpSurface; + for (i = 0; i < sizeof(lightmap[i]->lightmaps); i++) + *c++ = rand(); + }*/ + IDirect3DTexture9_UnlockRect(lightmap_d3d9textures[i], 0); + + if (deluxmap_d3d9textures[i]) + { + IDirect3DTexture9_LockRect(deluxmap_d3d9textures[i], 0, &desc, NULL, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS); + memcpy(desc.pBits, lightmap[i]->lightmaps, sizeof(lightmap[i]->deluxmaps)); + IDirect3DTexture9_UnlockRect(deluxmap_d3d9textures[i], 0); + } + } + +} + + + + + + +void D3D9_DrawSkyMesh(int pass, int texture, void *verts, int numverts, void *indicies, int numelements) +{ + if (pass == 0) + { + IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, FALSE ); + + IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); + IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); + + IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); + + IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); + IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); + + IDirect3DDevice9_SetTexture(pD3DDev9, 0, (LPDIRECT3DBASETEXTURE9)texture); + IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_TEX1); + IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, numverts, numelements, indicies, D3DFMT_QINDEX, verts, 20); + } + + if (pass == 1) + { + IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, TRUE); + + IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); + IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_CURRENT); + IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); + + IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); + + IDirect3DDevice9_SetTexture(pD3DDev9, 0, (LPDIRECT3DBASETEXTURE9)texture); + IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_TEX1); + IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, numverts, numelements, indicies, D3DFMT_QINDEX, verts, 20); + + + + + IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, FALSE); + } +} + +#endif diff --git a/engine/gl/gl_alias.c b/engine/gl/gl_alias.c index 2ef2e3268..7ed59a9ef 100644 --- a/engine/gl/gl_alias.c +++ b/engine/gl/gl_alias.c @@ -139,7 +139,7 @@ typedef struct { //frame is an index into this typedef struct { #ifdef SKELETALMODELS - qboolean isheirachical; //for models with transforms, states that bones need to be transformed from thier parent. + qboolean isheirachical; //for models with transforms, states that bones need to be transformed from their parent. //this is actually bad, and can result in bones shortening as they interpolate. #endif qboolean loop; diff --git a/engine/gl/gl_rsurf.c b/engine/gl/gl_rsurf.c index 8253bee36..41ec64744 100644 --- a/engine/gl/gl_rsurf.c +++ b/engine/gl/gl_rsurf.c @@ -826,7 +826,7 @@ void GLR_BuildLightMap (msurface_t *surf, qbyte *dest, qbyte *deluxdest, stmap * surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; } */ - for (i = 0; i < tmax; i++) //q3 maps store thier light in a block fashion, q1/q2/hl store it in a linear fashion. + for (i = 0; i < tmax; i++) //q3 maps store their light in a block fashion, q1/q2/hl store it in a linear fashion. { for (j = 0; j < smax; j++) { @@ -3219,7 +3219,7 @@ int GLAllocBlock (int w, int h, int *x, int *y) return 0; } -//quake3 maps have thier lightmaps in gl style already. +//quake3 maps have their lightmaps in gl style already. //rather than forgetting that and redoing it, let's just keep the data. int GLFillBlock (int texnum, int w, int h, int x, int y) { diff --git a/engine/qclib/pr_edict.c b/engine/qclib/pr_edict.c index f5ed7d415..7186a5827 100644 --- a/engine/qclib/pr_edict.c +++ b/engine/qclib/pr_edict.c @@ -2673,9 +2673,9 @@ retry: else type = fld16[i].type & ~(DEF_SHARED|DEF_SAVEGLOBAL); - if (progfuncs->fieldadjust && !pr_typecurrent) //we need to make sure all fields appear in thier original place. + if (progfuncs->fieldadjust && !pr_typecurrent) //we need to make sure all fields appear in their original place. QC_RegisterFieldVar(progfuncs, type, fld16[i].s_name+pr_strings, 4*(fld16[i].ofs+progfuncs->fieldadjust), -1); - else if (type == ev_vector) //emit vector vars early, so thier fields cannot be alocated before the vector itself. (useful against scramblers) + else if (type == ev_vector) //emit vector vars early, so their fields cannot be alocated before the vector itself. (useful against scramblers) { QC_RegisterFieldVar(progfuncs, type, fld16[i].s_name+pr_strings, -1, fld16[i].ofs); } @@ -2742,7 +2742,7 @@ retry: type = pr_types[pr_fielddefs32[i].type & ~(DEF_SHARED|DEF_SAVEGLOBAL)].type; else type = pr_fielddefs32[i].type & ~(DEF_SHARED|DEF_SAVEGLOBAL); - if (progfuncs->fieldadjust && !pr_typecurrent) //we need to make sure all fields appear in thier original place. + if (progfuncs->fieldadjust && !pr_typecurrent) //we need to make sure all fields appear in their original place. QC_RegisterFieldVar(progfuncs, type, fld16[i].s_name+pr_strings, 4*(fld16[i].ofs+progfuncs->fieldadjust), -1); else if (type == ev_vector) QC_RegisterFieldVar(progfuncs, type, pr_fielddefs32[i].s_name+pr_strings, -1, pr_fielddefs32[i].ofs); diff --git a/engine/qclib/pr_multi.c b/engine/qclib/pr_multi.c index 5e803c97f..88d04a66c 100644 --- a/engine/qclib/pr_multi.c +++ b/engine/qclib/pr_multi.c @@ -193,7 +193,7 @@ void QC_FlushProgsOffsets(progfuncs_t *progfuncs) //called if a global is defined as a field //returns offset. -//vectors must be added before any of thier corresponding _x/y/z vars +//vectors must be added before any of their corresponding _x/y/z vars //in this way, even screwed up progs work. //requestedpos is the offset the engine WILL put it at. diff --git a/engine/qclib/qcc_pr_comp.c b/engine/qclib/qcc_pr_comp.c index b1a9d54d1..1f2becd2c 100644 --- a/engine/qclib/qcc_pr_comp.c +++ b/engine/qclib/qcc_pr_comp.c @@ -66,7 +66,7 @@ pbool keyword_union; //you surly know what a union is! pbool keywords_coexist; //don't disable a keyword simply because a var was made with the same name. pbool output_parms; //emit some PARMX fields. confuses decompilers. pbool autoprototype; //take two passes over the source code. First time round doesn't enter and functions or initialise variables. -pbool pr_subscopedlocals; //causes locals to be valid ONLY within thier statement block. (they simply can't be referenced by name outside of it) +pbool pr_subscopedlocals; //causes locals to be valid ONLY within their statement block. (they simply can't be referenced by name outside of it) pbool flag_ifstring; //makes if (blah) equivelent to if (blah != "") which resolves some issues in multiprogs situations. pbool flag_acc; //reacc like behaviour of src files (finds *.qc in start dir and compiles all in alphabetical order) pbool flag_caseinsensative; //symbols will be matched to an insensative case if the specified case doesn't exist. This should b usable for any mod @@ -3168,7 +3168,7 @@ void QCC_PR_EmitFieldsForMembers(QCC_type_t *clas) unsigned int o; QCC_type_t *mt, *ft; QCC_def_t *f, *m; - if (clas->parentclass != type_entity) //parents MUST have all thier fields set or inheritance would go crazy. + if (clas->parentclass != type_entity) //parents MUST have all their fields set or inheritance would go crazy. QCC_PR_EmitFieldsForMembers(clas->parentclass); np = clas->num_parms; diff --git a/engine/qclib/qccmain.c b/engine/qclib/qccmain.c index 5017356cf..7017a6e97 100644 --- a/engine/qclib/qccmain.c +++ b/engine/qclib/qccmain.c @@ -502,7 +502,7 @@ int WriteBodylessFuncs (int handle) return ret; } -//marshalled locals remaps all the functions to use the range MAX_REGS onwards for the offset to thier locals. +//marshalled locals remaps all the functions to use the range MAX_REGS onwards for the offset to their locals. //this function remaps all the locals back into the function. void QCC_UnmarshalLocals(void) { diff --git a/engine/server/net_preparse.c b/engine/server/net_preparse.c index 816a6c381..257496953 100644 --- a/engine/server/net_preparse.c +++ b/engine/server/net_preparse.c @@ -23,7 +23,7 @@ static qboolean ignoreprotocol; #define svc_clearviewflags 41 //hexen2. //these are present in the darkplaces engine. -//I wanna knick thier mods. +//I wanna knick their mods. #define svcdp_skybox 37 #define svcdp_showlmp 35 // [string] slotname [string] lmpfilename [short] x [short] y diff --git a/engine/server/pr_cmds.c b/engine/server/pr_cmds.c index 7110b1f0f..af7c4ac6a 100644 --- a/engine/server/pr_cmds.c +++ b/engine/server/pr_cmds.c @@ -6480,7 +6480,7 @@ lh_extension_t FTE_Protocol_Extensions[] = {"FTE_PEXT_BULLETENS"}, //bulleten boards (scrolling text on walls) {"FTE_PEXT_ZLIBDL"}, //supposed download optimisation (unimportant to qc) {"FTE_PEXT_LIGHTUPDATES"}, //zap.mdl is sent as a nail packet. - {"FTE_PEXT_FATNESS"}, //entities may be expanded along thier vertex normals + {"FTE_PEXT_FATNESS"}, //entities may be expanded along their vertex normals {"DP_HALFLIFE_MAP"}, //entitiy can visit a hl bsp {"FTE_PEXT_TE_BULLET"}, //additional particle effect. Like TE_SPIKE and TE_SUPERSPIKE {"FTE_PEXT_HULLSIZE"}, //means we can tell a client to go to crouching hull diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index 06f23f84d..b96669f77 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -2016,7 +2016,7 @@ client_t *SVC_DirectConnect(void) SV_OutOfBandTPrintf (protocol == SCP_QUAKE2, adr, newcl->language, STL_FIRSTGREETING, newcl->name, (int)rs.timeonserver); } - //else loaded players already have thier initial parms set + //else loaded players already have their initial parms set } } #else diff --git a/engine/server/sv_user.c b/engine/server/sv_user.c index 8dc421d1e..0191a7784 100644 --- a/engine/server/sv_user.c +++ b/engine/server/sv_user.c @@ -4510,7 +4510,7 @@ void SV_RunCmd (usercmd_t *ucmd, qboolean recurse) oldmsec = ucmd->msec; cmd.msec = oldmsec/2; SV_RunCmd (&cmd, true); - cmd.msec = oldmsec/2 + (oldmsec&1); //give them back thier msec. + cmd.msec = oldmsec/2 + (oldmsec&1); //give them back their msec. cmd.impulse = 0; SV_RunCmd (&cmd, true); return; diff --git a/engine/sw/vid_sdl.c b/engine/sw/vid_sdl.c index 6efa0ca32..8217af4df 100755 --- a/engine/sw/vid_sdl.c +++ b/engine/sw/vid_sdl.c @@ -45,7 +45,7 @@ qboolean SWVID_Init (rendererstate_t *info, unsigned char *palette) int flags; Con_Printf("SDL SWVID_Init\n"); - info->bpp = 8; //I don't know thier card details I'm afraid. + info->bpp = 8; //I don't know their card details I'm afraid. SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);