diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 0cd5d2a9f..6fc8959da 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -5458,6 +5458,56 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba 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 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 (!Bstrcasecmp(parm->name, "r_swapinterval")) + if (!Bstrcasecmp(parm->name, "r_palookupinfo")) + palookupinfo(); + + else if (!Bstrcasecmp(parm->name, "r_swapinterval")) vsync = videoSetVsync(vsync); else if (!Bstrcasecmp(parm->name, "r_downsize")) { @@ -5537,6 +5590,8 @@ static int osdcmd_cvar_set_polymost(osdcmdptr_t parm) return r; } +int r_palookupinfo; + void polymost_initosdfuncs(void) { 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_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_palookupinfo", "", (void*)&r_palookupinfo, CVAR_INT|CVAR_FUNCPTR, 0, 1 }, { "r_yshearing", "enable/disable y-shearing", (void*) &r_yshearing, CVAR_BOOL, 0, 1 }, { "fixpalette", "", (void*)& fixpalette, CVAR_INT, 0, 256 }, diff --git a/source/glbackend/gl_hwtexture.cpp b/source/glbackend/gl_hwtexture.cpp index 61a0330a1..e661c2e13 100644 --- a/source/glbackend/gl_hwtexture.cpp +++ b/source/glbackend/gl_hwtexture.cpp @@ -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; 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); glBindTexture(GL_TEXTURE_2D, glTexID); diff --git a/source/glbackend/gl_hwtexture.h b/source/glbackend/gl_hwtexture.h index 363663f33..55516eca6 100644 --- a/source/glbackend/gl_hwtexture.h +++ b/source/glbackend/gl_hwtexture.h @@ -27,9 +27,9 @@ public: //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 LoadTexture(const unsigned char * buffer); - unsigned int LoadTexturePart(const unsigned char* buffer, int x, int y, int w, int h); - unsigned int LoadTexture(FBitmap &bmp); + 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, bool brga = false); + unsigned int LoadTexture(FBitmap &bmp, bool brga = false); unsigned int GetTextureHandle(); int GetSampler() { return mSampler; } void SetSampler(int sampler) { mSampler = sampler; } diff --git a/source/glbackend/gl_palmanager.cpp b/source/glbackend/gl_palmanager.cpp index 815e47ff1..a9c332729 100644 --- a/source/glbackend/gl_palmanager.cpp +++ b/source/glbackend/gl_palmanager.cpp @@ -189,7 +189,7 @@ void PaletteManager::BindPalette(int index) { auto p = GLInterface.NewTexture(); p->CreateTexture(256, 1, false, false); - p->LoadTexture((uint8_t*)transientpalette.colors); + p->LoadTexture((uint8_t*)transientpalette.colors, true); p->SetSampler(Sampler2DNoFilter); transientpalette.paltexture = p; } @@ -205,7 +205,7 @@ void PaletteManager::BindPalette(int index) { auto p = GLInterface.NewTexture(); p->CreateTexture(256, 1, false, false); - p->LoadTexture((uint8_t*)palettes[uindex].colors); + p->LoadTexture((uint8_t*)palettes[uindex].colors, true); p->SetSampler(Sampler2DNoFilter); palettes[uindex].paltexture = p; } diff --git a/wadsrc/static/demolition/shaders/glsl/polymost.fp b/wadsrc/static/demolition/shaders/glsl/polymost.fp index e87cf5b73..b6d4dab20 100644 --- a/wadsrc/static/demolition/shaders/glsl/polymost.fp +++ b/wadsrc/static/demolition/shaders/glsl/polymost.fp @@ -188,12 +188,12 @@ void main() } if (fullbright == 0.0) color.rgb *= v_color.rgb; 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; - color.rgb *= detailColor.rgb; 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