diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 1d1b9cbfe..4aa6ebfdb 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6147,13 +6147,14 @@ void HWR_AddSessionCommands(void) // -------------------------------------------------------------------------- void HWR_Startup(void) { - INT32 i; static boolean startupdone = false; // do this once if (!startupdone) { + INT32 i; CONS_Printf("HWR_Startup()...\n"); + HWR_InitPolyPool(); HWR_AddSessionCommands(); HWR_InitTextureCache(); @@ -6161,16 +6162,17 @@ void HWR_Startup(void) #ifdef ALAM_LIGHTING HWR_InitLight(); #endif + + // read every custom shader + for (i = 0; i < numwadfiles; i++) + HWR_ReadShaders(i, (wadfiles[i]->type == RET_PK3)); + HWR_LoadShaders(); } if (rendermode == render_opengl) textureformat = patchformat = GR_RGBA; startupdone = true; - - for (i = 0; i < numwadfiles; i++) - HWR_LoadShaders(i, (wadfiles[i]->type == RET_PK3)); - HWD.pfnInitCustomShaders(); } // -------------------------------------------------------------------------- @@ -6466,7 +6468,12 @@ static inline UINT16 HWR_CheckShader(UINT16 wadnum) return INT16_MAX; } -void HWR_LoadShaders(UINT16 wadnum, boolean PK3) +void HWR_LoadShaders(void) +{ + HWD.pfnInitCustomShaders(); +} + +void HWR_ReadShaders(UINT16 wadnum, boolean PK3) { UINT16 lump; char *shaderdef, *line; @@ -6497,9 +6504,6 @@ void HWR_LoadShaders(UINT16 wadnum, boolean PK3) 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'; @@ -6518,7 +6522,7 @@ void HWR_LoadShaders(UINT16 wadnum, boolean PK3) 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); + CONS_Alert(CONS_WARNING, "HWR_ReadShaders: Missing shader type (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); stoken = strtok(NULL, "\r\n"); // skip end of line goto skip_lump; } @@ -6537,14 +6541,14 @@ skip_lump: value = strtok(NULL, "\r\n= "); if (!value) { - CONS_Alert(CONS_WARNING, "HWR_LoadShaders: Missing shader target (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); + CONS_Alert(CONS_WARNING, "HWR_ReadShaders: Missing shader target (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 type (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); + CONS_Alert(CONS_ERROR, "HWR_ReadShaders: Missing shader type (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); Z_Free(line); return; } @@ -6575,7 +6579,7 @@ skip_lump: 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); + CONS_Alert(CONS_ERROR, "HWR_ReadShaders: Missing shader source %s (file %s, line %d)\n", shader_lumpname, wadfiles[wadnum]->filename, linenum); Z_Free(shader_lumpname); continue; } diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 6e3e7d2b0..aedfa9cd6 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -69,7 +69,8 @@ void HWR_DrawScreenFinalTexture(int width, int height); void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap); UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap); // Let's see if this can work -void HWR_LoadShaders(UINT16 wadnum, boolean PK3); +void HWR_ReadShaders(UINT16 wadnum, boolean PK3); +void HWR_LoadShaders(void); extern CV_PossibleValue_t granisotropicmode_cons_t[]; diff --git a/src/w_wad.c b/src/w_wad.c index 1684af2a4..9ff082aa5 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -788,6 +788,15 @@ UINT16 W_InitFile(const char *filename, boolean mainfile) 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 + // Read shaders from file + if (rendermode == render_opengl && hwrenderloaded) + { + HWR_ReadShaders(numwadfiles - 1, (type == RET_PK3)); + HWR_LoadShaders(); + } +#endif // HWRENDER + // 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) {