Replace MathUtil::Clamp with its std counterpart

This commit is contained in:
fearlessTobi 2018-07-24 19:08:17 +02:00
parent 14878a17d9
commit 7a3e126a4f
17 changed files with 49 additions and 72 deletions

View file

@ -8,7 +8,6 @@
#include "common/color.h"
#include "common/common_types.h"
#include "common/logging/log.h"
#include "common/math_util.h"
#include "common/vector_math.h"
#include "core/hw/gpu.h"
#include "core/memory.h"
@ -301,8 +300,8 @@ Math::Vec4<u8> EvaluateBlendEquation(const Math::Vec4<u8>& src, const Math::Vec4
UNIMPLEMENTED();
}
return Math::Vec4<u8>(MathUtil::Clamp(result.r(), 0, 255), MathUtil::Clamp(result.g(), 0, 255),
MathUtil::Clamp(result.b(), 0, 255), MathUtil::Clamp(result.a(), 0, 255));
return Math::Vec4<u8>(std::clamp(result.r(), 0, 255), std::clamp(result.g(), 0, 255),
std::clamp(result.b(), 0, 255), std::clamp(result.a(), 0, 255));
};
u8 LogicOp(u8 src, u8 dest, FramebufferRegs::LogicOp op) {
@ -400,7 +399,7 @@ void DrawShadowMapPixel(int x, int y, u32 depth, u8 stencil) {
float16 linear = float16::FromRaw(shadow.linear);
float16 x = float16::FromFloat32(static_cast<float>(depth) / ref_z);
float16 stencil_new = float16::FromFloat32(stencil) / (constant + linear * x);
stencil = static_cast<u8>(MathUtil::Clamp(stencil_new.ToFloat32(), 0.0f, 255.0f));
stencil = static_cast<u8>(std::clamp(stencil_new.ToFloat32(), 0.0f, 255.0f));
if (stencil < ref_s)
EncodeX24S8Shadow(stencil, dst_pixel);

View file

@ -2,7 +2,6 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/math_util.h"
#include "video_core/swrasterizer/lighting.h"
namespace Pica {
@ -96,10 +95,10 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
size_t lut =
static_cast<size_t>(LightingRegs::LightingSampler::DistanceAttenuation) + num;
float sample_loc = MathUtil::Clamp(scale * distance + bias, 0.0f, 1.0f);
float sample_loc = std::clamp(scale * distance + bias, 0.0f, 1.0f);
u8 lutindex =
static_cast<u8>(MathUtil::Clamp(std::floor(sample_loc * 256.0f), 0.0f, 255.0f));
static_cast<u8>(std::clamp(std::floor(sample_loc * 256.0f), 0.0f, 255.0f));
float delta = sample_loc * 256 - lutindex;
dist_atten = LookupLightingLut(lighting_state, lut, lutindex, delta);
}
@ -158,11 +157,11 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
result = std::max(result, 0.0f);
float flr = std::floor(result * 256.0f);
index = static_cast<u8>(MathUtil::Clamp(flr, 0.0f, 255.0f));
index = static_cast<u8>(std::clamp(flr, 0.0f, 255.0f));
delta = result * 256 - index;
} else {
float flr = std::floor(result * 128.0f);
s8 signed_index = static_cast<s8>(MathUtil::Clamp(flr, -128.0f, 127.0f));
s8 signed_index = static_cast<s8>(std::clamp(flr, -128.0f, 127.0f));
delta = result * 128.0f - signed_index;
index = static_cast<u8>(signed_index);
}
@ -316,15 +315,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
diffuse_sum += Math::MakeVec(lighting.global_ambient.ToVec3f(), 0.0f);
auto diffuse = Math::MakeVec<float>(MathUtil::Clamp(diffuse_sum.x, 0.0f, 1.0f) * 255,
MathUtil::Clamp(diffuse_sum.y, 0.0f, 1.0f) * 255,
MathUtil::Clamp(diffuse_sum.z, 0.0f, 1.0f) * 255,
MathUtil::Clamp(diffuse_sum.w, 0.0f, 1.0f) * 255)
auto diffuse = Math::MakeVec<float>(std::clamp(diffuse_sum.x, 0.0f, 1.0f) * 255,
std::clamp(diffuse_sum.y, 0.0f, 1.0f) * 255,
std::clamp(diffuse_sum.z, 0.0f, 1.0f) * 255,
std::clamp(diffuse_sum.w, 0.0f, 1.0f) * 255)
.Cast<u8>();
auto specular = Math::MakeVec<float>(MathUtil::Clamp(specular_sum.x, 0.0f, 1.0f) * 255,
MathUtil::Clamp(specular_sum.y, 0.0f, 1.0f) * 255,
MathUtil::Clamp(specular_sum.z, 0.0f, 1.0f) * 255,
MathUtil::Clamp(specular_sum.w, 0.0f, 1.0f) * 255)
auto specular = Math::MakeVec<float>(std::clamp(specular_sum.x, 0.0f, 1.0f) * 255,
std::clamp(specular_sum.y, 0.0f, 1.0f) * 255,
std::clamp(specular_sum.z, 0.0f, 1.0f) * 255,
std::clamp(specular_sum.w, 0.0f, 1.0f) * 255)
.Cast<u8>();
return std::make_tuple(diffuse, specular);
}

