From 3a511ecc37f45f73a04f4bfa04268c282a36ab05 Mon Sep 17 00:00:00 2001 From: timbergeron Date: Wed, 18 Sep 2024 16:48:20 -0700 Subject: [PATCH] 24bit external sky support --- Quake/gl_model.c | 36 ++++++++++++++++++++++++++++---- Quake/gl_sky.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ Quake/glquake.h | 1 + 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/Quake/gl_model.c b/Quake/gl_model.c index f40b60ea..7c7dbb80 100644 --- a/Quake/gl_model.c +++ b/Quake/gl_model.c @@ -855,10 +855,13 @@ static void Mod_LoadTextures (lump_t *l) { if (!q_strncasecmp(tx->name,"sky",3)) //sky texture //also note -- was Q_strncmp, changed to match qbsp { - if (loadmodel->bspversion == BSPVERSION_QUAKE64) - Sky_LoadTextureQ64 (loadmodel, tx); - else - Sky_LoadTexture (loadmodel, tx, fmt, imgwidth, imgheight); + if (!gl_load24bit.value || !Sky_LoadExternalTextures(loadmodel, tx)) // woods #extsky + { + if (loadmodel->bspversion == BSPVERSION_QUAKE64) + Sky_LoadTextureQ64 (loadmodel, tx); + else + Sky_LoadTexture (loadmodel, tx, fmt, imgwidth, imgheight); + } } else if (tx->name[0] == '*') //warping texture { @@ -3936,6 +3939,11 @@ static void *Mod_LoadSpriteFrame (void * pin, mspriteframe_t **ppframe, int fram int width, height, size, origin[2]; char name[64]; src_offset_t offset; //johnfitz + byte* data = NULL; + qboolean malloced = false; + int fwidth = 0, fheight = 0; + enum srcformat rfmt = SRC_RGBA; + int hunkmark; pinframe = (dspriteframe_t *)pin; @@ -3963,6 +3971,26 @@ static void *Mod_LoadSpriteFrame (void * pin, mspriteframe_t **ppframe, int fram pspriteframe->tmax = (float)height/(float)TexMgr_PadConditional(height); //johnfitz + if (gl_load24bit.value) // woods #extsprites + { + hunkmark = Hunk_LowMark(); + q_snprintf(name, sizeof(name), "%s_%i", loadmodel->name, framenum); + data = Image_LoadImage(name, &fwidth, &fheight, &rfmt, &malloced); + + if (data) + { + pspriteframe->gltexture = + TexMgr_LoadImage(loadmodel, name, fwidth, fheight, rfmt, + data, name, 0, TEXPREF_PAD | TEXPREF_NOPICMIP | TEXPREF_LINEAR | TEXPREF_ALPHA); + + if (malloced) + free(data); + Hunk_FreeToLowMark(hunkmark); + + return (void*)((byte*)pinframe + sizeof(dspriteframe_t) + size); + } + } + q_snprintf (name, sizeof(name), "%s:frame%i", loadmodel->name, framenum); offset = (src_offset_t)(pinframe+1) - (src_offset_t)mod_base; //johnfitz pspriteframe->gltexture = diff --git a/Quake/gl_sky.c b/Quake/gl_sky.c index f5e36fac..c7dc992e 100644 --- a/Quake/gl_sky.c +++ b/Quake/gl_sky.c @@ -222,6 +222,60 @@ void Sky_LoadTextureQ64 (qmodel_t *mod, texture_t *mt) skyflatcolor[2] = (float)b/(count*255); } +/* +============= +Sky_LoadExternalTextures -- woods #extsky +Load external sky textures +============== +*/ +qboolean Sky_LoadExternalTextures (qmodel_t* mod, texture_t* mt) +{ + if (r_fastsky.value == 1) + return false; + + char texturename_back[MAX_OSPATH], texturename_front[MAX_OSPATH]; + char mapname[MAX_OSPATH]; + byte* back_data = NULL, * front_data = NULL; + int fwidth_back = 0, fheight_back = 0, fwidth_front = 0, fheight_front = 0; + enum srcformat rfmt_back = SRC_EXTERNAL, rfmt_front = SRC_EXTERNAL; + qboolean malloced_back = false, malloced_front = false; + + int mark = Hunk_LowMark(); + + COM_StripExtension(mod->name + 5, mapname, sizeof(mapname)); + + q_snprintf(texturename_back, sizeof(texturename_back), "textures/%s/%s_back", mapname, mt->name); + back_data = Image_LoadImage(texturename_back, &fwidth_back, &fheight_back, &rfmt_back, &malloced_back); + if (!back_data) { + q_snprintf(texturename_back, sizeof(texturename_back), "textures/%s_back", mt->name); + back_data = Image_LoadImage(texturename_back, &fwidth_back, &fheight_back, &rfmt_back, &malloced_back); + } + + q_snprintf(texturename_front, sizeof(texturename_front), "textures/%s/%s_front", mapname, mt->name); + front_data = Image_LoadImage(texturename_front, &fwidth_front, &fheight_front, &rfmt_front, &malloced_front); + if (!front_data) { + q_snprintf(texturename_front, sizeof(texturename_front), "textures/%s_front", mt->name); + front_data = Image_LoadImage(texturename_front, &fwidth_front, &fheight_front, &rfmt_front, &malloced_front); + } + + if (back_data && front_data) // If both textures loaded successfully + { + mt->gltexture = solidskytexture = TexMgr_LoadImage(mod, texturename_back, fwidth_back, fheight_back, rfmt_back, back_data, texturename_back, 0, TEXPREF_NONE); + mt->fullbright = alphaskytexture = TexMgr_LoadImage(mod, texturename_front, fwidth_front, fheight_front, rfmt_front, front_data, texturename_front, 0, TEXPREF_ALPHA); + + if (malloced_back) free(back_data); + if (malloced_front) free(front_data); + Hunk_FreeToLowMark(mark); + return true; // success: both textures loaded + } + + if (malloced_back) free(back_data); + if (malloced_front) free(front_data); + Hunk_FreeToLowMark(mark); + + return false; +} + /* ================== Sky_LoadSkyBox diff --git a/Quake/glquake.h b/Quake/glquake.h index b813e706..e7b4738d 100644 --- a/Quake/glquake.h +++ b/Quake/glquake.h @@ -459,6 +459,7 @@ void Sky_DrawSky (void); void Sky_NewMap (void); void Sky_LoadTexture (qmodel_t *mod, texture_t *mt, enum srcformat fmt, unsigned int width, unsigned int height); void Sky_LoadTextureQ64 (qmodel_t *mod, texture_t *mt); +qboolean Sky_LoadExternalTextures (qmodel_t* mod, texture_t* mt); // woods #extsky void Sky_LoadSkyBox (const char *name); extern qboolean skyroom_drawn, skyroom_drawing; //we draw a skyroom this frame extern qboolean skyroom_enabled; //we know where the skyroom is ...