From 76f3774756ad46db130ec7c8d67b3845e984c06d Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 6 May 2005 11:28:31 +0000 Subject: [PATCH] moved mod_shared.c detail texture and distortion texture stuff to gl_rmain.c (renamed mod_shared_* to r_texture_*) got rid of unused mod_q1bsp_novis array moved Mod_Q1BSP_Collision_Init into the boxhull code (which isn't even used anyway) made r_restart reload models (as was intended) by making Mod_UnloadModel preserve the ->use field git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5234 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 239 ++++++++++++++++++++++++++++++++++++------------- gl_rsurf.c | 2 +- model_brush.c | 72 +++++++-------- model_shared.c | 120 ++----------------------- model_shared.h | 9 -- render.h | 3 + 6 files changed, 219 insertions(+), 226 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index 40428196..8dc33697 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -115,6 +115,8 @@ rtexture_t *r_texture_black; rtexture_t *r_texture_notexture; rtexture_t *r_texture_whitecube; rtexture_t *r_texture_normalizationcube; +rtexture_t *r_texture_detailtextures[NUM_DETAILTEXTURES]; +rtexture_t *r_texture_distorttexture[64]; void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b) { @@ -214,17 +216,97 @@ void FOG_registercvars(void) } } -void gl_main_start(void) +static void R_BuildDetailTextures (void) { - int x, y, side; - vec3_t v; - vec_t s, t, intensity; - qbyte pix[16][16][4]; -#define NORMSIZE 64 - qbyte data[6*NORMSIZE*NORMSIZE*4]; - r_main_texturepool = R_AllocTexturePool(); - r_bloom_texture_screen = NULL; - r_bloom_texture_bloom = NULL; + int i, x, y, light; + float vc[3], vx[3], vy[3], vn[3], lightdir[3]; +#define DETAILRESOLUTION 256 + qbyte data[DETAILRESOLUTION][DETAILRESOLUTION][4], noise[DETAILRESOLUTION][DETAILRESOLUTION]; + lightdir[0] = 0.5; + lightdir[1] = 1; + lightdir[2] = -0.25; + VectorNormalize(lightdir); + for (i = 0;i < NUM_DETAILTEXTURES;i++) + { + fractalnoise(&noise[0][0], DETAILRESOLUTION, DETAILRESOLUTION >> 4); + for (y = 0;y < DETAILRESOLUTION;y++) + { + for (x = 0;x < DETAILRESOLUTION;x++) + { + vc[0] = x; + vc[1] = y; + vc[2] = noise[y][x] * (1.0f / 32.0f); + vx[0] = x + 1; + vx[1] = y; + vx[2] = noise[y][(x + 1) % DETAILRESOLUTION] * (1.0f / 32.0f); + vy[0] = x; + vy[1] = y + 1; + vy[2] = noise[(y + 1) % DETAILRESOLUTION][x] * (1.0f / 32.0f); + VectorSubtract(vx, vc, vx); + VectorSubtract(vy, vc, vy); + CrossProduct(vx, vy, vn); + VectorNormalize(vn); + light = 128 - DotProduct(vn, lightdir) * 128; + light = bound(0, light, 255); + data[y][x][0] = data[y][x][1] = data[y][x][2] = light; + data[y][x][3] = 255; + } + } + r_texture_detailtextures[i] = R_LoadTexture2D(r_main_texturepool, va("detailtexture%i", i), DETAILRESOLUTION, DETAILRESOLUTION, &data[0][0][0], TEXTYPE_RGBA, TEXF_MIPMAP | TEXF_PRECACHE, NULL); + } +} + +static qbyte R_MorphDistortTexture (double y0, double y1, double y2, double y3, double morph) +{ + int m = (int)(((y1 + y3 - (y0 + y2)) * morph * morph * morph) + + ((2 * (y0 - y1) + y2 - y3) * morph * morph) + + ((y2 - y0) * morph) + + (y1)); + return (qbyte)bound(0, m, 255); +} + +static void R_BuildDistortTexture (void) +{ + int x, y, i, j; +#define DISTORTRESOLUTION 32 + qbyte data[5][DISTORTRESOLUTION][DISTORTRESOLUTION][2]; + + for (i=0; i<4; i++) + { + for (y=0; yskin.base); m.texcombinergb[0] = GL_REPLACE; m.texcombinergb[1] = GL_REPLACE; diff --git a/model_brush.c b/model_brush.c index f0ef9297..fd378a2c 100644 --- a/model_brush.c +++ b/model_brush.c @@ -26,8 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "wad.h" -qbyte mod_q1bsp_novis[(MAX_MAP_LEAFS + 7)/ 8]; - //cvar_t r_subdivide_size = {CVAR_SAVE, "r_subdivide_size", "128"}; cvar_t halflifebsp = {0, "halflifebsp", "0"}; cvar_t r_novis = {0, "r_novis", "0"}; @@ -46,7 +44,6 @@ cvar_t mod_q3bsp_curves_collisions = {0, "mod_q3bsp_curves_collisions", "1"}; cvar_t mod_q3bsp_optimizedtraceline = {0, "mod_q3bsp_optimizedtraceline", "1"}; cvar_t mod_q3bsp_debugtracebrush = {0, "mod_q3bsp_debugtracebrush", "0"}; -static void Mod_Q1BSP_Collision_Init (void); void Mod_BrushInit(void) { // Cvar_RegisterVariable(&r_subdivide_size); @@ -66,8 +63,6 @@ void Mod_BrushInit(void) Cvar_RegisterVariable(&mod_q3bsp_curves_collisions); Cvar_RegisterVariable(&mod_q3bsp_optimizedtraceline); Cvar_RegisterVariable(&mod_q3bsp_debugtracebrush); - memset(mod_q1bsp_novis, 0xff, sizeof(mod_q1bsp_novis)); - Mod_Q1BSP_Collision_Init(); } static mleaf_t *Mod_Q1BSP_PointInLeaf(model_t *model, const vec3_t p) @@ -680,40 +675,6 @@ static void Mod_Q1BSP_TraceBox(struct model_s *model, int frame, trace_t *trace, #endif } -static hull_t box_hull; -static dclipnode_t box_clipnodes[6]; -static mplane_t box_planes[6]; - -static void Mod_Q1BSP_Collision_Init (void) -{ - int i; - int side; - - //Set up the planes and clipnodes so that the six floats of a bounding box - //can just be stored out and get a proper hull_t structure. - - box_hull.clipnodes = box_clipnodes; - box_hull.planes = box_planes; - box_hull.firstclipnode = 0; - box_hull.lastclipnode = 5; - - for (i = 0;i < 6;i++) - { - box_clipnodes[i].planenum = i; - - side = i&1; - - box_clipnodes[i].children[side] = CONTENTS_EMPTY; - if (i != 5) - box_clipnodes[i].children[side^1] = i + 1; - else - box_clipnodes[i].children[side^1] = CONTENTS_SOLID; - - box_planes[i].type = i>>1; - box_planes[i].normal[i>>1] = 1; - } -} - void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask, int boxsupercontents) { #if 1 @@ -746,6 +707,9 @@ void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cm Collision_TraceLineBrushFloat(trace, start, end, &cbox, &cbox); #else RecursiveHullCheckTraceInfo_t rhc; + static hull_t box_hull; + static dclipnode_t box_clipnodes[6]; + static mplane_t box_planes[6]; // fill in a default trace memset(&rhc, 0, sizeof(rhc)); memset(trace, 0, sizeof(trace_t)); @@ -761,6 +725,36 @@ void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cm #if COLLISIONPARANOID >= 3 Con_Printf("box_planes %f:%f %f:%f %f:%f\ncbox %f %f %f:%f %f %f\nbox %f %f %f:%f %f %f\n", box_planes[0].dist, box_planes[1].dist, box_planes[2].dist, box_planes[3].dist, box_planes[4].dist, box_planes[5].dist, cmins[0], cmins[1], cmins[2], cmaxs[0], cmaxs[1], cmaxs[2], mins[0], mins[1], mins[2], maxs[0], maxs[1], maxs[2]); #endif + + if (box_hull.clipnodes == NULL) + { + int i, side; + + //Set up the planes and clipnodes so that the six floats of a bounding box + //can just be stored out and get a proper hull_t structure. + + box_hull.clipnodes = box_clipnodes; + box_hull.planes = box_planes; + box_hull.firstclipnode = 0; + box_hull.lastclipnode = 5; + + for (i = 0;i < 6;i++) + { + box_clipnodes[i].planenum = i; + + side = i&1; + + box_clipnodes[i].children[side] = CONTENTS_EMPTY; + if (i != 5) + box_clipnodes[i].children[side^1] = i + 1; + else + box_clipnodes[i].children[side^1] = CONTENTS_SOLID; + + box_planes[i].type = i>>1; + box_planes[i].normal[i>>1] = 1; + } + } + // trace a line through the generated clipping hull //rhc.boxsupercontents = boxsupercontents; rhc.hull = &box_hull; diff --git a/model_shared.c b/model_shared.c index 368c1c3a..bcc813aa 100644 --- a/model_shared.c +++ b/model_shared.c @@ -34,112 +34,6 @@ model_t *loadmodel; #define MAX_MOD_KNOWN (MAX_MODELS + 256) static model_t mod_known[MAX_MOD_KNOWN]; -rtexturepool_t *mod_shared_texturepool; -rtexture_t *r_texture_notexture; -rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES]; -rtexture_t *mod_shared_distorttexture[64]; - -void Mod_BuildDetailTextures (void) -{ - int i, x, y, light; - float vc[3], vx[3], vy[3], vn[3], lightdir[3]; -#define DETAILRESOLUTION 256 - qbyte data[DETAILRESOLUTION][DETAILRESOLUTION][4], noise[DETAILRESOLUTION][DETAILRESOLUTION]; - lightdir[0] = 0.5; - lightdir[1] = 1; - lightdir[2] = -0.25; - VectorNormalize(lightdir); - for (i = 0;i < NUM_DETAILTEXTURES;i++) - { - fractalnoise(&noise[0][0], DETAILRESOLUTION, DETAILRESOLUTION >> 4); - for (y = 0;y < DETAILRESOLUTION;y++) - { - for (x = 0;x < DETAILRESOLUTION;x++) - { - vc[0] = x; - vc[1] = y; - vc[2] = noise[y][x] * (1.0f / 32.0f); - vx[0] = x + 1; - vx[1] = y; - vx[2] = noise[y][(x + 1) % DETAILRESOLUTION] * (1.0f / 32.0f); - vy[0] = x; - vy[1] = y + 1; - vy[2] = noise[(y + 1) % DETAILRESOLUTION][x] * (1.0f / 32.0f); - VectorSubtract(vx, vc, vx); - VectorSubtract(vy, vc, vy); - CrossProduct(vx, vy, vn); - VectorNormalize(vn); - light = 128 - DotProduct(vn, lightdir) * 128; - light = bound(0, light, 255); - data[y][x][0] = data[y][x][1] = data[y][x][2] = light; - data[y][x][3] = 255; - } - } - mod_shared_detailtextures[i] = R_LoadTexture2D(mod_shared_texturepool, va("detailtexture%i", i), DETAILRESOLUTION, DETAILRESOLUTION, &data[0][0][0], TEXTYPE_RGBA, TEXF_MIPMAP | TEXF_PRECACHE, NULL); - } -} - -qbyte Mod_MorphDistortTexture (double y0, double y1, double y2, double y3, double morph) -{ - int value = (int)(((y1 + y3 - (y0 + y2)) * morph * morph * morph) + - ((2 * (y0 - y1) + y2 - y3) * morph * morph) + - ((y2 - y0) * morph) + - (y1)); - - if (value > 255) - value = 255; - if (value < 0) - value = 0; - - return (qbyte)value; -} - -void Mod_BuildDistortTexture (void) -{ - int x, y, i, j; -#define DISTORTRESOLUTION 32 - qbyte data[5][DISTORTRESOLUTION][DISTORTRESOLUTION][2]; - - for (i=0; i<4; i++) - { - for (y=0; yname); isworldmodel = mod->isworldmodel; + used = mod->used; Mod_FreeModel(mod); strcpy(mod->name, name); mod->isworldmodel = isworldmodel; + mod->used = used; mod->loaded = false; } @@ -1043,7 +933,7 @@ int Mod_LoadSkinFrame(skinframe_t *skinframe, char *basename, int textureflags, if (!image_loadskin(&s, basename)) return false; if (usedetailtexture) - skinframe->detail = mod_shared_detailtextures[(detailtexturecycle++) % NUM_DETAILTEXTURES]; + skinframe->detail = r_texture_detailtextures[(detailtexturecycle++) % NUM_DETAILTEXTURES]; skinframe->base = R_LoadTexture2D (loadmodel->texturepool, basename, s.basepixels_width, s.basepixels_height, s.basepixels, TEXTYPE_RGBA, textureflags, NULL); if (s.nmappixels != NULL) skinframe->nmap = R_LoadTexture2D (loadmodel->texturepool, va("%s_nmap", basename), s.nmappixels_width, s.nmappixels_height, s.nmappixels, TEXTYPE_RGBA, textureflags, NULL); @@ -1071,7 +961,7 @@ int Mod_LoadSkinFrame_Internal(skinframe_t *skinframe, char *basename, int textu if (!skindata) return false; if (usedetailtexture) - skinframe->detail = mod_shared_detailtextures[(detailtexturecycle++) % NUM_DETAILTEXTURES]; + skinframe->detail = r_texture_detailtextures[(detailtexturecycle++) % NUM_DETAILTEXTURES]; if (r_shadow_bumpscale_basetexture.value > 0) { temp1 = Mem_Alloc(loadmodel->mempool, width * height * 8); diff --git a/model_shared.h b/model_shared.h index a8953629..96cf1292 100644 --- a/model_shared.h +++ b/model_shared.h @@ -427,15 +427,6 @@ model_t; //============================================================================ -// this can be used for anything without a valid texture -extern rtexture_t *r_texture_notexture; -#define NUM_DETAILTEXTURES 1 -extern rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES]; -// every texture must be in a pool... -extern rtexturepool_t *mod_shared_texturepool; - -extern rtexture_t *mod_shared_distorttexture[64]; - // model loading extern model_t *loadmodel; extern qbyte *mod_base; diff --git a/render.h b/render.h index 92992f85..1a46caad 100644 --- a/render.h +++ b/render.h @@ -181,6 +181,9 @@ extern rtexture_t *r_texture_black; extern rtexture_t *r_texture_notexture; extern rtexture_t *r_texture_whitecube; extern rtexture_t *r_texture_normalizationcube; +#define NUM_DETAILTEXTURES 1 +extern rtexture_t *r_texture_detailtextures[NUM_DETAILTEXTURES]; +extern rtexture_t *r_texture_distorttexture[64]; void R_TimeReport(char *name); void R_TimeReport_Start(void); -- 2.39.2