mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-26 20:31:30 +00:00
Improve custom shader support
This commit is contained in:
parent
848ae84188
commit
f714cba310
7 changed files with 148 additions and 52 deletions
|
@ -77,6 +77,7 @@ EXPORT void HWRAPI(SetShader) (int shader);
|
|||
EXPORT void HWRAPI(UnSetShader) (void);
|
||||
|
||||
EXPORT void HWRAPI(LoadCustomShader) (int number, char *shader, size_t size, boolean fragment);
|
||||
EXPORT void HWRAPI(InitCustomShaders) (void);
|
||||
|
||||
// ==========================================================================
|
||||
// HWR DRIVER OBJECT, FOR CLIENT PROGRAM
|
||||
|
@ -126,6 +127,7 @@ struct hwdriver_s
|
|||
UnSetShader pfnUnSetShader;
|
||||
|
||||
LoadCustomShader pfnLoadCustomShader;
|
||||
InitCustomShaders pfnInitCustomShaders;
|
||||
};
|
||||
|
||||
extern struct hwdriver_s hwdriver;
|
||||
|
|
|
@ -5937,9 +5937,139 @@ void HWR_DrawScreenFinalTexture(int width, int height)
|
|||
}
|
||||
|
||||
// jimita 18032019
|
||||
void HWR_LoadShader(int number, char *shader, size_t size, boolean fragment)
|
||||
typedef struct
|
||||
{
|
||||
HWD.pfnLoadCustomShader(number, shader, size, fragment);
|
||||
char type[16];
|
||||
INT32 id;
|
||||
} shaderxlat_t;
|
||||
|
||||
static inline UINT16 HWR_CheckShader(UINT16 wadnum)
|
||||
{
|
||||
UINT16 i;
|
||||
lumpinfo_t *lump_p;
|
||||
|
||||
lump_p = wadfiles[wadnum]->lumpinfo;
|
||||
for (i = 0; i < wadfiles[wadnum]->numlumps; i++, lump_p++)
|
||||
if (memcmp(lump_p->name, "SHADERS", 7) == 0)
|
||||
return i;
|
||||
|
||||
return INT16_MAX;
|
||||
}
|
||||
|
||||
void HWR_LoadShaders(UINT16 wadnum)
|
||||
{
|
||||
UINT16 lump;
|
||||
char *shaderdef, *line;
|
||||
char *stoken;
|
||||
char *value;
|
||||
size_t size;
|
||||
int linenum = 1;
|
||||
int shadertype = 0;
|
||||
int i;
|
||||
|
||||
#define SHADER_TYPES 6
|
||||
shaderxlat_t shaderxlat[SHADER_TYPES] =
|
||||
{
|
||||
{"Flat", 1},
|
||||
{"WallTexture", 2},
|
||||
{"Sprite", 3},
|
||||
{"Model", 4},
|
||||
{"WaterRipple", 5},
|
||||
{"Sky", 6},
|
||||
};
|
||||
|
||||
lump = HWR_CheckShader(wadnum);
|
||||
if (lump == INT16_MAX)
|
||||
return;
|
||||
|
||||
shaderdef = W_CacheLumpNumPwad(wadnum, lump, PU_CACHE);
|
||||
size = W_LumpLengthPwad(wadnum, lump);
|
||||
|
||||
line = Z_Malloc(size+1, PU_STATIC, NULL);
|
||||
if (!line)
|
||||
I_Error("HWR_LoadShaders: No more free memory\n");
|
||||
|
||||
M_Memcpy(line, shaderdef, size);
|
||||
line[size] = '\0';
|
||||
|
||||
stoken = strtok(line, "\r\n ");
|
||||
while (stoken)
|
||||
{
|
||||
if (!stricmp(stoken, "GLSL"))
|
||||
{
|
||||
value = strtok(NULL, "\r\n ");
|
||||
if (!value)
|
||||
{
|
||||
CONS_Alert(CONS_WARNING, "HWR_LoadShaders: Missing shader type (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum);
|
||||
stoken = strtok(NULL, "\r\n"); // skip end of line
|
||||
goto skip_lump;
|
||||
}
|
||||
|
||||
if (!stricmp(value, "VERTEX"))
|
||||
shadertype = 1;
|
||||
else if (!stricmp(value, "FRAGMENT"))
|
||||
shadertype = 2;
|
||||
|
||||
skip_lump:
|
||||
stoken = strtok(NULL, "\r\n ");
|
||||
linenum++;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = strtok(NULL, "\r\n= ");
|
||||
if (!value)
|
||||
{
|
||||
CONS_Alert(CONS_WARNING, "HWR_LoadShaders: Missing shader source (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum);
|
||||
stoken = strtok(NULL, "\r\n"); // skip end of line
|
||||
goto skip_field;
|
||||
}
|
||||
|
||||
if (!shadertype)
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, "HWR_LoadShaders: Missing shader target (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum);
|
||||
Z_Free(line);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < SHADER_TYPES; i++)
|
||||
{
|
||||
if (!stricmp(shaderxlat[i].type, stoken))
|
||||
{
|
||||
size_t shader_size;
|
||||
char *shader_source;
|
||||
char shader_lumpname[9];
|
||||
UINT16 shader_lumpnum;
|
||||
|
||||
strcpy(shader_lumpname, "SH_");
|
||||
strcat(shader_lumpname, value);
|
||||
shader_lumpnum = W_CheckNumForNamePwad(shader_lumpname, wadnum, 0);
|
||||
|
||||
if (shader_lumpnum == INT16_MAX)
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, "HWR_LoadShaders: Missing shader source %s (file %s, line %d)\n", shader_lumpname, wadfiles[wadnum]->filename, linenum);
|
||||
break;
|
||||
}
|
||||
|
||||
shader_size = W_LumpLengthPwad(wadnum, shader_lumpnum);
|
||||
shader_source = Z_Malloc(shader_size, PU_STATIC, NULL);
|
||||
W_ReadLumpPwad(wadnum, shader_lumpnum, shader_source);
|
||||
|
||||
HWD.pfnLoadCustomShader(shaderxlat[i].id, shader_source, shader_size, (shadertype == 2));
|
||||
|
||||
Z_Free(shader_source);
|
||||
}
|
||||
}
|
||||
|
||||
skip_field:
|
||||
stoken = strtok(NULL, "\r\n= ");
|
||||
linenum++;
|
||||
}
|
||||
}
|
||||
|
||||
HWD.pfnInitCustomShaders();
|
||||
|
||||
Z_Free(line);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif // HWRENDER
|
||||
|
|
|
@ -65,7 +65,7 @@ void HWR_DrawIntermissionBG(void);
|
|||
void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum);
|
||||
void HWR_MakeScreenFinalTexture(void);
|
||||
void HWR_DrawScreenFinalTexture(int width, int height);
|
||||
void HWR_LoadShader(int number, char *shader, size_t size, boolean fragment);
|
||||
void HWR_LoadShaders(UINT16 wadnum);
|
||||
|
||||
// This stuff is put here so MD2's can use them
|
||||
void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, UINT32 mixcolor, UINT32 fadecolor);
|
||||
|
|
|
@ -823,7 +823,12 @@ EXPORT void HWRAPI(LoadCustomShader) (int number, char *shader, size_t size, boo
|
|||
strncpy(gl_customvertexshaders[number], shader, size);
|
||||
gl_customvertexshaders[number][size] = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
EXPORT void HWRAPI(InitCustomShaders) (void)
|
||||
{
|
||||
#ifdef USE_SHADERS
|
||||
KillShaders();
|
||||
LoadShaders();
|
||||
#endif
|
||||
|
|
|
@ -109,6 +109,7 @@ void *hwSym(const char *funcName,void *handle)
|
|||
GETFUNC(UnSetShader);
|
||||
|
||||
GETFUNC(LoadCustomShader);
|
||||
GETFUNC(InitCustomShaders);
|
||||
|
||||
#else //HWRENDER
|
||||
if (0 == strcmp("FinishUpdate", funcName))
|
||||
|
|
|
@ -1506,6 +1506,7 @@ void I_StartupGraphics(void)
|
|||
HWD.pfnUnSetShader = hwSym("UnSetShader",NULL);
|
||||
|
||||
HWD.pfnLoadCustomShader = hwSym("LoadCustomShader",NULL);
|
||||
HWD.pfnInitCustomShaders = hwSym("InitCustomShaders",NULL);
|
||||
|
||||
// check gl renderer lib
|
||||
if (HWD.pfnGetRenderVersion() != VERSION)
|
||||
|
|
55
src/w_wad.c
55
src/w_wad.c
|
@ -181,24 +181,6 @@ FILE *W_OpenWadFile(const char **filename, boolean useerrors)
|
|||
return handle;
|
||||
}
|
||||
|
||||
static inline void W_LoadShader(UINT16 wadnum, UINT16 lump, char *name, boolean fragment)
|
||||
{
|
||||
size_t shader_size;
|
||||
char *shader_string;
|
||||
char shader_number[2];
|
||||
|
||||
shader_size = W_LumpLengthPwad(wadnum, lump);
|
||||
shader_string = Z_Malloc(shader_size, PU_STATIC, NULL);
|
||||
W_ReadLumpPwad(wadnum, lump, shader_string);
|
||||
|
||||
shader_number[0] = name[6];
|
||||
shader_number[1] = name[7];
|
||||
|
||||
HWR_LoadShader(atoi(shader_number), shader_string, shader_size, fragment);
|
||||
|
||||
Z_Free(shader_string);
|
||||
}
|
||||
|
||||
// Look for all DEHACKED and Lua scripts inside a PK3 archive.
|
||||
static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum)
|
||||
{
|
||||
|
@ -231,21 +213,6 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum)
|
|||
free(name);
|
||||
}
|
||||
}
|
||||
|
||||
// jimita 18032019
|
||||
#ifdef HWRENDER
|
||||
posStart = W_CheckNumForFolderStartPK3("Shaders/", wadnum, 0);
|
||||
if (posStart != INT16_MAX)
|
||||
{
|
||||
posEnd = W_CheckNumForFolderEndPK3("Shaders/", wadnum, posStart);
|
||||
posStart++;
|
||||
for (; posStart < posEnd; posStart++)
|
||||
{
|
||||
lumpinfo_t *lump_p = &wadfiles[wadnum]->lumpinfo[posStart];
|
||||
W_LoadShader(wadnum, posStart, lump_p->name2, !(memcmp(lump_p->name2,"FRGSHD",6)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// search for all DEHACKED lump in all wads and load it
|
||||
|
@ -289,20 +256,6 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum)
|
|||
}
|
||||
}
|
||||
|
||||
// jimita 18032019
|
||||
#ifdef HWRENDER
|
||||
{
|
||||
lumpinfo_t *lump_p = wadfiles[wadnum]->lumpinfo;
|
||||
for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++)
|
||||
{
|
||||
boolean vertex = (!(memcmp(lump_p->name,"VRTSHD",6)));
|
||||
boolean fragment = (!(memcmp(lump_p->name,"FRGSHD",6)));
|
||||
if (vertex || fragment)
|
||||
W_LoadShader(wadnum, lump, lump_p->name, fragment);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SCANTHINGS
|
||||
// Scan maps for emblems 'n shit
|
||||
{
|
||||
|
@ -828,6 +781,11 @@ UINT16 W_InitFile(const char *filename)
|
|||
wadfiles[numwadfiles] = wadfile;
|
||||
numwadfiles++; // must come BEFORE W_LoadDehackedLumps, so any addfile called by COM_BufInsertText called by Lua doesn't overwrite what we just loaded
|
||||
|
||||
#ifdef HWRENDER
|
||||
if (rendermode == render_opengl)
|
||||
HWR_LoadShaders(numwadfiles - 1);
|
||||
#endif
|
||||
|
||||
// TODO: HACK ALERT - Load Lua & SOC stuff right here. I feel like this should be out of this place, but... Let's stick with this for now.
|
||||
switch (wadfile->type)
|
||||
{
|
||||
|
@ -1741,8 +1699,7 @@ int W_VerifyNMUSlumps(const char *filename)
|
|||
{"PAL", 3},
|
||||
{"CLM", 3},
|
||||
{"TRANS", 5},
|
||||
{"VRTSHD", 6},
|
||||
{"FRGSHD", 6},
|
||||
{"SH_", 3},
|
||||
{NULL, 0},
|
||||
};
|
||||
return W_VerifyFile(filename, NMUSlist, false);
|
||||
|
|
Loading…
Reference in a new issue