Merge branch 'Saturn-Next' into gammastuff

This commit is contained in:
indev authored and GitHub committed 2024-01-18 18:40:51 +03:00
commit fd1177b6e5
30 files changed
+817 -550

No files matched your search

+1 -1
View File
@@ -141,7 +141,7 @@ DECL_HUD_OFFSET(item); // Item box
DECL_HUD_OFFSET(time); // Time
DECL_HUD_OFFSET(laps); // Number of laps
DECL_HUD_OFFSET(dnft); // Countdown (did not finish timer)
DECL_HUD_OFFSET(spdm); // Speedometer
DECL_HUD_OFFSET(speed); // Speedometer
DECL_HUD_OFFSET(posi); // Position in race
DECL_HUD_OFFSET(face); // Mini rankings
DECL_HUD_OFFSET(stcd); // Starting countdown
+217 -20
View File
@@ -33,12 +33,20 @@ static INT32 blocksize, blockwidth, blockheight;
INT32 patchformat = GR_TEXFMT_AP_88; // use alpha for holes
INT32 textureformat = GR_TEXFMT_P_8; // use chromakey for hole
RGBA_t mapPalette[256] = {0}; // the palette for the currently loaded level or menu etc.
// Returns a pointer to the palette which should be used for caching textures.
RGBA_t *HWR_GetTexturePalette(void)
{
return HWR_ShouldUsePaletteRendering() ? mapPalette : pLocalPalette;
}
// sprite, use alpha and chroma key for hole
static void HWR_DrawPatchInCache(GLMipmap_t *mipmap,
INT32 pblockwidth, INT32 pblockheight, INT32 blockmodulo,
INT32 ptexturewidth, INT32 ptextureheight,
INT32 originx, INT32 originy, // where to draw patch in surface block
const patch_t *realpatch, INT32 bpp)
const patch_t *realpatch, INT32 bpp, RGBA_t *palette)
{
INT32 x, x1, x2;
INT32 col, ncols;
@@ -67,6 +75,8 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap,
if (!ptexturewidth)
return;
palette = HWR_GetTexturePalette();
col = x * pblockwidth / ptexturewidth;
ncols = ((x2 - x) * pblockwidth) / ptexturewidth;
@@ -152,10 +162,10 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap,
case 2 : texelu16 = (UINT16)((alpha<<8) | texel);
memcpy(dest, &texelu16, sizeof(UINT16));
break;
case 3 : colortemp = V_GetColor(texel);
case 3 : colortemp = palette[texel];
memcpy(dest, &colortemp, sizeof(RGBA_t)-sizeof(UINT8));
break;
case 4 : colortemp = V_GetColor(texel);
case 4 : colortemp = palette[texel];
colortemp.s.alpha = alpha;
memcpy(dest, &colortemp, sizeof(RGBA_t));
break;
@@ -329,6 +339,9 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex)
INT32 i;
boolean skyspecial = false; //poor hack for Legacy large skies..
RGBA_t *palette;
palette = HWR_GetTexturePalette();
texture = textures[texnum];
@@ -349,7 +362,12 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex)
HWR_ResizeBlock (texture->width, texture->height, &grtex->mipmap.grInfo);
grtex->mipmap.width = (UINT16)blockwidth;
grtex->mipmap.height = (UINT16)blockheight;
grtex->mipmap.grInfo.format = textureformat;
//grtex->mipmap.grInfo.format = textureformat;
if (skyspecial)
grtex->mipmap.grInfo.format = GR_RGBA; // that skyspecial code below assumes this format ...
else
grtex->mipmap.grInfo.format = textureformat;
grtex->mipmap.colormap = colormaps;
@@ -365,7 +383,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex)
INT32 j;
RGBA_t col;
col = V_GetColor(HWR_CHROMAKEY_EQUIVALENTCOLORINDEX);
col = palette[HWR_CHROMAKEY_EQUIVALENTCOLORINDEX];
for (j = 0; j < blockheight; j++)
{
for (i = 0; i < blockwidth; i++)
@@ -388,7 +406,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex)
texture->width, texture->height,
patch->originx, patch->originy,
realpatch,
format2bpp[grtex->mipmap.grInfo.format]);
format2bpp[grtex->mipmap.grInfo.format], palette);
Z_Unlock(realpatch);
}
//Hurdler: not efficient at all but I don't remember exactly how HWR_DrawPatchInCache works :(
@@ -412,6 +430,8 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex)
void HWR_MakePatch (patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap)
{
INT32 newwidth, newheight;
RGBA_t *palette = HWR_GetTexturePalette();
// don't do it twice (like a cache)
if (grMipmap->width == 0)
@@ -456,7 +476,7 @@ void HWR_MakePatch (patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, bo
grPatch->width, grPatch->height,
0, 0,
patch,
format2bpp[grMipmap->grInfo.format]);
format2bpp[grMipmap->grInfo.format], palette);
}
grPatch->max_s = (float)newwidth / (float)blockwidth;
@@ -557,18 +577,6 @@ void HWR_PrepLevelCache(size_t pnumtextures)
I_Error("HWR_PrepLevelCache: can't alloc gr_textures");
}
void HWR_SetPalette(RGBA_t *palette)
{
HWD.pfnSetPalette(palette);
// hardware driver will flush there own cache if cache is non paletized
// now flush data texture cache so 32 bit texture are recomputed
if (patchformat == GR_RGBA || textureformat == GR_RGBA)
{
Z_FreeTags(PU_HWRCACHE, PU_HWRCACHE);
Z_FreeTags(PU_HWRCACHE_UNLOCKED, PU_HWRCACHE_UNLOCKED);
}
}
// --------------------------------------------------------------------------
// Make sure texture is downloaded and set it as the source
// --------------------------------------------------------------------------
@@ -814,6 +822,7 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32
UINT8 *flat;
UINT8 *dest, *src, texel;
RGBA_t col;
RGBA_t *palette = HWR_GetTexturePalette();
// Place the flats data into flat
W_ReadLump(fademasklumpnum, Z_Malloc(W_LumpLength(fademasklumpnum),
@@ -831,7 +840,7 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32
{
// fademask bpp is always 1, and is used just for alpha
texel = src[(posx)>>FRACBITS];
col = V_GetColor(texel);
col = palette[texel];
*dest = col.s.red; // take the red level of the colour and use it for alpha, as fademasks do
dest++;
@@ -907,4 +916,192 @@ void HWR_GetFadeMask(lumpnum_t fademasklumpnum)
Z_ChangeTag(grmip->grInfo.data, PU_HWRCACHE_UNLOCKED);
}
// =================================================
// PALETTE HANDLING
// =================================================
void HWR_SetPalette(RGBA_t *palette)
{
if (HWR_ShouldUsePaletteRendering())
{
// set the palette for palette postprocessing
if (cv_grpalettedepth.value == 16)
{
// crush to 16-bit rgb565, like software currently does in the standard configuration
// Note: Software's screenshots have the 24-bit palette, but the screen gets
// the 16-bit version! For making comparison screenshots either use an external screenshot
// tool or set the palette depth to 24 bits.
RGBA_t crushed_palette[256];
int i;
for (i = 0; i < 256; i++)
{
float fred = (float)(palette[i].s.red >> 3);
float fgreen = (float)(palette[i].s.green >> 2);
float fblue = (float)(palette[i].s.blue >> 3);
crushed_palette[i].s.red = (UINT8)(fred / 31.0f * 255.0f);
crushed_palette[i].s.green = (UINT8)(fgreen / 63.0f * 255.0f);
crushed_palette[i].s.blue = (UINT8)(fblue / 31.0f * 255.0f);
crushed_palette[i].s.alpha = 255;
}
HWD.pfnSetScreenPalette(crushed_palette);
}
else
{
HWD.pfnSetScreenPalette(palette);
}
// this part is responsible for keeping track of the palette OUTSIDE of a level.
if ((!(gamestate == GS_LEVEL)) || (gamestate == GS_TITLESCREEN))
HWR_SetMapPalette();
}
else
{
// set the palette for the textures
HWD.pfnSetTexturePalette(palette);
// reset mapPalette so next call to HWR_SetMapPalette will update everything correctly
memset(mapPalette, 0, sizeof(mapPalette));
// hardware driver will flush there own cache if cache is non paletized
// now flush data texture cache so 32 bit texture are recomputed
//if (patchformat == GL_TEXFMT_RGBA || textureformat == GL_TEXFMT_RGBA)
if (patchformat == GR_RGBA || textureformat == GR_RGBA)
{
Z_FreeTag(PU_HWRCACHE);
Z_FreeTag(PU_HWRCACHE_UNLOCKED);
}
}
}
static void HWR_SetPaletteLookup(RGBA_t *palette)
{
int r, g, b;
UINT8 *lut = Z_Malloc(
HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*sizeof(UINT8),
PU_STATIC, NULL);
#define STEP_SIZE (256/HWR_PALETTE_LUT_SIZE)
for (b = 0; b < HWR_PALETTE_LUT_SIZE; b++)
{
for (g = 0; g < HWR_PALETTE_LUT_SIZE; g++)
{
for (r = 0; r < HWR_PALETTE_LUT_SIZE; r++)
{
lut[b*HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE+g*HWR_PALETTE_LUT_SIZE+r] =
NearestPaletteColor(r*STEP_SIZE, g*STEP_SIZE, b*STEP_SIZE, palette);
}
}
}
#undef STEP_SIZE
HWD.pfnSetPaletteLookup(lut);
Z_Free(lut);
}
// Updates mapPalette to reflect the loaded level or other game state.
// Textures are flushed if needed.
// Call this function only in palette rendering mode.
void HWR_SetMapPalette(void)
{
RGBA_t RGBA_converted[256];
RGBA_t *palette;
int i;
if ((!(gamestate == GS_LEVEL)) || (gamestate == GS_TITLESCREEN))
{
// outside of a level, pMasterPalette should have PLAYPAL ready for us
//palette = pMasterPalette; // we dont have this in kart so just use pLocalPalette as before
palette = pLocalPalette;
}
else
{
// in a level pLocalPalette might have a flash palette, but we
// want the map's original palette.
lumpnum_t lumpnum = W_GetNumForName(GetPalette());
size_t palsize = W_LumpLength(lumpnum);
UINT8 *RGB_data;
if (palsize < 768) // 256 * 3
I_Error("HWR_SetMapPalette: A programmer assumed palette lumps are at least 768 bytes long, but apparently this was a wrong assumption!\n");
RGB_data = W_CacheLumpNum(lumpnum, PU_CACHE);
// we got the RGB palette now, but we need it in RGBA format.
for (i = 0; i < 256; i++)
{
RGBA_converted[i].s.red = *(RGB_data++);
RGBA_converted[i].s.green = *(RGB_data++);
RGBA_converted[i].s.blue = *(RGB_data++);
RGBA_converted[i].s.alpha = 255;
}
palette = RGBA_converted;
}
// check if the palette has changed from the previous one
if (memcmp(mapPalette, palette, sizeof(mapPalette)))
{
memcpy(mapPalette, palette, sizeof(mapPalette));
// in palette rendering mode, this means that all rgba textures now have wrong colors
// and the lookup table is outdated
HWR_SetPaletteLookup(mapPalette);
HWD.pfnSetTexturePalette(mapPalette);
//if (patchformat == GL_TEXFMT_RGBA || textureformat == GL_TEXFMT_RGBA)
if (patchformat == GR_RGBA || textureformat == GR_RGBA)
{
Z_FreeTag(PU_HWRCACHE);
Z_FreeTag(PU_HWRCACHE_UNLOCKED);
}
}
}
// Creates a hardware lighttable from the supplied lighttable.
// Returns the id of the hw lighttable, usable in FSurfaceInfo.
UINT32 HWR_CreateLightTable(UINT8 *lighttable)
{
UINT32 i, id;
RGBA_t *palette = HWR_GetTexturePalette();
RGBA_t *hw_lighttable = Z_Malloc(256 * 32 * sizeof(RGBA_t), PU_STATIC, NULL);
// To make the palette index -> RGBA mapping easier for the shader,
// the hardware lighttable is composed of RGBA colors instead of palette indices.
for (i = 0; i < 256 * 32; i++)
hw_lighttable[i] = palette[lighttable[i]];
id = HWD.pfnCreateLightTable(hw_lighttable);
Z_Free(hw_lighttable);
return id;
}
// get hwr lighttable id for colormap, create it if it doesn't already exist
UINT32 HWR_GetLightTableID(extracolormap_t *colormap)
{
boolean default_colormap = false;
if (!colormap)
{
colormap = &extra_colormaps[num_extra_colormaps]; // a place to store the hw lighttable id
// alternatively could just store the id in a global variable if there are issues
default_colormap = true;
}
// create hw lighttable if there isn't one
if (!colormap->gl_lighttable_id)
{
UINT8 *colormap_pointer;
if (default_colormap)
colormap_pointer = colormaps; // don't actually use the data from the "default colormap"
else
colormap_pointer = colormap->colormap;
colormap->gl_lighttable_id = HWR_CreateLightTable(colormap_pointer);
}
return colormap->gl_lighttable_id;
}
// Note: all hardware lighttable ids assigned before this
// call become invalid and must not be used.
void HWR_ClearLightTables(void)
{
//if (vid.glstate == VID_GL_LIBRARY_LOADED) // we have pfnInit which is essentially the same, but it doesent work here for whatever reason, since this should not be done in software renderer ever!
if (rendermode == render_opengl)
HWD.pfnClearLightTables();
}
#endif //HWRENDER
+6 -1
View File
@@ -25,6 +25,12 @@
#define NZCLIP_PLANE 0.9f // Seems to be only used for the HUD and screen textures
#define FAR_ZCLIP_DEFAULT 32768.0f
// The width/height/depth of the palette lookup table used by palette rendering.
// Changing this also requires changing the shader code!
// Also assumed to be a power of two in some parts of the code.
// 64 seems to work perfectly for the vanilla palette.
#define HWR_PALETTE_LUT_SIZE 64
// ==========================================================================
// SIMPLE TYPES
// ==========================================================================
@@ -234,7 +240,6 @@ typedef struct FSurfaceInfo FSurfaceInfo;
enum hwdsetspecialstate
{
HWD_SET_SHADERS,
HWD_PAL_SHADER,
HWD_SET_TEXTUREFILTERMODE,
HWD_SET_TEXTUREANISOTROPICMODE,
+19 -15
View File
@@ -567,12 +567,13 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength)
}
else // Do TRANSMAP** fade.
{
if (HWR_ShouldUsePaletteRendering())
Surf.PolyColor.rgba = pLocalPalette[color&0xFF].rgba;
else
Surf.PolyColor.rgba = pLocalPalette[color].rgba;
RGBA_t *palette = HWR_GetTexturePalette();
Surf.PolyColor.rgba = palette[color&0xFF].rgba;
Surf.PolyColor.s.alpha = (UINT8)(strength*25.5f);
if (HWR_ShouldUsePaletteRendering())
Surf.PolyColor.s.alpha = softwaretranstogl[strength];
else
Surf.PolyColor.s.alpha = (UINT8)(strength*25.5f);
}
HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false);
@@ -748,9 +749,10 @@ void HWR_drawAMline(const fline_t *fl, INT32 color)
{
F2DCoord v1, v2;
RGBA_t color_rgba;
color_rgba = V_GetColor(color);
RGBA_t *palette = HWR_GetTexturePalette();
color_rgba = palette[color&0xFF];
v1.x = ((float)fl->a.x-(vid.width/2.0f))*(2.0f/vid.width);
v1.y = ((float)fl->a.y-(vid.height/2.0f))*(2.0f/vid.height);
@@ -768,6 +770,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color)
FOutVector v[4];
FSurfaceInfo Surf;
float fx, fy, fw, fh, fwait = 0;
RGBA_t *palette = HWR_GetTexturePalette();
if (wh < 0)
return; // consistency w/ software
@@ -848,7 +851,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color)
v[0].t = v[1].t = 0.0f;
v[2].t = v[3].t = 1.0f;
Surf.PolyColor = V_GetColor(color);
Surf.PolyColor = palette[color&0xFF];
HWD.pfnDrawPolygon(&Surf, v, 4,
PF_Modulated|PF_NoTexture|PF_NoDepthTest, false);
@@ -862,6 +865,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32
FOutVector v[4];
FSurfaceInfo Surf;
float fx, fy, fw, fh;
RGBA_t *palette = HWR_GetTexturePalette();
if (w < 0 || h < 0)
return; // consistency w/ software
@@ -882,7 +886,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32
if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT)
{
RGBA_t rgbaColour = V_GetColor(color);
RGBA_t rgbaColour = palette[color&0xFF];
FRGBAFloat clearColour;
clearColour.red = (float)rgbaColour.s.red / 255;
clearColour.green = (float)rgbaColour.s.green / 255;
@@ -972,6 +976,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color)
FSurfaceInfo Surf;
float fx, fy, fw, fh;
UINT8 alphalevel = ((color & V_ALPHAMASK) >> V_ALPHASHIFT);
RGBA_t *palette = HWR_GetTexturePalette();
if (w < 0 || h < 0)
return; // consistency w/ software
@@ -992,7 +997,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color)
if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT)
{
RGBA_t rgbaColour = V_GetColor(color);
RGBA_t rgbaColour = palette[color&0xFF];
FRGBAFloat clearColour;
clearColour.red = (float)rgbaColour.s.red / 255;
clearColour.green = (float)rgbaColour.s.green / 255;
@@ -1066,7 +1071,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color)
v[0].t = v[1].t = 0.0f;
v[2].t = v[3].t = 1.0f;
Surf.PolyColor = V_GetColor(color);
Surf.PolyColor = palette[color&0xFF];
if (alphalevel)
{
@@ -1074,10 +1079,9 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color)
else if (alphalevel == 14) Surf.PolyColor.s.alpha = softwaretranstogl[hudtrans];
else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[hudtrans];
else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel];
HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false);
}
else
HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_NoTexture|PF_NoDepthTest, false);
HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false);
}
#ifdef HAVE_PNG
+10 -12
View File
@@ -29,11 +29,7 @@
EXPORT boolean HWRAPI(Init) (void);
EXPORT void HWRAPI(SetupGLInfo) (void);
#if defined (PURESDL) || defined (macintosh)
EXPORT void HWRAPI(SetPalette) (INT32 *);
#else
EXPORT void HWRAPI(SetPalette) (RGBA_t *ppal);
#endif
EXPORT void HWRAPI(SetTexturePalette) (RGBA_t *ppal);
EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl);
EXPORT void HWRAPI(Draw2DLine) (F2DCoord *v1, F2DCoord *v2, RGBA_t Color);
EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, boolean horizonSpecial);
@@ -84,9 +80,10 @@ EXPORT boolean HWRAPI(InitCustomShaders) (void);
EXPORT void HWRAPI(StartBatching) (void);
EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors);
EXPORT void HWRAPI(InitPalette) (int flashnum, boolean skiplut);
EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable);
EXPORT void HWRAPI(ClearLightTableCache) (void);
EXPORT void HWRAPI(SetPaletteLookup)(UINT8 *lut);
EXPORT UINT32 HWRAPI(CreateLightTable)(RGBA_t *hw_lighttable);
EXPORT void HWRAPI(ClearLightTables)(void);
EXPORT void HWRAPI(SetScreenPalette)(RGBA_t *palette);
// ==========================================================================
// HWR DRIVER OBJECT, FOR CLIENT PROGRAM
@@ -98,7 +95,7 @@ struct hwdriver_s
{
Init pfnInit;
SetupGLInfo pfnSetupGLInfo;
SetPalette pfnSetPalette;
SetTexturePalette pfnSetTexturePalette;
FinishUpdate pfnFinishUpdate;
Draw2DLine pfnDraw2DLine;
DrawPolygon pfnDrawPolygon;
@@ -139,9 +136,10 @@ struct hwdriver_s
StartBatching pfnStartBatching;
RenderBatches pfnRenderBatches;
InitPalette pfnInitPalette;
AddLightTable pfnAddLightTable;
ClearLightTableCache pfnClearLightTableCache;
SetPaletteLookup pfnSetPaletteLookup;
CreateLightTable pfnCreateLightTable;
ClearLightTables pfnClearLightTables;
SetScreenPalette pfnSetScreenPalette;
};
extern struct hwdriver_s hwdriver;
+5
View File
@@ -68,6 +68,11 @@ void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap);
void HWR_MakePatch(patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap);
void HWR_UnlockCachedPatch(GLPatch_t *gpatch);
void HWR_SetPalette(RGBA_t *palette);
void HWR_SetMapPalette(void);
UINT32 HWR_CreateLightTable(UINT8 *lighttable);
UINT32 HWR_GetLightTableID(extracolormap_t *colormap);
void HWR_ClearLightTables(void);
GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wad, UINT16 lump);
GLPatch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum);
void HWR_GetFadeMask(lumpnum_t fademasklumpnum);
+100 -61
View File
@@ -57,6 +57,12 @@
// ==========================================================================
struct hwdriver_s hwdriver;
boolean gr_shadersavailable = true;
// Whether the internal state is set to palette rendering or not.
static boolean gr_palette_rendering_state = false;
// ==========================================================================
// Commands and console variables
// ==========================================================================
@@ -66,6 +72,8 @@ static void CV_anisotropic_ONChange(void);
static void CV_screentextures_ONChange(void);
static void CV_useCustomShaders_ONChange(void);
static void CV_grshaders_OnChange(void);
static void CV_grpaletterendering_OnChange(void);
static void CV_grpalettedepth_OnChange(void);
static CV_PossibleValue_t grfakecontrast_cons_t[] = {{0, "Off"}, {1, "Standard"}, {2, "Smooth"}, {0, NULL}};
@@ -115,7 +123,6 @@ consvar_t cv_secbright = {"secbright", "0", CV_SAVE, secbright_cons_t,
consvar_t cv_grfovchange = {"gr_fovchange", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_grvhseffect = {"gr_vhseffect", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
// values for the far clipping plane
static float clipping_distances[] = {1024.0f, 2048.0f, 4096.0f, 6144.0f, 8192.0f, 12288.0f, 16384.0f};
@@ -138,7 +145,10 @@ consvar_t cv_grscreentextures = {"gr_screentextures", "On", CV_CALL|CV_SAVE, CV_
consvar_t cv_grshaders = {"gr_shaders", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_grusecustomshaders = {"gr_usecustomshaders", "Yes", CV_CALL|CV_SAVE, CV_OnOff, CV_useCustomShaders_ONChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_grpaletteshader = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_grpaletterendering = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grpaletterendering_OnChange, 0, NULL, NULL, 0, 0, NULL};
static CV_PossibleValue_t glpalettedepth_cons_t[] = {{16, "16 bits"}, {24, "24 bits"}, {0, NULL}};
consvar_t cv_grpalettedepth = {"gr_palettedepth", "16 bits", CV_SAVE|CV_CALL, glpalettedepth_cons_t, CV_grpalettedepth_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_grflashpal = {"gr_flashpal", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL};
@@ -171,32 +181,34 @@ static void CV_screentextures_ONChange(void)
static void CV_grshaders_OnChange(void)
{
if (rendermode == render_opengl)
if ((rendermode == render_opengl) && (cv_grpaletterendering.value))
{
if (HWR_ShouldUsePaletteRendering())
HWR_InitPalette(0, false);
HWD.pfnSetSpecialState(HWD_PAL_SHADER, HWR_ShouldUsePaletteRendering());
V_SetPalette(0);
// can't do palette rendering without shaders, so update the state if needed
HWR_TogglePaletteRendering();
}
}
static void CV_useCustomShaders_ONChange(void)
static void CV_useCustomShaders_ONChange(void) // should we do a call to HWR_TogglePaletteRendering here aswell in pal rendering mode?
{
if (rendermode == render_opengl)
{
if (HWR_UseShader())
HWD.pfnInitCustomShaders();
if (HWR_ShouldUsePaletteRendering())
HWR_InitPalette(0, false);
}
}
void HWR_InitPalette(int flashnum, boolean skiplut)
static void CV_grpaletterendering_OnChange(void)
{
HWD.pfnInitPalette(flashnum, skiplut);
if ((rendermode == render_opengl) && (gr_shadersavailable))
{
HWR_TogglePaletteRendering();
}
}
static void CV_grpalettedepth_OnChange(void)
{
if ((rendermode == render_opengl) && (HWR_ShouldUsePaletteRendering()))
HWR_SetPalette(pLocalPalette);
}
// ==========================================================================
@@ -230,8 +242,6 @@ static sector_t *gr_backsector;
static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags);
boolean gr_shadersavailable = true;
// Performance stats
ps_metric_t ps_hw_nodesorttime = {0};
ps_metric_t ps_hw_nodedrawtime = {0};
@@ -429,18 +439,17 @@ boolean HWR_UseShader(void)
boolean HWR_ShouldUsePaletteRendering(void)
{
return (cv_grpaletteshader.value && HWR_UseShader());
return (cv_grpaletterendering.value && HWR_UseShader());
}
boolean HWR_PalRenderFlashpal(void)
{
return (cv_grpaletteshader.value && HWR_UseShader() && cv_grflashpal.value);
return (cv_grpaletterendering.value && HWR_UseShader() && cv_grflashpal.value);
}
void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap)
{
RGBA_t poly_color, tint_color, fade_color;
boolean default_colormap = false;
poly_color.rgba = 0xFFFFFFFF;
tint_color.rgba = (colormap != NULL) ? (UINT32)colormap->rgba : GL_DEFAULTMIX;
@@ -494,35 +503,9 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col
Surface->LightInfo.fade_end = (colormap != NULL) ? colormap->fadeend : 31;
if (HWR_ShouldUsePaletteRendering())
{
if (!colormap)
{
colormap = &extra_colormaps[num_extra_colormaps];
default_colormap = true;
}
if (!colormap->gl_lighttable_id)
{
UINT8 *colormap_pointer;
if (default_colormap)
{
colormap_pointer = colormaps;
}
else
{
colormap_pointer = colormap->colormap;
}
colormap->gl_lighttable_id = HWD.pfnAddLightTable(colormap_pointer);
}
Surface->LightTableId = colormap->gl_lighttable_id;
}
}
void HWR_ClearLightTableCache(void)
{
if (rendermode == render_opengl)
HWD.pfnClearLightTableCache();
Surface->LightTableId = HWR_GetLightTableID(colormap);
else
Surface->LightTableId = 0;
}
UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if this can work
@@ -2875,8 +2858,8 @@ void HWR_AddLine(seg_t *line)
}
// OPTIMIZE: quickly reject orthogonal back sides.
angle1 = R_PointToAngleEx64(viewx, viewy, v1x, v1y);
angle2 = R_PointToAngleEx64(viewx, viewy, v2x, v2y);
angle1 = R_PointToAngle64(v1x, v1y);
angle2 = R_PointToAngle64(v2x, v2y);
// do an extra culling check when rendering portals
// check if any line vertex is on the viewable side of the portal target line
@@ -3069,8 +3052,8 @@ boolean HWR_CheckBBox(fixed_t *bspcoord)
if (mindist > current_bsp_culling_distance) return false;
}
angle1 = R_PointToAngleEx64(viewx, viewy, px1, py1);
angle2 = R_PointToAngleEx64(viewx, viewy, px2, py2);
angle1 = R_PointToAngle64(px1, py1);
angle2 = R_PointToAngle64(px2, py2);
return gld_clipper_SafeCheckRange(angle2, angle1);
}
@@ -5929,8 +5912,8 @@ static void HWR_PortalClipping(gl_portal_t *portal)
line_t *line = &lines[portal->clipline];
angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y);
angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y);
angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y);
angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y);
// clip things that are not inside the portal window from our viewpoint
gld_clipper_SafeAddClipRange(angle2, angle1);
@@ -6160,6 +6143,20 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox)
gr_windowcenterx += gr_viewwidth;
}
if (splitscreen == 2 && player == &players[displayplayers[2]])
{
// V_DrawPatchFill, but for the fourth screen only
GLPatch_t *gpatch = W_CachePatchName("SRB2BACK", PU_CACHE);
INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy);
INT32 x, y, pw = SHORT(gpatch->width) * dupz, ph = SHORT(gpatch->height) * dupz;
for (x = vid.width>>1; x < vid.width; x += pw)
{
for (y = vid.height>>1; y < vid.height; y += ph)
HWR_DrawStretchyFixedPatch(gpatch, (x)<<FRACBITS, (y)<<FRACBITS, FRACUNIT, FRACUNIT, V_NOSCALESTART, NULL);
}
}
// check for new console commands.
NetUpdate();
@@ -6312,8 +6309,50 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
HWR_RenderFrame(viewnumber, player, false);
}
// enable or disable palette rendering state depending on settings and availability
// called when relevant settings change
// shader recompilation is done in the cvar callback
void HWR_TogglePaletteRendering(void)
{
// which state should we go to?
if (HWR_ShouldUsePaletteRendering())
{
// are we not in that state already?
if (!gr_palette_rendering_state)
{
gr_palette_rendering_state = true;
// The textures will still be converted to RGBA by r_opengl.
// This however makes hw_cache use paletted blending for composite textures!
// (patchformat is not touched)
textureformat = GR_TEXFMT_P_8;
HWR_SetMapPalette();
HWR_SetPalette(pLocalPalette);
// If the r_opengl "texture palette" stays the same during this switch, these textures
// will not be cleared out. However they are still out of date since the
// composite texture blending method has changed. Therefore they need to be cleared.
//HWD.pfnClearMipMapCache();
HWR_PrepLevelCache(numtextures);
}
}
else
{
// are we not in that state already?
if (gr_palette_rendering_state)
{
gr_palette_rendering_state = false;
textureformat = GR_RGBA;
HWR_SetPalette(pLocalPalette);
// If the r_opengl "texture palette" stays the same during this switch, these textures
// will not be cleared out. However they are still out of date since the
// composite texture blending method has changed. Therefore they need to be cleared.
//HWD.pfnClearMipMapCache();
HWR_PrepLevelCache(numtextures);
}
}
}
//added by Hurdler: console varibale that are saved
void HWR_AddCommands(void)
@@ -6356,10 +6395,9 @@ void HWR_AddCommands(void)
CV_RegisterVar(&cv_secbright);
CV_RegisterVar(&cv_grpaletteshader);
CV_RegisterVar(&cv_grpaletterendering);
CV_RegisterVar(&cv_grpalettedepth);
CV_RegisterVar(&cv_grflashpal);
CV_RegisterVar(&cv_grvhseffect);
}
// --------------------------------------------------------------------------
@@ -6373,21 +6411,22 @@ void HWR_Startup(void)
if (!startupdone)
{
CONS_Printf("HWR_Startup()...\n");
textureformat = patchformat = GR_RGBA;
HWR_InitTextureCache();
HWR_InitMD2();
HWD.pfnSetupGLInfo();
}
if (rendermode == render_opengl)
textureformat = patchformat = GR_RGBA;
startupdone = true;
// jimita
HWD.pfnKillShaders();
if (!HWD.pfnLoadShaders())
gr_shadersavailable = false;
HWR_TogglePaletteRendering();
if (msaa)
{
+5 -6
View File
@@ -92,6 +92,7 @@ void HWR_ClearClipper(void);
boolean HWR_UseShader(void);
boolean HWR_ShouldUsePaletteRendering(void);
boolean HWR_PalRenderFlashpal(void);
void HWR_TogglePaletteRendering(void);
// My original intention was to split hw_main.c
// into files like hw_bsp.c, hw_sprites.c...
@@ -114,7 +115,6 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum);
void HWR_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize);
void HWR_MakeScreenFinalTexture(void);
void HWR_DrawScreenFinalTexture(int width, int height);
void HWR_InitPalette(int flashnum, boolean skiplut);
// hw_main.c: Planes
void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap);
@@ -148,8 +148,6 @@ void HWR_AddLine(seg_t *line);
boolean HWR_CheckBBox(fixed_t *bspcoord);
void HWR_RenderDrawNodes(void);
void HWR_ClearLightTableCache(void);
// hw_main.c: Sprites
void HWR_AddSprites(sector_t *sec);
void HWR_ProjectSprite(mobj_t *thing);
@@ -162,6 +160,7 @@ extern boolean gr_maphasportals;
// hw_cache.c
void HWR_PrepLevelCache(size_t pnumtextures);
RGBA_t *HWR_GetTexturePalette(void);
// hw_trick.c
void HWR_CorrectSWTricks(void);
@@ -189,13 +188,13 @@ extern consvar_t cv_grfallbackplayermodel;
extern consvar_t cv_grbatching;
extern consvar_t cv_grrenderdistance;
extern consvar_t cv_grusecustomshaders;
extern consvar_t cv_grpaletteshader;
extern consvar_t cv_grscreentextures;
extern consvar_t cv_grpaletterendering;
extern consvar_t cv_grpalettedepth;
extern consvar_t cv_grflashpal;
extern consvar_t cv_grscreentextures;
extern consvar_t cv_grportals;
extern consvar_t cv_nostencil;
extern consvar_t cv_secbright;
extern consvar_t cv_grvhseffect;
extern CV_PossibleValue_t granisotropicmode_cons_t[];
+223 -299
View File
@@ -27,9 +27,6 @@
#include "r_opengl.h"
#include "r_vbo.h"
#include "../../v_video.h" // pLocalPalette
#include "../../r_data.h" // NearestColor
//#include "../../p_tick.h" // for leveltime (NOTE: THIS IS BAD, FIGURE OUT HOW TO PROPERLY IMPLEMENT gl_leveltime)
#include "../../i_system.h" // for I_GetPreciseTime (batching time measurements)
@@ -51,13 +48,19 @@ struct GLRGBAFloat
};
typedef struct GLRGBAFloat GLRGBAFloat;
static const GLubyte white[4] = { 255, 255, 255, 255 };
// lighttable list item
struct LTListItem
{
UINT32 id;
struct LTListItem *next;
};
typedef struct LTListItem LTListItem;
// ==========================================================================
// CONSTANTS
// ==========================================================================
static const GLubyte white[4] = { 255, 255, 255, 255 };
// With OpenGL 1.1+, the first texture should be 1
#define NOTEXTURE_NUM 0
@@ -74,24 +77,26 @@ static float NEAR_CLIPPING_PLANE = NZCLIP_PLANE;
// GLOBALS
// **************************************************************************
static GLuint tex_downloaded = 0;
// these didnt work with karts batching system, hope this is not an issue
//static GLuint lt_downloaded = 0; // currently bound lighttable texture - currentSurfaceInfo
//static GLuint lt_downloaded2 = 0; // currently bound lighttable texture - nextSurfaceInfo
//static GLuint lt_downloaded3 = 0; // currently bound lighttable texture - pSurf
static GLfloat fov = 90.0f;
static FBITFIELD CurrentPolyFlags;
static FTextureInfo *gr_cachetail = NULL;
static FTextureInfo *gr_cachehead = NULL;
typedef struct LightTableCacheEntry_s
{
GLuint id;
struct LightTableCacheEntry_s *next;
} LightTableCacheEntry_t;
// Linked list of all lighttables.
static LTListItem *LightTablesTail = NULL;
static LTListItem *LightTablesHead = NULL;
LightTableCacheEntry_t *ltcachehead = NULL;
LightTableCacheEntry_t *ltcachetail = NULL;
static RGBA_t screenPalette[256] = {0}; // the palette for the postprocessing step in palette rendering
static GLuint screenPaletteTex = 0; // 1D texture containing the screen palette
static GLuint paletteLookupTex = 0; // 3D texture containing RGB -> palette index lookup table
RGBA_t myPaletteData[256]; // the palette for converting textures to RGBA
RGBA_t myPaletteData[256];
GLint screen_width = 0; // used by Draw2DLine()
GLint screen_height = 0;
GLbyte screen_depth = 0;
@@ -198,7 +203,6 @@ FUNCPRINTF void GL_DBG_Printf(const char *format, ...)
#endif
}
// -----------------+
// GL_MSG_Warning : Raises a warning.
// :
@@ -250,7 +254,6 @@ static void GL_MSG_Error(const char *format, ...)
#endif
}
#ifdef STATIC_OPENGL
/* 1.0 functions */
/* Miscellaneous */
@@ -429,10 +432,10 @@ typedef void (APIENTRY * PFNglTexEnvi) (GLenum target, GLenum pname, GLint param
static PFNglTexEnvi pglTexEnvi;
typedef void (APIENTRY * PFNglTexParameteri) (GLenum target, GLenum pname, GLint param);
static PFNglTexParameteri pglTexParameteri;
typedef void (APIENTRY * PFNglTexImage1D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
static PFNglTexImage1D pglTexImage1D;
typedef void (APIENTRY * PFNglTexImage2D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
static PFNglTexImage2D pglTexImage2D;
typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
static PFNglTexImage3D pglTexImage3D;
typedef void (APIENTRY * PFNglTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
static PFNglTexSubImage2D pglTexSubImage2D;
@@ -461,6 +464,10 @@ typedef void (APIENTRY * PFNglGenerateMipmap) (GLenum target);
static PFNglGenerateMipmap pglGenerateMipmap;
#endif
/* 1.2 functions for 3D textures */
typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
static PFNglTexImage3D pglTexImage3D;
/* 1.3 functions for multitexturing */
typedef void (APIENTRY *PFNglActiveTexture) (GLenum);
static PFNglActiveTexture pglActiveTexture;
@@ -560,6 +567,7 @@ boolean SetupGLfunc(void)
GETOPENGLFUNC(pglTexEnvi, glTexEnvi)
GETOPENGLFUNC(pglTexParameteri, glTexParameteri)
GETOPENGLFUNC(pglTexImage1D, glTexImage1D)
GETOPENGLFUNC(pglTexImage2D, glTexImage2D)
GETOPENGLFUNC(pglTexSubImage2D , glTexSubImage2D)
@@ -594,7 +602,6 @@ typedef void (APIENTRY *PFNglLinkProgram) (GLuint);
typedef void (APIENTRY *PFNglGetProgramiv) (GLuint, GLenum, GLint*);
typedef void (APIENTRY *PFNglUseProgram) (GLuint);
typedef void (APIENTRY *PFNglUniform1i) (GLint, GLint);
typedef void (APIENTRY *PFNglUniform1iv) (GLint, GLsizei, const GLint*);
typedef void (APIENTRY *PFNglUniform1f) (GLint, GLfloat);
typedef void (APIENTRY *PFNglUniform2f) (GLint, GLfloat, GLfloat);
typedef void (APIENTRY *PFNglUniform3f) (GLint, GLfloat, GLfloat, GLfloat);
@@ -616,7 +623,6 @@ static PFNglLinkProgram pglLinkProgram;
static PFNglGetProgramiv pglGetProgramiv;
static PFNglUseProgram pglUseProgram;
static PFNglUniform1i pglUniform1i;
static PFNglUniform1iv pglUniform1iv;
static PFNglUniform1f pglUniform1f;
static PFNglUniform2f pglUniform2f;
static PFNglUniform3f pglUniform3f;
@@ -640,10 +646,6 @@ static boolean gl_shaderprogramchanged = true;
static boolean gl_batching = false;// are we currently collecting batches?
static GLint gl_palette[768];
boolean gl_palette_initialized = false;
static boolean gl_palshader = false;
static INT32 gl_enable_screen_textures = 1;
static GLint gl_portal_stencil_level = 0;
@@ -662,10 +664,10 @@ typedef enum
gluniform_fade_end,
// palette rendering
gluniform_palette,
gluniform_color_lookup,
gluniform_lighttable_tex,
gluniform_palette_tex, // 1d texture containing a palette
gluniform_palette_lookup_tex, // 3d texture containing the rgb->index lookup table
gluniform_lighttable_tex, // 2d texture containing a light table
// misc.
gluniform_leveltime,
@@ -759,6 +761,8 @@ static float shader_leveltime = 0;
"gl_FragColor = final_color;\n" \
"}\n"
// hand tuned adjustments for light level calculation
// do those even work correctly without the preprocessor?
#define GLSL_FLOOR_FUDGES \
"#define STARTMAP_FUDGE 1.06\n" \
"#define MULT_FUDGE 0.5\n" \
@@ -787,21 +791,19 @@ static float shader_leveltime = 0;
#define GLSL_SOFTWARE_PAL_UNIFORMS \
"uniform sampler2D tex;\n" \
"uniform sampler3D palette_lookup_tex;\n" \
"uniform sampler2D lighttable_tex;\n" \
"uniform sampler3D lookup_tex;\n" \
"uniform int palette[768];\n" \
"uniform vec4 poly_color;\n" \
"uniform float lighting;\n" \
#define GLSL_SOFTWARE_PAL_MAIN \
"void main(void) {\n" \
"vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \
"int tex_pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \
"float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \
"float z = gl_FragCoord.z / gl_FragCoord.w;\n" \
"int light_y = int(clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0));\n" \
"vec2 lighttable_coord = vec2((float(tex_pal_idx) + 0.5) / 256.0, (float(light_y) + 0.5) / 32.0);\n" \
"int final_idx = int(texture2D(lighttable_tex, lighttable_coord)[0] * 255.0);\n" \
"vec4 final_color = vec4(float(palette[final_idx*3])/255.0, float(palette[final_idx*3+1])/255.0, float(palette[final_idx*3+2])/255.0, 1.0);\n" \
"float light_y = clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0);\n" \
"vec2 lighttable_coord = vec2((tex_pal_idx + 0.5) / 256.0, (light_y + 0.5) / 32.0);\n" \
"vec4 final_color = texture2D(lighttable_tex, lighttable_coord);\n" \
"final_color.a = texel.a * poly_color.a;\n" \
"gl_FragColor = final_color;\n" \
"}\n"
@@ -856,7 +858,8 @@ static float shader_leveltime = 0;
"final_color.a = texel.a * poly_color.a;\n" \
"gl_FragColor = final_color;\n" \
"}\0"
//TODO: make this not a hacky copy of two shaders mixed together
#define GLSL_PALETTE_WATER_FRAGMENT_SHADER \
GLSL_FLOOR_FUDGES \
"const float freq = 0.025;\n" \
@@ -864,9 +867,8 @@ static float shader_leveltime = 0;
"const float speed = 2.0;\n" \
"const float pi = 3.14159;\n" \
"uniform sampler2D tex;\n" \
"uniform sampler3D palette_lookup_tex;\n" \
"uniform sampler2D lighttable_tex;\n" \
"uniform sampler3D lookup_tex;\n" \
"uniform int palette[768];\n" \
"uniform vec4 poly_color;\n" \
"uniform float lighting;\n" \
"uniform float leveltime;\n" \
@@ -877,16 +879,15 @@ static float shader_leveltime = 0;
"float sdistort = sin(a) * amp;\n" \
"float cdistort = cos(a) * amp;\n" \
"vec4 texel = texture2D(tex, vec2(gl_TexCoord[0].s - sdistort, gl_TexCoord[0].t - cdistort));\n" \
"int tex_pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \
"float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \
"float z = gl_FragCoord.z / gl_FragCoord.w;\n" \
"int light_y = int(clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0));\n" \
"vec2 lighttable_coord = vec2((float(tex_pal_idx) + 0.5) / 256.0, (float(light_y) + 0.5) / 32.0);\n" \
"int final_idx = int(texture2D(lighttable_tex, lighttable_coord)[0] * 255.0);\n" \
"vec4 final_color = vec4(float(palette[final_idx*3])/255.0, float(palette[final_idx*3+1])/255.0, float(palette[final_idx*3+2])/255.0, 1.0);\n" \
"float light_y = clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0);\n" \
"vec2 lighttable_coord = vec2((tex_pal_idx + 0.5) / 256.0, (light_y + 0.5) / 32.0);\n" \
"vec4 final_color = texture2D(lighttable_tex, lighttable_coord);\n" \
"final_color.a = texel.a * poly_color.a;\n" \
"gl_FragColor = final_color;\n" \
"}\0"
//
// Fog block shader
//
@@ -916,12 +917,14 @@ static float shader_leveltime = 0;
#define GLSL_PALETTE_FRAGMENT_SHADER \
"uniform sampler2D tex;\n" \
"uniform sampler3D lookup_tex;\n" \
"uniform int palette[768];\n" \
"uniform sampler3D palette_lookup_tex;\n" \
"uniform sampler1D palette_tex;\n" \
"void main(void) {\n" \
"vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \
"int pal_idx = int(texture3D(lookup_tex, vec3((63.0/64.0) * texel + 1.0 / 128.0))[0] * 255.0);\n" \
"gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \
"vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \
"float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \
"float palette_coord = (tex_pal_idx + 0.5) / 256.0;\n" \
"vec4 final_color = texture1D(palette_tex, palette_coord);\n" \
"gl_FragColor = final_color;\n" \
"}\0"
//
@@ -1019,8 +1022,14 @@ static const char *vertex_shaders[] = {
// Palette vertex shader
GLSL_DEFAULT_VERTEX_SHADER,
// Palette floor vertex shader
GLSL_DEFAULT_VERTEX_SHADER,
// Palette wall vertex shader
GLSL_DEFAULT_VERTEX_SHADER,
// Palette water vertex shader
GLSL_DEFAULT_VERTEX_SHADER,
NULL,
@@ -1030,7 +1039,9 @@ static const char *vertex_shaders[] = {
void SetupGLFunc4(void)
{
/* 1.2 funcs */
pglTexImage3D = GetGLFunc("glTexImage3D");
/* 1.3 funcs */
pglActiveTexture = GetGLFunc("glActiveTexture");
pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f");
pglClientActiveTexture = GetGLFunc("glClientActiveTexture");
@@ -1057,7 +1068,6 @@ void SetupGLFunc4(void)
pglGetProgramiv = GetGLFunc("glGetProgramiv");
pglUseProgram = GetGLFunc("glUseProgram");
pglUniform1i = GetGLFunc("glUniform1i");
pglUniform1iv = GetGLFunc("glUniform1iv");
pglUniform1f = GetGLFunc("glUniform1f");
pglUniform2f = GetGLFunc("glUniform2f");
pglUniform3f = GetGLFunc("glUniform3f");
@@ -1199,14 +1209,13 @@ EXPORT boolean HWRAPI(LoadShaders) (void)
shader->uniforms[gluniform_fade_start] = GETUNI("fade_start");
shader->uniforms[gluniform_fade_end] = GETUNI("fade_end");
// misc. (custom shaders)
shader->uniforms[gluniform_leveltime] = GETUNI("leveltime");
// palette rendering
shader->uniforms[gluniform_palette] = GETUNI("palette");
shader->uniforms[gluniform_color_lookup] = GETUNI("lookup_tex");
shader->uniforms[gluniform_palette_tex] = GETUNI("palette_tex");
shader->uniforms[gluniform_palette_lookup_tex] = GETUNI("palette_lookup_tex");
shader->uniforms[gluniform_lighttable_tex] = GETUNI("lighttable_tex");
// misc.
shader->uniforms[gluniform_leveltime] = GETUNI("leveltime");
#undef GETUNI
// set permanent uniform values
@@ -1214,22 +1223,18 @@ EXPORT boolean HWRAPI(LoadShaders) (void)
if (uniform != -1) \
function (uniform, a);
#define UNIFORM_2(uniform, a, b, function) \
if (uniform != -1) \
function (uniform, a, b);
pglUseProgram(shader->program);
// texture unit numbers for the samplers used for palette rendering
UNIFORM_2(shader->uniforms[gluniform_palette], 768, gl_palette, pglUniform1iv);
UNIFORM_1(shader->uniforms[gluniform_color_lookup], 1, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_palette_tex], 2, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_palette_lookup_tex], 1, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i);
pglUseProgram(0);
// restore gl shader state
//pglUseProgram(gl_shaderstate.program);
pglUseProgram(gl_currentshaderprogram);
//pglUseProgram(0); // dont remember why this was here in the first place, but seems fine?
#undef UNIFORM_1
#undef UNIFORM_2
}
#endif
return true;
@@ -1334,117 +1339,6 @@ EXPORT void HWRAPI(KillShaders) (void)
// unused.........................
}
GLuint palette_tex_num;
// length of one side of lookup texture
// smallest separation between all the colors in the srb2 palette is 6, so
// possibly a 64x64x64 lookup texture might be enough for 100% correct colors
// (min separation for 64^3 size is 4)
#define LUT_SIZE 64
#define STEP_SIZE (256/LUT_SIZE)
// the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed!
// the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed!
EXPORT void HWRAPI(InitPalette) (int flashnum, boolean skiplut)
{
int i, r, g, b;
// init the palette
int flashoffset = flashnum*256;
for (i = 0+flashoffset; i < 256+flashoffset; i++)
{
int fi = i-flashoffset;
// crush to 16-bit rgb565, like software currently does
float fred = (float)(pLocalPalette[i].s.red >> 3);
float fgreen = (float)(pLocalPalette[i].s.green >> 2);
float fblue = (float)(pLocalPalette[i].s.blue >> 3);
// restore to rgb888
gl_palette[fi*3] = (GLint)(fred / 31.0f * 255.0f);
gl_palette[fi*3+1] = (GLint)(fgreen / 63.0f * 255.0f);
gl_palette[fi*3+2] = (GLint)(fblue / 31.0f * 255.0f);
}
if (!skiplut)
{
GLenum internalFormat;
if (gl_version[0] == '1' || gl_version[0] == '2')
{
// if the OpenGL version is below 3.0, then the GL_R8 format may not be available.
// so use GL_LUMINANCE8 instead to get a single component 8-bit format
// (it is possible to have access to shaders even in some OpenGL 1.x systems,
// so palette rendering can still possibly be achieved there)
internalFormat = GL_LUMINANCE8;
}
else
{
internalFormat = GL_R8;
}
// init the palette conversion lookup texture
GLubyte *pal_lookup_tex = malloc(LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(GLubyte));
if (!pal_lookup_tex)
I_Error("Failed to allocate memory for generating palette lookup texture.");
for (b = 0; b < LUT_SIZE; b++)
{
for (g = 0; g < LUT_SIZE; g++)
{
for (r = 0; r < LUT_SIZE; r++)
{
pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+0, g*STEP_SIZE+0, b*STEP_SIZE+0);
}
}
}
pglGenTextures(1, &palette_tex_num);
pglBindTexture(GL_TEXTURE_3D, palette_tex_num);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
if (!pglTexImage3D){
GL_MSG_Error("pglTexImage3D is NULL!");
CV_Set(&cv_grpaletteshader, "Off"); // turn that thing off if you cant use it
return;
}
pglTexImage3D(GL_TEXTURE_3D, 0, internalFormat, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex);
free(pal_lookup_tex);
}
#undef STEP_SIZE
pglUseProgram(gl_shaderprograms[8].program);
pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit
pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette);
// bind the palette to the fancy shader here
pglUseProgram(gl_shaderprograms[9].program);
pglUniform1iv(gl_shaderprograms[9].uniforms[gluniform_palette], 768, gl_palette);
// bind tex unit 2 to lighttable tex
pglUniform1i(gl_shaderprograms[9].uniforms[gluniform_lighttable_tex], 2);
pglUniform1i(gl_shaderprograms[9].uniforms[gluniform_color_lookup], 1);
// bind the palette to the fancy shader here
pglUseProgram(gl_shaderprograms[10].program);
pglUniform1iv(gl_shaderprograms[10].uniforms[gluniform_palette], 768, gl_palette);
// bind tex unit 2 to lighttable tex
pglUniform1i(gl_shaderprograms[10].uniforms[gluniform_lighttable_tex], 2);
pglUniform1i(gl_shaderprograms[10].uniforms[gluniform_color_lookup], 1);
// bind stuff to wöter shader
pglUseProgram(gl_shaderprograms[11].program);
pglUniform1iv(gl_shaderprograms[11].uniforms[gluniform_palette], 768, gl_palette);
pglUniform1i(gl_shaderprograms[11].uniforms[gluniform_lighttable_tex], 2);
pglUniform1i(gl_shaderprograms[11].uniforms[gluniform_color_lookup], 1);
pglUseProgram(0);
pglBindTexture(GL_TEXTURE_3D, 0);
// bind 3d lookup to unit 1, maybe it can stay there
pglActiveTexture(GL_TEXTURE1);
pglBindTexture(GL_TEXTURE_3D, palette_tex_num);
pglActiveTexture(GL_TEXTURE0);
gl_palette_initialized = true;
}
// -----------------+
// SetNoTexture : Disable texture
// -----------------+
@@ -1632,65 +1526,6 @@ EXPORT void HWRAPI(ClearMipMapCache) (void)
Flush();
}
EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable)
{
LightTableCacheEntry_t *cache_entry = malloc(sizeof(LightTableCacheEntry_t));
if (!ltcachetail)
{
ltcachehead = ltcachetail = cache_entry;
}
else
{
ltcachetail->next = cache_entry;
ltcachetail = cache_entry;
}
ltcachetail->next = NULL;
GLenum internalFormat;
if (gl_version[0] == '1' || gl_version[0] == '2')
{
// if the OpenGL version is below 3.0, then the GL_R8 format may not be available.
// so use GL_LUMINANCE8 instead to get a single component 8-bit format
// (it is possible to have access to shaders even in some OpenGL 1.x systems,
// so palette rendering can still possibly be achieved there)
internalFormat = GL_LUMINANCE8;
}
else
{
internalFormat = GL_R8;
}
pglGenTextures(1, &ltcachetail->id);
if (!ltcachetail->id){
GL_MSG_Error("HWR Lighttable cache entry id is zero");
CV_Set(&cv_grpaletteshader, "Off"); // turn that thing off if you cant use it
return;
}
pglBindTexture(GL_TEXTURE_2D, ltcachetail->id);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
pglTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 256, 32, 0, GL_RED, GL_UNSIGNED_BYTE, lighttable);
// restore previously bound texture
if (!gl_batching)
pglBindTexture(GL_TEXTURE_2D, tex_downloaded);
return ltcachetail->id;
}
// Delete light table textures, ids given before become invalid and must not be used.
EXPORT void HWRAPI(ClearLightTableCache) (void)
{
while (ltcachehead)
{
pglDeleteTextures(1, &ltcachehead->id);
LightTableCacheEntry_t *next = ltcachehead->next;
free(ltcachehead);
ltcachehead = next;
}
ltcachetail = NULL;
}
// -----------------+
// ReadRect : Read a rectangle region of the truecolor framebuffer
// : store pixels as 16bit 565 RGB
@@ -1801,9 +1636,6 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask,
pglClear(ClearMask);
pglEnableClientState(GL_VERTEX_ARRAY); // We always use this one
pglEnableClientState(GL_TEXTURE_COORD_ARRAY); // And mostly this one, too
if ((!gl_palette_initialized) && (gl_palshader))
InitPalette(0, false); // just gonna put this here for now
}
@@ -2020,6 +1852,8 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo)
w = pTexInfo->width;
h = pTexInfo->height;
if (w*h > 2048*2048 && pTexInfo->grInfo.format != GL_RGBA)
I_Error("Tried to convert too big texture: %dx%d", w, h);
if ((pTexInfo->grInfo.format == GR_TEXFMT_P_8) ||
(pTexInfo->grInfo.format == GR_TEXFMT_AP_88))
@@ -2377,7 +2211,7 @@ int finalVertexArrayAllocSize = 65536;
PolygonArrayEntry* polygonArray = NULL;// contains the polygon data from DrawPolygon, waiting to be processed
int polygonArraySize = 0;
PolygonArrayEntry **polygonArraySorted = NULL;// contains sorted pointers to polygonArray
UINT32* polygonIndexArray = NULL;// contains sorting pointers for polygonArray
int polygonArrayAllocSize = 65536;
FOutVector* unsortedVertexArray = NULL;// contains unsorted vertices and texture coordinates from DrawPolygon
@@ -2393,7 +2227,7 @@ EXPORT void HWRAPI(StartBatching) (void)
finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector));
finalVertexIndexArray = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32));
polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry));
polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *));
polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32));
unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector));
}
// drawing functions will now collect the drawing data instead of passing it to opengl
@@ -2403,8 +2237,10 @@ EXPORT void HWRAPI(StartBatching) (void)
static int comparePolygons(const void *p1, const void *p2)
{
PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1;
PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2;
unsigned int index1 = *(const unsigned int*)p1;
unsigned int index2 = *(const unsigned int*)p2;
PolygonArrayEntry* poly1 = &polygonArray[index1];
PolygonArrayEntry* poly2 = &polygonArray[index2];
int diff;
INT64 diff64;
@@ -2420,12 +2256,12 @@ static int comparePolygons(const void *p1, const void *p2)
// skywalls and horizon lines must retain their order for horizon lines to work
if (shader1 == -1 && shader2 == -1)
return poly1 - poly2;
return index1 - index2;
diff = poly1->texNum - poly2->texNum;
if (diff != 0) return diff;
if (gl_palshader)
if (HWR_ShouldUsePaletteRendering())
{
diff = poly1->surf.LightTableId - poly2->surf.LightTableId;
if (diff != 0) return diff;
@@ -2451,8 +2287,10 @@ static int comparePolygons(const void *p1, const void *p2)
static int comparePolygonsNoShaders(const void *p1, const void *p2)
{
PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1;
PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2;
unsigned int index1 = *(const unsigned int*)p1;
unsigned int index2 = *(const unsigned int*)p2;
PolygonArrayEntry* poly1 = &polygonArray[index1];
PolygonArrayEntry* poly2 = &polygonArray[index2];
int diff;
INT64 diff64;
@@ -2467,7 +2305,7 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2)
// skywalls and horizon lines must retain their order for horizon lines to work
if (texNum1 == 0 && texNum2 == 0)
return poly1 - poly2;
return index1 - index2;
diff = poly1->polyFlags - poly2->polyFlags;
if (diff != 0) return diff;
@@ -2484,7 +2322,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i
int finalVertexWritePos = 0;// position in finalVertexArray
int finalIndexWritePos = 0;// position in finalVertexIndexArray
int polygonReadPos = 0;// position in polygonArraySorted
int polygonReadPos = 0;// position in polygonIndexArray
GLuint currentShader;
GLuint currentTexture;
@@ -2510,19 +2348,19 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i
*sNumPolys = polygonArraySize;
*sNumCalls = *sNumVerts = 0;
*sNumShaders = *sNumTextures = *sNumPolyFlags = *sNumColors = 1;
// init polygonArraySorted
// init polygonIndexArray
for (i = 0; i < polygonArraySize; i++)
{
polygonArraySorted[i] = &polygonArray[i];
polygonIndexArray[i] = i;
}
// sort polygons
//CONS_Printf("qsort polys\n");
*sSortTime = I_GetPreciseTime();
if (gl_allowshaders)
qsort(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygons);
qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygons);
else
qsort(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygonsNoShaders);
qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygonsNoShaders);
*sSortTime = I_GetPreciseTime() - *sSortTime;
//CONS_Printf("sort done\n");
// sort order
@@ -2534,10 +2372,10 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i
*sDrawTime = I_GetPreciseTime();
currentShader = polygonArraySorted[0]->shader;
currentTexture = polygonArraySorted[0]->texNum;
currentPolyFlags = polygonArraySorted[0]->polyFlags;
currentSurfaceInfo = polygonArraySorted[0]->surf;
currentShader = polygonArray[polygonIndexArray[0]].shader;
currentTexture = polygonArray[polygonIndexArray[0]].texNum;
currentPolyFlags = polygonArray[polygonIndexArray[0]].polyFlags;
currentSurfaceInfo = polygonArray[polygonIndexArray[0]].surf;
// For now, will sort and track the colors. Vertex attributes could be used instead of uniforms
// and a color array could replace the color calls.
@@ -2568,11 +2406,14 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i
if (gl_allowshaders)
{
Shader_Load(&currentSurfaceInfo, &firstPoly, &firstTint, &firstFade);
if (gl_palshader)
//if (currentSurfaceInfo.LightTableId && currentSurfaceInfo.LightTableId != lt_downloaded)
if (HWR_ShouldUsePaletteRendering())
{
pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now
pglActiveTexture(GL_TEXTURE2);
pglBindTexture(GL_TEXTURE_2D, currentSurfaceInfo.LightTableId);
pglActiveTexture(GL_TEXTURE0);
//lt_downloaded = currentSurfaceInfo.LightTableId;
}
}
@@ -2615,8 +2456,8 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i
// reset write pos
// repeat loop
PolygonArrayEntry *entry = polygonArraySorted[polygonReadPos++];
int numVerts = entry->numVerts;
int index = polygonIndexArray[polygonReadPos++];
int numVerts = polygonArray[index].numVerts;
// before writing, check if there is enough room
// using 'while' instead of 'if' here makes sure that there will *always* be enough room.
// probably never will this loop run more than once though
@@ -2641,7 +2482,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i
}
//CONS_Printf("write verts to final\n");
// write the vertices of the polygon
memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[entry->vertsIndex],
memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[polygonArray[index].vertsIndex],
numVerts * sizeof(FOutVector));
// write the indexes, pointing to the fan vertexes but in triangles format
firstIndex = finalVertexWritePos;
@@ -2663,11 +2504,11 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i
{
//CONS_Printf("state change check\n");
// check if a state change is required, set the change bools and next vars
PolygonArrayEntry *nextEntry = polygonArraySorted[polygonReadPos];
nextShader = nextEntry->shader;
nextTexture = nextEntry->texNum;
nextPolyFlags = nextEntry->polyFlags;
nextSurfaceInfo = nextEntry->surf;
int nextIndex = polygonIndexArray[polygonReadPos];
nextShader = polygonArray[nextIndex].shader;
nextTexture = polygonArray[nextIndex].texNum;
nextPolyFlags = polygonArray[nextIndex].polyFlags;
nextSurfaceInfo = polygonArray[nextIndex].surf;
if (nextPolyFlags & PF_NoTexture)
nextTexture = 0;
if (currentShader != nextShader)
@@ -2685,7 +2526,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i
changeState = true;
changePolyFlags = true;
}
if (gl_allowshaders && gl_palshader)
if (gl_allowshaders && HWR_ShouldUsePaletteRendering())
{
if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba ||
currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba ||
@@ -2699,7 +2540,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i
changeSurfaceInfo = true;
}
}
else if ((gl_allowshaders) && (!gl_palshader))
else if ((gl_allowshaders) && (!HWR_ShouldUsePaletteRendering()))
{
if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba ||
currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba ||
@@ -2777,6 +2618,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i
fade.alpha = byte2float[nextSurfaceInfo.FadeColor.s.alpha];
Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade);
currentShader = nextShader;
changeShader = false;
@@ -2829,12 +2671,14 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i
fade.alpha = byte2float[nextSurfaceInfo.FadeColor.s.alpha];
Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade);
if (gl_palshader)
//if (nextSurfaceInfo.LightTableId && nextSurfaceInfo.LightTableId != lt_downloaded2)
if (HWR_ShouldUsePaletteRendering())
{
pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now
pglActiveTexture(GL_TEXTURE2);
pglBindTexture(GL_TEXTURE_2D, nextSurfaceInfo.LightTableId);
pglActiveTexture(GL_TEXTURE0);
//lt_downloaded2 = nextSurfaceInfo.LightTableId;
}
}
@@ -2872,8 +2716,8 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI
free(polygonArray);
polygonArray = new_array;
// also need to redo the index array, dont need to copy it though
free(polygonArraySorted);
polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *));
free(polygonIndexArray);
polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(unsigned int));
}
while (unsortedVertexArraySize + (int)iNumPts > unsortedVertexArrayAllocSize)
@@ -2939,13 +2783,15 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI
fade.green = byte2float[pSurf->FadeColor.s.green];
fade.blue = byte2float[pSurf->FadeColor.s.blue];
fade.alpha = byte2float[pSurf->FadeColor.s.alpha];
}
if (gl_palshader && gl_allowshaders)
{
pglActiveTexture(GL_TEXTURE2);
pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId);
pglActiveTexture(GL_TEXTURE0);
//if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded3)
if (HWR_ShouldUsePaletteRendering())
{
pglActiveTexture(GL_TEXTURE2);
pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId);
pglActiveTexture(GL_TEXTURE0);
//lt_downloaded3 = pSurf->LightTableId;
}
}
}
@@ -3289,10 +3135,6 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value)
break;
}
break;
case HWD_PAL_SHADER:
gl_palshader = Value;
break;
case HWD_SET_TEXTUREFILTERMODE:
switch (Value)
@@ -3934,6 +3776,8 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform)
if (shearing)
{
float dy = FIXED_TO_FLOAT(AIMINGTODY(stransform->viewaiming)) * 2; //screen_width/BASEVIDWIDTH;
if (stransform->flip)
dy *= -1.0f;
pglTranslatef(0.0f, -dy/BASEVIDHEIGHT, 0.0f);
}
@@ -4471,7 +4315,6 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height)
off[10] = -yoff;
off[11] = 1.0f;
fix[0] = 0.0f;
fix[1] = 0.0f;
fix[2] = 0.0f;
@@ -4486,19 +4329,14 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height)
clearColour.red = clearColour.green = clearColour.blue = 0;
clearColour.alpha = 1;
ClearBuffer(true, false, false, &clearColour);
if (gl_palshader)
{
SetBlend(PF_NoDepthTest);
pglBindTexture(GL_TEXTURE_2D, finalScreenTexture);
}
else
pglBindTexture(GL_TEXTURE_2D, finalScreenTexture);
if (gl_palshader)
{
if (HWR_ShouldUsePaletteRendering())
SetBlend(PF_NoDepthTest);
pglBindTexture(GL_TEXTURE_2D, finalScreenTexture);
if (HWR_ShouldUsePaletteRendering()) // still quite hacky, but the replacement code in i_video didnt work and killed performance instead. somehow need to figure out whats up with that.
pglUseProgram(gl_shaderprograms[8].program); // palette postprocess shader
pglActiveTexture(GL_TEXTURE2);
}
pglColor4ubv(white);
pglTexCoordPointer(2, GL_FLOAT, 0, fix);
@@ -4508,9 +4346,95 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height)
tex_downloaded = finalScreenTexture;
if (gl_palshader)
{
if (HWR_ShouldUsePaletteRendering())
pglUseProgram(0);
}
EXPORT void HWRAPI(SetPaletteLookup)(UINT8 *lut)
{
GLenum internalFormat;
if (gl_version[0] == '1' || gl_version[0] == '2')
{
// if the OpenGL version is below 3.0, then the GL_R8 format may not be available.
// so use GL_LUMINANCE8 instead to get a single component 8-bit format
// (it is possible to have access to shaders even in some OpenGL 1.x systems,
// so palette rendering can still possibly be achieved there)
internalFormat = GL_LUMINANCE8;
}
else
{
internalFormat = GL_R8;
}
if (!paletteLookupTex)
pglGenTextures(1, &paletteLookupTex);
pglActiveTexture(GL_TEXTURE1);
pglBindTexture(GL_TEXTURE_3D, paletteLookupTex);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
pglTexImage3D(GL_TEXTURE_3D, 0, internalFormat, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE,
0, GL_RED, GL_UNSIGNED_BYTE, lut); // should there be a safety guard here aswell as the old one had? cant really test since i dont have hardware which doesent support 3D textures
pglActiveTexture(GL_TEXTURE0);
}
EXPORT UINT32 HWRAPI(CreateLightTable)(RGBA_t *hw_lighttable)
{
LTListItem *item = malloc(sizeof(LTListItem));
if (!LightTablesTail)
{
LightTablesHead = LightTablesTail = item;
}
else
{
LightTablesTail->next = item;
LightTablesTail = item;
}
item->next = NULL;
pglGenTextures(1, &item->id);
pglBindTexture(GL_TEXTURE_2D, item->id);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
pglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, hw_lighttable);
// restore previously bound texture
pglBindTexture(GL_TEXTURE_2D, tex_downloaded);
return item->id;
}
// Delete light table textures, ids given before become invalid and must not be used.
EXPORT void HWRAPI(ClearLightTables)(void)
{
while (LightTablesHead)
{
LTListItem *item = LightTablesHead;
pglDeleteTextures(1, (GLuint *)&item->id);
LightTablesHead = item->next;
free(item);
}
LightTablesTail = NULL;
// we no longer have a bound light table (if we had one), we just deleted it!
//lt_downloaded = 0;
//lt_downloaded2 = 0;
//lt_downloaded3 = 0;
}
// This palette is used for the palette rendering postprocessing step.
EXPORT void HWRAPI(SetScreenPalette)(RGBA_t *palette)
{
if (memcmp(screenPalette, palette, sizeof(screenPalette)))
{
memcpy(screenPalette, palette, sizeof(screenPalette));
if (!screenPaletteTex)
pglGenTextures(1, &screenPaletteTex);
pglActiveTexture(GL_TEXTURE2);
pglBindTexture(GL_TEXTURE_1D, screenPaletteTex);
pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
pglTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, palette);
pglActiveTexture(GL_TEXTURE0);
}
}
-3
View File
@@ -133,7 +133,4 @@ typedef enum
GLF_NOTEXENV = 0x02,
} oglflags_t;
// in order for custom playpals n shit to work properly
extern boolean gl_palette_initialized;
#endif
+4 -4
View File
@@ -40,7 +40,7 @@ IMPL_HUD_OFFSET(item); // Item box
IMPL_HUD_OFFSET(time); // Time
IMPL_HUD_OFFSET(laps); // Number of laps
IMPL_HUD_OFFSET(dnft); // Countdown (did not finish timer)
IMPL_HUD_OFFSET(spdm); // Speedometer
IMPL_HUD_OFFSET(speed); // Speedometer
IMPL_HUD_OFFSET(posi); // Position in race
IMPL_HUD_OFFSET(face); // Mini rankings
IMPL_HUD_OFFSET(stcd); // Starting countdown
@@ -685,7 +685,7 @@ void K_RegisterKartStuff(void)
REG_HUD_OFFSET(time); // Time
REG_HUD_OFFSET(laps); // Number of laps
REG_HUD_OFFSET(dnft); // Countdown (did not finish timer)
REG_HUD_OFFSET(spdm); // Speedometer
REG_HUD_OFFSET(speed); // Speedometer
REG_HUD_OFFSET(posi); // Position in race
REG_HUD_OFFSET(face); // Mini rankings
REG_HUD_OFFSET(stcd); // Starting countdown
@@ -7451,8 +7451,8 @@ static void K_initKartHUD(void)
LAPS_X = 9 + cv_laps_xoffset.value; // 9
LAPS_Y = BASEVIDHEIGHT - 29 + cv_laps_yoffset.value; // 171
// Speedometer
SPDM_X = 9 + cv_spdm_xoffset.value; // 9
SPDM_Y = BASEVIDHEIGHT - 45 + cv_spdm_yoffset.value; // 155
SPDM_X = 9 + cv_speed_xoffset.value; // 9
SPDM_Y = BASEVIDHEIGHT - 45 + cv_speed_yoffset.value; // 155
// Position Number
POSI_X = BASEVIDWIDTH - 9 + cv_posi_xoffset.value; // 268
POSI_Y = BASEVIDHEIGHT - 9 + cv_posi_yoffset.value; // 138
+114
View File
@@ -11,6 +11,7 @@
/// \brief custom HUD rendering library for Lua scripting
#include "doomdef.h"
#include "fastcmp.h"
#ifdef HAVE_BLUA
#include "r_defs.h"
#include "r_local.h"
@@ -346,6 +347,118 @@ static int libd_cachePatch(lua_State *L)
return 1;
}
// this is structured like getSprite2Patch in vanilla 2.2
// v.getSpritePatch(skin, sprite, [frame, [angle, [rollangle]]])
static int libd_getSpritePatch(lua_State *L)
{
UINT32 i; // sprite prefix
INT32 skn = -1; // skin number
UINT32 frame = 0; // 'A'
UINT8 angle = 0;
spritedef_t *sprdef;
spriteframe_t *sprframe;
#ifdef ROTSPRITE
spriteinfo_t *sprinfo;
#endif
HUDONLY
// mashing together the stuff from getSprite2Patch:
// get skin first!
if (!lua_isnoneornil(L, 1)) // ONLY do this if we have a skin
{
if (lua_isnumber(L, 1)) // find skin by number
{
skn = lua_tonumber(L, 1);
if (skn < 0 || skn >= MAXSKINS)
return luaL_error(L, "skin number %d out of range (0 - %d)", skn, MAXSKINS-1);
if (skn >= numskins)
return 0;
}
else // find skin by name
{
const char *name = luaL_checkstring(L, 1);
for (skn = 0; skn < numskins; skn++)
if (fastcmp(skins[skn].name, name))
break;
if (skn >= numskins)
return 0;
}
}
lua_remove(L, 1); // remove skin now
if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR_THOK
{
i = lua_tonumber(L, 1);
if (i >= NUMSPRITES)
return 0;
}
else if (lua_isstring(L, 1)) // sprite prefix name given, e.g. "THOK"
{
const char *name = lua_tostring(L, 1);
for (i = 0; i < NUMSPRITES; i++)
if (fastcmp(name, sprnames[i]))
break;
if (i >= NUMSPRITES)
return 0;
}
else
return 0;
// get outta dodge if we're a playersprite and have no skin
if ((i == SPR_PLAY) && (skn < 0))
return luaL_error(L, "You must provide a skin for player sprites!");
if (skn < 0) // standard sprite
{
sprdef = &sprites[i];
sprinfo = &spriteinfo[i];
}
else // player skin
{
sprdef = &skins[skn].spritedef;
sprinfo = &skins[skn].sprinfo;
}
// set frame number
frame = luaL_optinteger(L, 2, 0);
frame &= FF_FRAMEMASK; // ignore any bits that are not the actual frame, just in case
if (frame >= sprdef->numframes)
return 0;
// set angle number
sprframe = &sprdef->spriteframes[frame];
angle = luaL_optinteger(L, 3, 1);
// convert WAD editor angle numbers (1-8) to internal angle numbers (0-7)
// keep 0 the same since we'll make it default to angle 1 (which is internally 0)
// in case somebody didn't know that angle 0 really just maps all 8 angles to the same patch
if (angle != 0)
angle--;
if (angle >= 8) // out of range?
angle = (angle & 7); // modulus angle by 8
// rotsprite?????
if (lua_isnumber(L, 4) && (cv_spriteroll.value))
{
angle_t rollangle = luaL_checkangle(L, 4);
INT32 rot = R_GetRollAngle(rollangle);
if (rot) {
patch_t *rotsprite = Patch_GetRotatedSprite(sprframe, frame, angle, sprframe->flip & (1<<angle), false, sprinfo, rot);
LUA_PushUserdata(L, rotsprite, META_PATCH);
lua_pushboolean(L, false);
lua_pushboolean(L, true);
return 3;
}
}
// push both the patch and its "flip" value
LUA_PushUserdata(L, W_CachePatchNum(sprframe->lumppat[angle], PU_STATIC), META_PATCH);
lua_pushboolean(L, (sprframe->flip & (1<<angle)) != 0);
return 2;
}
static int libd_draw(lua_State *L)
{
INT32 x, y, flags;
@@ -954,6 +1067,7 @@ static luaL_Reg lib_draw[] = {
{"drawPaddedNum", libd_drawPaddedNum},
{"drawPingNum", libd_drawPingNum},
{"drawFill", libd_drawFill},
{"getSpritePatch",libd_getSpritePatch},
{"fadeScreen", libd_fadeScreen},
{"drawString", libd_drawString},
{"drawKartString", libd_drawKartString},
+7 -13
View File
@@ -1492,8 +1492,7 @@ static menuitem_t OP_ExpOptionsMenu[] =
{IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 85},
{IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 95},
#ifdef HWRENDER
{IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 65},
{IT_STRING | IT_CVAR, NULL, "VHS effect", &cv_grvhseffect, 75},
{IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 75},
{IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 95},
{IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 105},
@@ -1507,15 +1506,14 @@ static const char* OP_ExpTooltips[] =
NULL,
"Should weather be interpolated? Weather should look about the\nsame but perform a bit better when disabled.",
"When weather is on this will cut the object amount used in half.",
"Show a VHS-like effect when the game is paused or youre rewinding replays.",
"Show a VHS-like effect when the game is paused\n or youre rewinding replays.",
"Hides 3DFloors which are not visible\npotentially resulting in a performance boost.",
"Hides Sprites which are not visible\npotentially resulting in a performance boost.",
#ifdef HWRENDER
"Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.",
"Show a VHS-like effect when the game is paused or youre rewinding replays.",
"Fixes issues that resulted in Textures sticking from the ground sometimes.\n This may be CPU heavy and result in worse performance in some cases.",
"Fixes issues that resulted in Textures sticking from the\nground sometimes.\nThis may be CPU heavy and result in worse performance in some cases.",
"Fixes issues that resulted in Textures not being properly skewed\n example: Fences on slopes that didnt show proper.\n This may be CPU heavy and result in worse performance in some cases.",
"Fixes issues that resulted in Textures on Floor over Floors ZFighting heavily.",
"Fixes issues that resulted in Textures on Floor over Floors\nZFighting heavily.",
"Toggle for FOF wall cutoff with slopes.",
#endif
};
@@ -1530,7 +1528,6 @@ enum
op_exp_sprclip,
#ifdef HWRENDER
op_exp_grscrtx,
op_exp_grvhs,
op_exp_spltwal,
op_exp_pegging,
op_exp_fofzfight,
@@ -1546,7 +1543,7 @@ static menuitem_t OP_OpenGLOptionsMenu[] =
{IT_STRING | IT_CVAR, NULL, "Fallback Player 3D Model", &cv_grfallbackplayermodel, 20},
{IT_STRING | IT_CVAR, NULL, "Shaders", &cv_grshaders, 25},
//{IT_STRING|IT_CVAR, NULL, "Use custom Shaders", &cv_grusecustomshaders, 35},
{IT_STRING | IT_CVAR, NULL, "Palette Rendering", &cv_grpaletteshader, 30},
{IT_STRING | IT_CVAR, NULL, "Palette Rendering", &cv_grpaletterendering, 30},
{IT_STRING | IT_CVAR, NULL, "Flashpals in Palette Renderer", &cv_grflashpal, 35},
{IT_STRING | IT_CVAR, NULL, "Min Shader Brightness", &cv_secbright, 40},
@@ -1579,7 +1576,6 @@ static const char* OP_OpenGLTooltips[] =
"Should sprites always face the camera?",
"Recreates the look of software mode camera perspective.",
"How far the game world should be drawn.",
"Gamma (brightness) of colors.",
};
#endif
@@ -2160,8 +2156,8 @@ static menuitem_t OP_HudOffsetMenu[] =
{IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_laps_yoffset, 60},
{IT_HEADER, NULL, "Speedometer", NULL, 70},
{IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_spdm_xoffset, 75},
{IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_spdm_yoffset, 80},
{IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_speed_xoffset, 75},
{IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_speed_yoffset, 80},
{IT_HEADER, NULL, "Mini Rankings", NULL, 90},
{IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_face_xoffset, 95},
@@ -4479,7 +4475,6 @@ void M_Init(void)
{
OP_VideoOptionsMenu[op_video_ogl].status = IT_DISABLED;
OP_ExpOptionsMenu[op_exp_grscrtx].status = IT_DISABLED;
OP_ExpOptionsMenu[op_exp_grvhs].status = IT_DISABLED;
OP_ExpOptionsMenu[op_exp_spltwal].status = IT_DISABLED;
OP_ExpOptionsMenu[op_exp_pegging].status = IT_DISABLED;
OP_ExpOptionsMenu[op_exp_fofzfight].status = IT_DISABLED;
@@ -4487,7 +4482,6 @@ void M_Init(void)
}
if (rendermode == render_opengl){
OP_ExpOptionsMenu[op_exp_vhs].status = IT_DISABLED;
OP_ExpOptionsMenu[op_exp_ffclip].status = IT_DISABLED;
OP_ExpOptionsMenu[op_exp_sprclip].status = IT_DISABLED;
}
+3 -1
View File
@@ -8308,6 +8308,8 @@ void P_MobjThinker(mobj_t *mobj)
}
P_MoveOrigin(mobj, destx, desty, mobj->target->z);
mobj->spriteyoffset = mobj->target->spriteyoffset;
mobj->spritexoffset = mobj->target->spritexoffset;
break;
}
case MT_ROCKETSNEAKER:
@@ -11507,7 +11509,7 @@ void P_SpawnMapThing(mapthing_t *mthing)
mobj = P_SpawnMobj(x, y, z, i);
if (!mobj || P_MobjWasRemoved(mobj)) {
CONS_Alert(CONS_WARNING, "Failed to spawn map thing #%d at %d, %d\n", mthing->type, x>>FRACBITS, y>>FRACBITS);
CONS_Alert(CONS_ERROR, "Failed to spawn map thing #%d at %d, %d. This will crash vanilla clients!\n", mthing->type, x>>FRACBITS, y>>FRACBITS);
return;
}
+4
View File
@@ -3148,7 +3148,11 @@ boolean P_SetupLevel(boolean skipprecip)
// Correct missing sidedefs & deep water trick
HWR_CorrectSWTricks();
HWR_CreatePlanePolygons((INT32)numnodes - 1);
if (HWR_ShouldUsePaletteRendering()) //unsure if this is the right place, but seems to work since we dont have HWR_LoadLevel like srb2
HWR_SetMapPalette();
}
#endif
// oh god I hope this helps
+5 -5
View File
@@ -39,7 +39,7 @@ INT32 doorclosed;
boolean R_NoEncore(sector_t *sector, boolean ceiling)
{
boolean invertencore = (GETSECSPECIAL(sector->special, 2) == 12);
boolean invertencore = (GETSECSPECIAL(sector->special, 2) == 15);
#if 0 // perfect implementation
INT32 val = GETSECSPECIAL(sector->special, 3);
if (val != 1 && val != 3 // spring panel
@@ -410,8 +410,8 @@ static void R_AddLine(seg_t *line)
return;
// big room fix
angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y);
angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y);
angle1 = R_PointToAngle64(line->v1->x, line->v1->y);
angle2 = R_PointToAngle64(line->v2->x, line->v2->y);
curline = line;
// Clip to view edges.
@@ -613,8 +613,8 @@ static boolean R_CheckBBox(const fixed_t *bspcoord)
check = checkcoord[boxpos];
// big room fix
angle1 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]) - viewangle;
angle2 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[2]], bspcoord[check[3]]) - viewangle;
angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle;
angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle;
if ((signed)angle1 < (signed)angle2)
{
+12 -6
View File
@@ -28,6 +28,7 @@
#ifdef HWRENDER
#include "hardware/hw_main.h"
#include "hardware/hw_glob.h" // HWR_ClearLightTables
#endif
#ifdef _WIN32
@@ -1139,8 +1140,9 @@ void R_ClearColormaps(void)
memset(extra_colormaps, 0, sizeof (extra_colormaps));
#ifdef HWRENDER
HWR_ClearLightTableCache();
#endif
if (rendermode == render_opengl)
HWR_ClearLightTables();
#endif
}
/*INT32 R_ColormapNumForName(char *name)
@@ -1412,16 +1414,20 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3)
// Thanks to quake2 source!
// utils3/qdata/images.c
UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b)
UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette)
{
int dr, dg, db;
int distortion, bestdistortion = 256 * 256 * 4, bestcolor = 0, i;
// Use local palette if none specified
if (palette == NULL)
palette = pLocalPalette;
for (i = 0; i < 256; i++)
{
dr = r - pLocalPalette[i].s.red;
dg = g - pLocalPalette[i].s.green;
db = b - pLocalPalette[i].s.blue;
dr = r - palette[i].s.red;
dg = g - palette[i].s.green;
db = b - palette[i].s.blue;
distortion = dr*dr + dg*dg + db*db;
if (distortion < bestdistortion)
{
+2 -1
View File
@@ -100,7 +100,8 @@ void R_MakeInvertmap(void);
#endif
const char *R_ColormapNameForNum(INT32 num);
UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b);
UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette);
#define NearestColor(r, g, b) NearestPaletteColor(r, g, b, NULL)
extern INT32 numtextures;
-1
View File
@@ -63,7 +63,6 @@ typedef struct
INT32 fadergba; // The colour the colourmaps fade to
lighttable_t *colormap;
#ifdef HWRENDER
// The id of the hardware lighttable. Zero means it does not exist yet.
+17 -26
View File
@@ -395,6 +395,23 @@ angle_t R_PointToAngle(fixed_t x, fixed_t y)
0;
}
// This version uses 64-bit variables to avoid overflows with large values.
angle_t R_PointToAngle64(INT64 x, INT64 y)
{
return (y -= viewy, (x -= viewx) || y) ?
x >= 0 ?
y >= 0 ?
(x > y) ? tantoangle[SlopeDivEx(y,x)] : // octant 0
ANGLE_90-tantoangle[SlopeDivEx(x,y)] : // octant 1
x > (y = -y) ? 0-tantoangle[SlopeDivEx(y,x)] : // octant 8
ANGLE_270+tantoangle[SlopeDivEx(x,y)] : // octant 7
y >= 0 ? (x = -x) > y ? ANGLE_180-tantoangle[SlopeDivEx(y,x)] : // octant 3
ANGLE_90 + tantoangle[SlopeDivEx(x,y)] : // octant 2
(x = -x) > (y = -y) ? ANGLE_180+tantoangle[SlopeDivEx(y,x)] : // octant 4
ANGLE_270-tantoangle[SlopeDivEx(x,y)] : // octant 5
0;
}
angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y)
{
return (y -= pviewy, (x -= pviewx) || y) ?
@@ -489,32 +506,6 @@ angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1)
0;
}
angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1)
{
INT64 dx = x1 - x2;
INT64 dy = y1 - y2;
// Check for potential overflow or underflow
if (dx < INT64_MIN || dx > INT64_MAX || dy < INT64_MIN || dy > INT64_MAX)
{
x1 = (INT64)(dx / 2 + x2);
y1 = (INT64)(dy / 2 + y2);
}
return (y1 -= y2, (x1 -= x2) || y1) ?
x1 >= 0 ?
y1 >= 0 ?
(x1 > y1) ? tantoangle[SlopeDivEx(y1, x1)] : // octant 0
ANGLE_90 - tantoangle[SlopeDivEx(x1, y1)] : // octant 1
x1 > (y1 = -y1) ? 0 - tantoangle[SlopeDivEx(y1, x1)] : // octant 8
ANGLE_270 + tantoangle[SlopeDivEx(x1, y1)] : // octant 7
y1 >= 0 ? (x1 = -x1) > y1 ? ANGLE_180 - tantoangle[SlopeDivEx(y1, x1)] : // octant 3
ANGLE_90 + tantoangle[SlopeDivEx(x1, y1)] : // octant 2
(x1 = -x1) > (y1 = -y1) ? ANGLE_180 + tantoangle[SlopeDivEx(y1, x1)] : // octant 4
ANGLE_270 - tantoangle[SlopeDivEx(x1, y1)] : // octant 5
0;
}
//
// R_ScaleFromGlobalAngle
// Returns the texture mapping scale for the current line (horizontal span)
+1 -1
View File
@@ -68,9 +68,9 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ];
INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node);
INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line);
angle_t R_PointToAngle(fixed_t x, fixed_t y);
angle_t R_PointToAngle64(INT64 x, INT64 y);
angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1);
angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1);
angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1);
fixed_t R_PointToDist(fixed_t x, fixed_t y);
fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1);
angle_t R_PlayerSliptideAngle(player_t *player);
+1 -1
View File
@@ -690,7 +690,7 @@ static void R_DrawRepeatMaskedColumn(column_t *col)
{
while (sprtopscreen < sprbotscreen) {
R_DrawMaskedColumn(col);
if ((INT64)sprtopscreen + dc_texheight*spryscale > (INT64)INT32_MAX) // prevent overflow
if (sprtopscreen + (INT64)dc_texheight*spryscale > (INT64)INT32_MAX) // prevent overflow
sprtopscreen = INT32_MAX;
else
sprtopscreen += dc_texheight*spryscale;
+1 -1
View File
@@ -2669,7 +2669,7 @@ static boolean R_CheckSpriteVisible(vissprite_t *spr, INT32 x1, INT32 x2)
// R_ClipVisSprite
// Clips vissprites without drawing, so that portals can work. -Red
void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2)
static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2)
{
drawseg_t *ds;
INT32 x;
-1
View File
@@ -182,7 +182,6 @@ typedef struct vissprite_s
extern UINT32 visspritecount, numvisiblesprites;
void R_ClipSprites(void);
void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2);
UINT8 *R_GetSpriteTranslation(vissprite_t *vis);
+5 -4
View File
@@ -74,7 +74,7 @@ void *hwSym(const char *funcName,void *handle)
{
void *funcPointer = NULL;
#ifdef HWRENDER
if (0 == strcmp("SetPalette", funcName))
if (0 == strcmp("SetTexturePalette", funcName))
funcPointer = &OglSdlSetPalette;
GETFUNC(Init);
@@ -118,9 +118,10 @@ void *hwSym(const char *funcName,void *handle)
GETFUNC(StartBatching);
GETFUNC(RenderBatches);
GETFUNC(InitPalette);
GETFUNC(AddLightTable);
GETFUNC(ClearLightTableCache);
GETFUNC(SetPaletteLookup);
GETFUNC(CreateLightTable);
GETFUNC(ClearLightTables);
GETFUNC(SetScreenPalette);
#else //HWRENDER
if (0 == strcmp("FinishUpdate", funcName))
+12 -4
View File
@@ -420,7 +420,7 @@ static void I_ReportSignal(int num, int coredumped)
{
//static char msg[] = "oh no! back to reality!\r\n";
const char * sigmsg;
char msg[128];
char msg[256];
switch (num)
{
@@ -459,15 +459,23 @@ static void I_ReportSignal(int num, int coredumped)
sprintf(msg, "%s (core dumped)", sigmsg);
else
strcat(msg, " (core dumped)");
sigmsg = msg;
}
else
{
sprintf(msg, "%s", sigmsg);
}
#ifdef HAVE_LIBBACKTRACE
strncat(msg, "\n\nCrash report has been saved into srb2kart-crash-log.txt", 255);
#elif defined(_WIN32) && !defined(__MINGW64__)
strncat(msg, "\n\nCrash report has been saved into srb2kart.rpt", 255);
#endif
I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Process killed by signal",
sigmsg, NULL);
msg, NULL);
}
#ifndef NEWSIGNALHANDLER
+17 -4
View File
@@ -1483,6 +1483,18 @@ void I_FinishUpdate(void)
#ifdef HWRENDER
else if (rendermode == render_opengl)
{
/*// Final postprocess step of palette rendering, after everything else has been drawn.
if (HWR_ShouldUsePaletteRendering())
{
// not using the function for its original named purpose but can be used like this too
HWR_MakeScreenFinalTexture();
HWD.pfnSetSpecialState(HWD_SET_SHADERS, 1);
HWD.pfnSetShader(8);
HWR_DrawScreenFinalTexture(vid.width, vid.height);
HWD.pfnUnSetShader();
HWD.pfnSetSpecialState(HWD_SET_SHADERS, 0);
}*/ //for some reason this does not work here,so ill keep it in DrawScreenFinalTexture itself for now
OglSdlFinishUpdate(cv_vidwait.value);
}
#endif
@@ -2121,7 +2133,7 @@ void I_StartupGraphics(void)
HWD.pfnGClipRect = hwSym("GClipRect",NULL);
HWD.pfnClearMipMapCache = hwSym("ClearMipMapCache",NULL);
HWD.pfnSetSpecialState = hwSym("SetSpecialState",NULL);
HWD.pfnSetPalette = hwSym("SetPalette",NULL);
HWD.pfnSetTexturePalette= hwSym("SetTexturePalette",NULL);
HWD.pfnGetTextureUsed = hwSym("GetTextureUsed",NULL);
HWD.pfnDrawModel = hwSym("DrawModel",NULL);
HWD.pfnCreateModelVBOs = hwSym("CreateModelVBOs",NULL);
@@ -2151,9 +2163,10 @@ void I_StartupGraphics(void)
HWD.pfnStartBatching = hwSym("StartBatching",NULL);
HWD.pfnRenderBatches = hwSym("RenderBatches",NULL);
HWD.pfnInitPalette = hwSym("InitPalette",NULL);
HWD.pfnAddLightTable = hwSym("AddLightTable",NULL);
HWD.pfnClearLightTableCache = hwSym("ClearLightTableCache",NULL);
HWD.pfnSetPaletteLookup = hwSym("SetPaletteLookup",NULL);
HWD.pfnCreateLightTable = hwSym("CreateLightTable",NULL);
HWD.pfnClearLightTables = hwSym("ClearLightTables",NULL);
HWD.pfnSetScreenPalette = hwSym("SetScreenPalette",NULL);
if (!HWD.pfnInit()) // load the OpenGL library
rendermode = render_soft;
+1 -1
View File
@@ -245,7 +245,7 @@ void ST_doPaletteStuff(void)
palette = 0;
#ifdef HWRENDER
if ((rendermode == render_opengl) && (!HWR_PalRenderFlashpal()))
if (rendermode == render_opengl && !HWR_PalRenderFlashpal())
palette = 0; // No flashpals here in OpenGL
#endif
+21 -51
View File
@@ -20,8 +20,6 @@
#include "r_draw.h"
#include "console.h"
#include "r_fps.h" //vhs effect stuff
#include "i_video.h" // rendermode
#include "z_zone.h"
#include "m_misc.h"
@@ -400,17 +398,8 @@ void V_SetPalette(INT32 palettenum)
LoadMapPalette();
#ifdef HWRENDER
if (rendermode != render_soft && rendermode != render_none) {
// in palette rendering mode, we already manage our palette ourselves
if (HWR_ShouldUsePaletteRendering())
{
// reset our palette lookups n shit
gl_palette_initialized = false;
HWR_InitPalette(palettenum, true);
}
else
HWR_SetPalette(&pLocalPalette[palettenum*256]);
}
if (rendermode != render_soft && rendermode != render_none)
HWR_SetPalette(&pLocalPalette[palettenum*256]);
#if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL)
else
#endif
@@ -423,16 +412,8 @@ void V_SetPaletteLump(const char *pal)
{
LoadPalette(pal);
#ifdef HWRENDER
if (rendermode != render_soft && rendermode != render_none) {
if (HWR_ShouldUsePaletteRendering())
{
// reset our palette lookups n shit
gl_palette_initialized = false;
HWR_InitPalette(0, false);
}
if (rendermode != render_soft && rendermode != render_none)
HWR_SetPalette(pLocalPalette);
}
#if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL)
else
#endif
@@ -897,8 +878,7 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c)
{
UINT8 *dest;
const UINT8 *deststop;
INT32 u, v;
UINT32 alphalevel = 0;
UINT32 alphalevel = ((c & V_ALPHAMASK) >> V_ALPHASHIFT);
if (rendermode == render_none)
return;
@@ -975,7 +955,7 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c)
dest = screens[0] + y*vid.width + x;
deststop = screens[0] + vid.rowbytes * vid.height;
if ((alphalevel = ((c & V_ALPHAMASK) >> V_ALPHASHIFT)))
if (alphalevel)
{
if (alphalevel == 13)
alphalevel = hudminusalpha[cv_translucenthud.value];
@@ -989,21 +969,20 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c)
}
c &= 255;
if (!alphalevel) {
if (alphalevel)
{
const UINT8 *fadetable = ((UINT8 *)transtables + ((alphalevel-1)<<FF_TRANSSHIFT) + (c*256));
for (;(--h >= 0) && dest < deststop; dest += vid.width)
{
for (x = 0; x < w; x++)
dest[x] = fadetable[dest[x]];
}
}
else
{
for (;(--h >= 0) && dest < deststop; dest += vid.width)
memset(dest, c, w * vid.bpp);
} else { // holy fuck i hope this doesent break lmao
const UINT8 *fadetable = ((UINT8 *)transtables + ((alphalevel-1)<<FF_TRANSSHIFT) + (c*256));
#define clip(x,y) (x>y) ? y : x
w = clip(w,vid.width);
h = clip(h,vid.height);
#undef clip
for (v = 0; v < h; v++, dest += vid.width) {
for (u = 0; u < w; u++) {
dest[u] = fadetable[dest[u]];
}
}
}
}
@@ -1383,26 +1362,17 @@ void V_DrawVhsEffect(boolean rewind)
if (rewind)
V_DrawVhsEffect(false); // experimentation
if (R_UsingFrameInterpolation()) // omg i fucking hate interp so much, its a bit smoother but still not great whatever, atleast like this shit wont completely go nuts when youre on high framerates
if (renderisnewtic)
{
if (renderisnewtic)
{
upbary -= FixedMul(vid.dupy * (rewind ? 3 : 1.8f), 22937*3);
downbary += FixedMul(vid.dupy * (rewind ? 2 : 1), 22937*3);
}
}
else
{
upbary -= vid.dupy * (rewind ? 3 : 1.8f);
downbary += vid.dupy * (rewind ? 2 : 1);
upbary -= (vid.dupy * (rewind ? 3 : 1.8f));
downbary += (vid.dupy * (rewind ? 2 : 1));
}
if (upbary < -barsize) upbary = vid.height;
if (downbary > vid.height) downbary = -barsize;
#ifdef HWRENDER
if ((rendermode == render_opengl) && (cv_grvhseffect.value))
if (rendermode == render_opengl)
{
HWR_RenderVhsEffect(upbary, downbary, updistort, downdistort, barsize);
return;
+4 -7
View File
@@ -769,13 +769,10 @@ UINT16 W_InitFile(const char *filename, const char *lumpname, UINT16 *wadnump, b
{
if (!memcmp(wadfiles[i]->md5sum, md5sum, 16))
{
if (!local) {
CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), filename);
if (handle)
fclose(handle);
return INT16_MAX;
}
CONS_Alert(CONS_WARNING, M_GetText("%s is a local skin that is already loaded\n"), filename);
CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), filename);
if (handle)
fclose(handle);
return INT16_MAX;
}
}
#endif