Skip to content

Commit

Permalink
24bit external sky support
Browse files Browse the repository at this point in the history
  • Loading branch information
timbergeron committed Sep 18, 2024
1 parent e60abfc commit 3a511ec
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
36 changes: 32 additions & 4 deletions Quake/gl_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 =
Expand Down
54 changes: 54 additions & 0 deletions Quake/gl_sky.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Quake/glquake.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand Down

0 comments on commit 3a511ec

Please sign in to comment.