16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00

Refactor clamp_power_of_two

This commit is contained in:
docentYT
2026-05-02 00:35:50 +02:00
parent 76844e33e7
commit 28baad8c5b
4 changed files with 15 additions and 15 deletions

View File

@@ -270,7 +270,7 @@ opengl_texture::load() {
WriteLog( "Warning: dimensions of texture \"" + name + "\" aren't powers of 2", logtype::texture );
}
}
if( ( quantize( data_width, 4 ) != data_width ) || ( quantize( data_height, 4 ) != data_height ) ) {
if( ( quantize( data_width, 4u ) != data_width ) || ( quantize( data_height, 4u ) != data_height ) ) {
WriteLog( "Warning: dimensions of texture \"" + name + "\" aren't multiples of 4", logtype::texture );
}

View File

@@ -119,7 +119,7 @@ public:
bool is_texstub = false; // for make_from_memory internal_src: functionality
std::vector<unsigned char> data; // texture data (stored GL-style, bottom-left origin)
resource_state data_state{ resource_state::none }; // current state of texture data
int data_width{ 0 },
unsigned int data_width{ 0 },
data_height{ 0 },
data_mapcount{ 0 };
GLint data_format{ 0 },

View File

@@ -284,17 +284,17 @@ bool global_settings::ConfigParseGraphics(cParser& Parser, const std::string& to
if (token == "maxtexturesize")
{
int size = 0;
unsigned int size = 0;
ParseOne(Parser, size, 1, false);
iMaxTextureSize = clamp_power_of_two(size, 64, 8192);
iMaxTextureSize = static_cast<GLint>(clamp_power_of_two(size, 64u, 8192u));
return true;
}
if (token == "maxcabtexturesize")
{
int size = 0;
unsigned int size = 0;
ParseOne(Parser, size, 1, false);
iMaxCabTextureSize = clamp_power_of_two(size, 512, 8192);
iMaxCabTextureSize = static_cast<GLint>(clamp_power_of_two(size, 512u, 8192u));
return true;
}

View File

@@ -269,17 +269,17 @@ template <typename T> T clamp_circular(T Value, T const Range = T(360))
}
// rounds down provided value to nearest power of two
template <typename Type_> Type_ clamp_power_of_two(Type_ Value, Type_ const Min = static_cast<Type_>(1), Type_ const Max = static_cast<Type_>(16384))
template <typename T> T clamp_power_of_two(T Value, T const Min = T(1), T const Max = T(16384))
{
if (Value < Min)
return Min;
Type_ p2size{Min};
Type_ size;
while ((p2size <= Max) && (p2size <= Value))
{
size = p2size;
p2size = p2size << 1;
}
return size;
T p2 = std::bit_floor(Value);
if (p2 > Max)
return Max;
return p2;
}
template <typename Type_> Type_ quantize(Type_ const Value, Type_ const Step)