- fixed creation of true color textures and disabled fog in palette mode.

The fog should go away entirely but in palette mode it made everything too dark.
This commit is contained in:
Christoph Oelckers 2019-10-18 22:09:19 +02:00
parent 2ed722f329
commit 00d59459a1
5 changed files with 70 additions and 14 deletions

View file

@ -5458,6 +5458,56 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba
return 0; return 0;
} }
void palookupinfo()
{
auto pal = basepaltable[0];
int black = -1, white = -1;
int brightness = 0;
for (int i = 0; i < 765; i += 3)
{
if (pal[i] == 0 && pal[i + 1] == 0 && pal[i + 2] == 0) black = i;
if (pal[i] == 255 && pal[i + 1] == 255 && pal[i + 2] == 255) white = i/3;
brightness += Luminance(pal[i], pal[i + 1], pal[i + 2]);
}
brightness /= 255;
OSD_Printf("Black at index %d, white at index %d, avg. luminance %d\n", black, white, brightness);
for (int i = 0; i < 256; i++)
{
if (palookup[i] == nullptr)
{
OSD_Printf("palookup[%d] undefined\n", i);
continue;
}
if (i > 0 && palookup[i] == palookup[0])
{
OSD_Printf("palookup[%d] == default\n", i);
continue;
}
OSD_Printf("palookup[%d]:\n", i);
for (int j = 0; j <= numshades; j++)
{
OSD_Printf(" Shade %d\n", j);
int map = palookup[i][j * 256 + black] * 3;
OSD_Printf(" Black maps to %d - %02x %02x %02x\n", map, pal[map], pal[map + 1], pal[map + 2]);
map = palookup[i][j * 256 + white] * 3;
OSD_Printf(" White maps to %d - %02x %02x %02x\n", map, pal[map], pal[map + 1], pal[map + 2]);
int mylum = 0;
for (int k = 0; k < 255; k++)
{
map = palookup[i][j * 256 + k] * 3;
mylum += Luminance(pal[map], pal[map + 1], pal[map + 2]);
}
mylum /= 255;
OSD_Printf(" luminance = %d\n", mylum);
}
OSD_Printf("-------------------------\n");
}
}
// Console commands by JBF // Console commands by JBF
static int32_t gltexturemode(osdcmdptr_t parm) static int32_t gltexturemode(osdcmdptr_t parm)
{ {
@ -5512,7 +5562,10 @@ static int osdcmd_cvar_set_polymost(osdcmdptr_t parm)
if (r == OSDCMD_OK) if (r == OSDCMD_OK)
{ {
if (!Bstrcasecmp(parm->name, "r_swapinterval")) if (!Bstrcasecmp(parm->name, "r_palookupinfo"))
palookupinfo();
else if (!Bstrcasecmp(parm->name, "r_swapinterval"))
vsync = videoSetVsync(vsync); vsync = videoSetVsync(vsync);
else if (!Bstrcasecmp(parm->name, "r_downsize")) else if (!Bstrcasecmp(parm->name, "r_downsize"))
{ {
@ -5537,6 +5590,8 @@ static int osdcmd_cvar_set_polymost(osdcmdptr_t parm)
return r; return r;
} }
int r_palookupinfo;
void polymost_initosdfuncs(void) void polymost_initosdfuncs(void)
{ {
uint32_t i; uint32_t i;
@ -5563,6 +5618,7 @@ void polymost_initosdfuncs(void)
{ "r_swapinterval","sets the GL swap interval (VSync)",(void *) &vsync, CVAR_INT|CVAR_FUNCPTR, -1, 1 }, { "r_swapinterval","sets the GL swap interval (VSync)",(void *) &vsync, CVAR_INT|CVAR_FUNCPTR, -1, 1 },
{ "r_texfilter", "changes the texture filtering settings (may require restart)", (void *) &gltexfiltermode, CVAR_INT|CVAR_FUNCPTR, 0, 5 }, { "r_texfilter", "changes the texture filtering settings (may require restart)", (void *) &gltexfiltermode, CVAR_INT|CVAR_FUNCPTR, 0, 5 },
{ "r_useindexedcolortextures", "enable/disable indexed color texture rendering", (void *) &r_useindexedcolortextures, CVAR_INT, 0, 1 }, { "r_useindexedcolortextures", "enable/disable indexed color texture rendering", (void *) &r_useindexedcolortextures, CVAR_INT, 0, 1 },
{ "r_palookupinfo", "", (void*)&r_palookupinfo, CVAR_INT|CVAR_FUNCPTR, 0, 1 },
{ "r_yshearing", "enable/disable y-shearing", (void*) &r_yshearing, CVAR_BOOL, 0, 1 }, { "r_yshearing", "enable/disable y-shearing", (void*) &r_yshearing, CVAR_BOOL, 0, 1 },
{ "fixpalette", "", (void*)& fixpalette, CVAR_INT, 0, 256 }, { "fixpalette", "", (void*)& fixpalette, CVAR_INT, 0, 256 },

View file

@ -65,14 +65,14 @@ unsigned int FHardwareTexture::CreateTexture(int w, int h, bool eightbit, bool m
// //
//=========================================================================== //===========================================================================
unsigned int FHardwareTexture::LoadTexture(const unsigned char * buffer) unsigned int FHardwareTexture::LoadTexture(const unsigned char * buffer, bool bgra)
{ {
return LoadTexturePart(buffer, 0, 0, mWidth, mHeight); return LoadTexturePart(buffer, 0, 0, mWidth, mHeight, bgra);
} }
unsigned int FHardwareTexture::LoadTexture(FBitmap& bmp) unsigned int FHardwareTexture::LoadTexture(FBitmap& bmp, bool bgra)
{ {
return LoadTexture(bmp.GetPixels()); return LoadTexture(bmp.GetPixels(), bgra);
} }
//=========================================================================== //===========================================================================
@ -81,12 +81,12 @@ unsigned int FHardwareTexture::LoadTexture(FBitmap& bmp)
// //
//=========================================================================== //===========================================================================
unsigned int FHardwareTexture::LoadTexturePart(const unsigned char* buffer, int x, int y, int w, int h) unsigned int FHardwareTexture::LoadTexturePart(const unsigned char* buffer, int x, int y, int w, int h, bool bgra)
{ {
if (glTexID == 0) return 0; if (glTexID == 0) return 0;
int dstformat = glTextureBytes == 1 ? GL_R8 : GL_RGBA8;// TexFormat[gl_texture_format]; int dstformat = glTextureBytes == 1 ? GL_R8 : GL_RGBA8;// TexFormat[gl_texture_format];
int srcformat = glTextureBytes == 1 ? GL_RED : GL_BGRA;// TexFormat[gl_texture_format]; int srcformat = glTextureBytes == 1 ? GL_RED : (bgra ? GL_BGRA : GL_RGBA);// TexFormat[gl_texture_format];
glActiveTexture(GL_TEXTURE15); glActiveTexture(GL_TEXTURE15);
glBindTexture(GL_TEXTURE_2D, glTexID); glBindTexture(GL_TEXTURE_2D, glTexID);

View file

@ -27,9 +27,9 @@ public:
//bool BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags); //bool BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags);
unsigned int CreateTexture(int w, int h, bool eightbit, bool mipmapped); unsigned int CreateTexture(int w, int h, bool eightbit, bool mipmapped);
unsigned int LoadTexture(const unsigned char * buffer); unsigned int LoadTexture(const unsigned char * buffer, bool brga = false);
unsigned int LoadTexturePart(const unsigned char* buffer, int x, int y, int w, int h); unsigned int LoadTexturePart(const unsigned char* buffer, int x, int y, int w, int h, bool brga = false);
unsigned int LoadTexture(FBitmap &bmp); unsigned int LoadTexture(FBitmap &bmp, bool brga = false);
unsigned int GetTextureHandle(); unsigned int GetTextureHandle();
int GetSampler() { return mSampler; } int GetSampler() { return mSampler; }
void SetSampler(int sampler) { mSampler = sampler; } void SetSampler(int sampler) { mSampler = sampler; }

View file

@ -189,7 +189,7 @@ void PaletteManager::BindPalette(int index)
{ {
auto p = GLInterface.NewTexture(); auto p = GLInterface.NewTexture();
p->CreateTexture(256, 1, false, false); p->CreateTexture(256, 1, false, false);
p->LoadTexture((uint8_t*)transientpalette.colors); p->LoadTexture((uint8_t*)transientpalette.colors, true);
p->SetSampler(Sampler2DNoFilter); p->SetSampler(Sampler2DNoFilter);
transientpalette.paltexture = p; transientpalette.paltexture = p;
} }
@ -205,7 +205,7 @@ void PaletteManager::BindPalette(int index)
{ {
auto p = GLInterface.NewTexture(); auto p = GLInterface.NewTexture();
p->CreateTexture(256, 1, false, false); p->CreateTexture(256, 1, false, false);
p->LoadTexture((uint8_t*)palettes[uindex].colors); p->LoadTexture((uint8_t*)palettes[uindex].colors, true);
p->SetSampler(Sampler2DNoFilter); p->SetSampler(Sampler2DNoFilter);
palettes[uindex].paltexture = p; palettes[uindex].paltexture = p;
} }

View file

@ -188,12 +188,12 @@ void main()
} }
if (fullbright == 0.0) color.rgb *= v_color.rgb; if (fullbright == 0.0) color.rgb *= v_color.rgb;
color.a *= v_color.a; color.a *= v_color.a;
color.rgb *= detailColor.rgb;
if (u_fogEnabled != 0.0)// the following would make sense if 'fullbright' could ever be true in non-paletted rendering: && (fullbright != 0.0 || u_fogColor.rgb != vec3(0.0) )) if (u_fogEnabled != 0.0 && u_usePalette == 0.0)// the following would make sense if 'fullbright' could ever be true in non-paletted rendering: && (fullbright != 0.0 || u_fogColor.rgb != vec3(0.0) ))
{ {
float fogFactor; float fogFactor;
color.rgb *= detailColor.rgb;
if (u_fog.z == 0) fogFactor = (u_fog.x-v_fogCoord)*u_fog.y; // linear fog if (u_fog.z == 0) fogFactor = (u_fog.x-v_fogCoord)*u_fog.y; // linear fog
else fogFactor = exp2 (u_fog.z * v_fogCoord); // exponential fog else fogFactor = exp2 (u_fog.z * v_fogCoord); // exponential fog