Skip to content

Commit

Permalink
Calculate separate POT (Power-Of-Two) texture width and height
Browse files Browse the repository at this point in the history
  • Loading branch information
KOPRajs authored and garbear committed May 28, 2024
1 parent 76f9b7e commit 366cac1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions xbmc/cores/RetroPlayer/shaders/ShaderUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ using namespace SHADER;

float2 CShaderUtils::GetOptimalTextureSize(float2 videoSize)
{
unsigned sizeMax = videoSize.Max<unsigned>();
unsigned size = 1;
unsigned textureWidth = 1;
unsigned textureHeight = 1;

// Find smallest possible power-of-two size that can contain input texture
// Find smallest possible power-of-two sized width that can contain the input texture
while (true)
{
if (size >= sizeMax)
if (textureWidth >= videoSize.x)
break;
size *= 2;
textureWidth *= 2;
}
return float2(size, size);

// Find smallest possible power-of-two sized height that can contain the input texture
while (true)
{
if (textureHeight >= videoSize.y)
break;
textureHeight *= 2;
}

return float2(textureWidth, textureHeight);
}

0 comments on commit 366cac1

Please sign in to comment.