View file

@ -11,7 +11,6 @@
#include "common/color.h"
#include "common/common_types.h"
#include "common/logging/log.h"
#include "common/math_util.h"
#include "common/microprofile.h"
#include "common/quaternion.h"
#include "common/vector_math.h"
@ -271,7 +270,7 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
}
// Clamp the result
depth = MathUtil::Clamp(depth, 0.0f, 1.0f);
depth = std::clamp(depth, 0.0f, 1.0f);
// Perspective correct attribute interpolation:
// Attribute values cannot be calculated by simple linear interpolation since
@ -645,11 +644,11 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
}
// Generate clamped fog factor from LUT for given fog index
float fog_i = MathUtil::Clamp(floorf(fog_index), 0.0f, 127.0f);
float fog_i = std::clamp(floorf(fog_index), 0.0f, 127.0f);
float fog_f = fog_index - fog_i;
const auto& fog_lut_entry = g_state.fog.lut[static_cast<unsigned int>(fog_i)];
float fog_factor = fog_lut_entry.ToFloat() + fog_lut_entry.DiffToFloat() * fog_f;
fog_factor = MathUtil::Clamp(fog_factor, 0.0f, 1.0f);
fog_factor = std::clamp(fog_factor, 0.0f, 1.0f);
// Blend the fog
for (unsigned i = 0; i < 3; i++) {

View file

@ -6,7 +6,6 @@
#include "common/assert.h"
#include "common/common_types.h"
#include "common/math_util.h"
#include "common/vector_math.h"
#include "video_core/regs_texturing.h"
#include "video_core/swrasterizer/texturing.h"
@ -148,9 +147,9 @@ Math::Vec3<u8> ColorCombine(TevStageConfig::Operation op, const Math::Vec3<u8> i
// (byte) 128 is correct
auto result =
input[0].Cast<int>() + input[1].Cast<int>() - Math::MakeVec<int>(128, 128, 128);
result.r() = MathUtil::Clamp<int>(result.r(), 0, 255);
result.g() = MathUtil::Clamp<int>(result.g(), 0, 255);
result.b() = MathUtil::Clamp<int>(result.b(), 0, 255);
result.r() = std::clamp<int>(result.r(), 0, 255);
result.g() = std::clamp<int>(result.g(), 0, 255);
result.b() = std::clamp<int>(result.b(), 0, 255);
return result.Cast<u8>();
}
@ -218,7 +217,7 @@ u8 AlphaCombine(TevStageConfig::Operation op, const std::array<u8, 3>& input) {
case Operation::AddSigned: {
// TODO(bunnei): Verify that the color conversion from (float) 0.5f to (byte) 128 is correct
auto result = static_cast<int>(input[0]) + static_cast<int>(input[1]) - 128;
return static_cast<u8>(MathUtil::Clamp<int>(result, 0, 255));
return static_cast<u8>(std::clamp<int>(result, 0, 255));
}
case Operation::Lerp: