mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #2828
2828: Use resize instead of rescale r=def- a=Jupeyy rescale doesn't clamp, and looks worse, might be slightly faster tho. So i also renamed the config vars that might cause resizing and/or are not very useful Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
commit
393f3deed4
|
@ -207,15 +207,6 @@ int CCommandProcessorFragment_OpenGL::TexFormatToImageColorChannelCount(int TexF
|
|||
return 4;
|
||||
}
|
||||
|
||||
unsigned char CCommandProcessorFragment_OpenGL::Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset, int ScaleW, int ScaleH, int Bpp)
|
||||
{
|
||||
int Value = 0;
|
||||
for(int x = 0; x < ScaleW; x++)
|
||||
for(int y = 0; y < ScaleH; y++)
|
||||
Value += pData[((v+y)*w+(u+x))*Bpp+Offset];
|
||||
return Value/(ScaleW*ScaleH);
|
||||
}
|
||||
|
||||
static float CubicHermite(float A, float B, float C, float D, float t)
|
||||
{
|
||||
float a = -A / 2.0f + (3.0f * B) / 2.0f - (3.0f * C) / 2.0f + D / 2.0f;
|
||||
|
@ -324,28 +315,6 @@ static void ResizeImage(uint8_t *pSourceImage, uint32_t SW, uint32_t SH, uint8_t
|
|||
}
|
||||
}
|
||||
|
||||
void *CCommandProcessorFragment_OpenGL::Rescale(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData)
|
||||
{
|
||||
unsigned char *pTmpData;
|
||||
int ScaleW = Width / NewWidth;
|
||||
int ScaleH = Height / NewHeight;
|
||||
|
||||
int Bpp = TexFormatToImageColorChannelCount(Format);
|
||||
|
||||
pTmpData = (unsigned char *)malloc(NewWidth * NewHeight * Bpp);
|
||||
|
||||
int c = 0;
|
||||
for(int y = 0; y < NewHeight; y++)
|
||||
for(int x = 0; x < NewWidth; x++, c++)
|
||||
{
|
||||
for(int i = 0; i < Bpp; ++i) {
|
||||
pTmpData[c*Bpp + i] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, i, ScaleW, ScaleH, Bpp);
|
||||
}
|
||||
}
|
||||
|
||||
return pTmpData;
|
||||
}
|
||||
|
||||
void *CCommandProcessorFragment_OpenGL::Resize(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData)
|
||||
{
|
||||
unsigned char *pTmpData;
|
||||
|
@ -504,7 +473,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Update(const CCommandBuffer::
|
|||
int ResizedW = (int)(Width * ResizeW);
|
||||
int ResizedH = (int)(Height * ResizeH);
|
||||
|
||||
void *pTmpData = Resize(Width, Height, ResizedW, ResizedH, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
|
||||
void *pTmpData = Resize(Width, Height, ResizedW, ResizedH, pCommand->m_Format, static_cast<const unsigned char *>(pTexData));
|
||||
free(pTexData);
|
||||
pTexData = pTmpData;
|
||||
|
||||
|
@ -515,6 +484,8 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Update(const CCommandBuffer::
|
|||
|
||||
if(m_aTextures[pCommand->m_Slot].m_RescaleCount > 0)
|
||||
{
|
||||
int OldWidth = Width;
|
||||
int OldHeight = Height;
|
||||
for(int i = 0; i < m_aTextures[pCommand->m_Slot].m_RescaleCount; ++i)
|
||||
{
|
||||
Width >>= 1;
|
||||
|
@ -524,7 +495,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Update(const CCommandBuffer::
|
|||
Y /= 2;
|
||||
}
|
||||
|
||||
void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
|
||||
void *pTmpData = Resize(OldWidth, OldHeight, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pTexData));
|
||||
free(pTexData);
|
||||
pTexData = pTmpData;
|
||||
}
|
||||
|
@ -594,7 +565,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::
|
|||
int PowerOfTwoHeight = HighestBit(Height);
|
||||
if(Width != PowerOfTwoWidth || Height != PowerOfTwoHeight)
|
||||
{
|
||||
void *pTmpData = Resize(Width, Height, PowerOfTwoWidth, PowerOfTwoHeight, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
|
||||
void *pTmpData = Resize(Width, Height, PowerOfTwoWidth, PowerOfTwoHeight, pCommand->m_Format, static_cast<const unsigned char *>(pTexData));
|
||||
free(pTexData);
|
||||
pTexData = pTmpData;
|
||||
|
||||
|
@ -609,6 +580,10 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::
|
|||
int RescaleCount = 0;
|
||||
if(pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGBA || pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGB || pCommand->m_Format == CCommandBuffer::TEXFORMAT_ALPHA)
|
||||
{
|
||||
int OldWidth = Width;
|
||||
int OldHeight = Height;
|
||||
bool NeedsResize = false;
|
||||
|
||||
if(Width > m_MaxTexSize || Height > m_MaxTexSize)
|
||||
{
|
||||
do
|
||||
|
@ -617,18 +592,19 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::
|
|||
Height >>= 1;
|
||||
++RescaleCount;
|
||||
} while(Width > m_MaxTexSize || Height > m_MaxTexSize);
|
||||
|
||||
void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
|
||||
free(pTexData);
|
||||
pTexData = pTmpData;
|
||||
NeedsResize = true;
|
||||
}
|
||||
else if(pCommand->m_Format != CCommandBuffer::TEXFORMAT_ALPHA && (Width > 16 && Height > 16 && (pCommand->m_Flags&CCommandBuffer::TEXFLAG_QUALITY) == 0))
|
||||
{
|
||||
Width >>= 1;
|
||||
Height >>= 1;
|
||||
++RescaleCount;
|
||||
NeedsResize = true;
|
||||
}
|
||||
|
||||
void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
|
||||
if(NeedsResize)
|
||||
{
|
||||
void *pTmpData = Resize(OldWidth, OldHeight, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pTexData));
|
||||
free(pTexData);
|
||||
pTexData = pTmpData;
|
||||
}
|
||||
|
@ -2538,7 +2514,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Update(const CCommandBuffe
|
|||
Y /= 2;
|
||||
}
|
||||
|
||||
void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
|
||||
void *pTmpData = Resize(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
|
||||
free(pTexData);
|
||||
pTexData = pTmpData;
|
||||
}
|
||||
|
@ -2584,7 +2560,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Create(const CCommandBuffe
|
|||
}
|
||||
while(Width > m_MaxTexSize || Height > m_MaxTexSize);
|
||||
|
||||
void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
|
||||
void *pTmpData = Resize(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
|
||||
free(pTexData);
|
||||
pTexData = pTmpData;
|
||||
}
|
||||
|
@ -2594,7 +2570,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Create(const CCommandBuffe
|
|||
Height>>=1;
|
||||
++RescaleCount;
|
||||
|
||||
void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
|
||||
void *pTmpData = Resize(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
|
||||
free(pTexData);
|
||||
pTexData = pTmpData;
|
||||
}
|
||||
|
|
|
@ -168,8 +168,6 @@ protected:
|
|||
|
||||
static int TexFormatToOpenGLFormat(int TexFormat);
|
||||
static int TexFormatToImageColorChannelCount(int TexFormat);
|
||||
static unsigned char Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset, int ScaleW, int ScaleH, int Bpp);
|
||||
static void *Rescale(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData);
|
||||
static void *Resize(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData);
|
||||
|
||||
virtual void Cmd_Init(const SCommand_Init *pCommand);
|
||||
|
|
|
@ -434,9 +434,9 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(int Width, int Heig
|
|||
Cmd.m_Flags = 0;
|
||||
if(Flags&IGraphics::TEXLOAD_NOMIPMAPS)
|
||||
Cmd.m_Flags |= CCommandBuffer::TEXFLAG_NOMIPMAPS;
|
||||
if(g_Config.m_GfxTextureCompression && ((Flags&IGraphics::TEXLOAD_NO_COMPRESSION) == 0))
|
||||
if(g_Config.m_GfxTextureCompressionOld && ((Flags & IGraphics::TEXLOAD_NO_COMPRESSION) == 0))
|
||||
Cmd.m_Flags |= CCommandBuffer::TEXFLAG_COMPRESSED;
|
||||
if(g_Config.m_GfxTextureQuality || Flags&TEXLOAD_NORESAMPLE)
|
||||
if(g_Config.m_GfxTextureQualityOld || Flags & TEXLOAD_NORESAMPLE)
|
||||
Cmd.m_Flags |= CCommandBuffer::TEXFLAG_QUALITY;
|
||||
if((Flags&IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE) != 0)
|
||||
Cmd.m_Flags |= CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE;
|
||||
|
|
|
@ -105,9 +105,9 @@ MACRO_CONFIG_INT(GfxColorDepth, gfx_color_depth, 24, 16, 24, CFGFLAG_SAVE | CFGF
|
|||
MACRO_CONFIG_INT(GfxVsync, gfx_vsync, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Vertical sync (may cause delay)")
|
||||
MACRO_CONFIG_INT(GfxResizable, gfx_resizable, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Enables window resizing")
|
||||
MACRO_CONFIG_INT(GfxDisplayAllModes, gfx_display_all_modes, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "")
|
||||
MACRO_CONFIG_INT(GfxTextureCompression, gfx_texture_compression, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Use texture compression")
|
||||
MACRO_CONFIG_INT(GfxTextureCompressionOld, gfx_texture_compression_old, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Use texture compression")
|
||||
MACRO_CONFIG_INT(GfxTextureQualityOld, gfx_texture_quality_old, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "")
|
||||
MACRO_CONFIG_INT(GfxHighDetail, gfx_high_detail, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "High detail")
|
||||
MACRO_CONFIG_INT(GfxTextureQuality, gfx_texture_quality, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "")
|
||||
MACRO_CONFIG_INT(GfxFsaaSamples, gfx_fsaa_samples, 0, 0, 16, CFGFLAG_SAVE | CFGFLAG_CLIENT, "FSAA Samples")
|
||||
MACRO_CONFIG_INT(GfxRefreshRate, gfx_refresh_rate, 0, 0, 10000, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen refresh rate")
|
||||
MACRO_CONFIG_INT(GfxFinish, gfx_finish, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "")
|
||||
|
|
|
@ -912,8 +912,6 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
|
|||
static int s_GfxColorDepth = g_Config.m_GfxColorDepth;
|
||||
static int s_GfxVsync = g_Config.m_GfxVsync;
|
||||
static int s_GfxFsaaSamples = g_Config.m_GfxFsaaSamples;
|
||||
static int s_GfxTextureQuality = g_Config.m_GfxTextureQuality;
|
||||
static int s_GfxTextureCompression = g_Config.m_GfxTextureCompression;
|
||||
static int s_GfxOpenGLVersion = (g_Config.m_GfxOpenGLMajor == 3 && g_Config.m_GfxOpenGLMinor == 3) || g_Config.m_GfxOpenGLMajor >= 4;
|
||||
static int s_GfxEnableTextureUnitOptimization = g_Config.m_GfxEnableTextureUnitOptimization;
|
||||
static int s_GfxUsePreinitBuffer = g_Config.m_GfxUsePreinitBuffer;
|
||||
|
@ -1079,8 +1077,6 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
|
|||
s_GfxColorDepth == g_Config.m_GfxColorDepth &&
|
||||
s_GfxVsync == g_Config.m_GfxVsync &&
|
||||
s_GfxFsaaSamples == g_Config.m_GfxFsaaSamples &&
|
||||
s_GfxTextureQuality == g_Config.m_GfxTextureQuality &&
|
||||
s_GfxTextureCompression == g_Config.m_GfxTextureCompression &&
|
||||
s_GfxOpenGLVersion == (int)IsNewOpenGL &&
|
||||
s_GfxUsePreinitBuffer == g_Config.m_GfxUsePreinitBuffer &&
|
||||
s_GfxEnableTextureUnitOptimization == g_Config.m_GfxEnableTextureUnitOptimization &&
|
||||
|
|
Loading…
Reference in a new issue