Merge pull request #3994 from FearlessTobi/replace-clamp-functions
Remove MathUtil::Clamp and replace it with its std:: counterpart
This commit is contained in:
commit
14b0435df2
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -9,7 +10,6 @@
|
||||||
#include "audio_core/codec.h"
|
#include "audio_core/codec.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
namespace Codec {
|
namespace Codec {
|
||||||
|
@ -51,7 +51,7 @@ StereoBuffer16 DecodeADPCM(const u8* const data, const size_t sample_count,
|
||||||
// Filter: y[n] = x[n] + 0.5 + c1 * y[n-1] + c2 * y[n-2]
|
// Filter: y[n] = x[n] + 0.5 + c1 * y[n-1] + c2 * y[n-2]
|
||||||
int val = ((xn << 11) + 0x400 + coef1 * yn1 + coef2 * yn2) >> 11;
|
int val = ((xn << 11) + 0x400 + coef1 * yn1 + coef2 * yn2) >> 11;
|
||||||
// Clamp to output range.
|
// Clamp to output range.
|
||||||
val = MathUtil::Clamp(val, -32768, 32767);
|
val = std::clamp(val, -32768, 32767);
|
||||||
// Advance output feedback.
|
// Advance output feedback.
|
||||||
yn2 = yn1;
|
yn2 = yn1;
|
||||||
yn1 = val;
|
yn1 = val;
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include "audio_core/hle/common.h"
|
#include "audio_core/hle/common.h"
|
||||||
#include "audio_core/hle/filter.h"
|
#include "audio_core/hle/filter.h"
|
||||||
#include "audio_core/hle/shared_memory.h"
|
#include "audio_core/hle/shared_memory.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
namespace HLE {
|
namespace HLE {
|
||||||
|
@ -68,7 +68,7 @@ std::array<s16, 2> SourceFilters::SimpleFilter::ProcessSample(const std::array<s
|
||||||
std::array<s16, 2> y0;
|
std::array<s16, 2> y0;
|
||||||
for (size_t i = 0; i < 2; i++) {
|
for (size_t i = 0; i < 2; i++) {
|
||||||
const s32 tmp = (b0 * x0[i] + a1 * y1[i]) >> 15;
|
const s32 tmp = (b0 * x0[i] + a1 * y1[i]) >> 15;
|
||||||
y0[i] = MathUtil::Clamp(tmp, -32768, 32767);
|
y0[i] = std::clamp(tmp, -32768, 32767);
|
||||||
}
|
}
|
||||||
|
|
||||||
y1 = y0;
|
y1 = y0;
|
||||||
|
@ -102,7 +102,7 @@ std::array<s16, 2> SourceFilters::BiquadFilter::ProcessSample(const std::array<s
|
||||||
std::array<s16, 2> y0;
|
std::array<s16, 2> y0;
|
||||||
for (size_t i = 0; i < 2; i++) {
|
for (size_t i = 0; i < 2; i++) {
|
||||||
const s32 tmp = (b0 * x0[i] + b1 * x1[i] + b2 * x2[i] + a1 * y1[i] + a2 * y2[i]) >> 14;
|
const s32 tmp = (b0 * x0[i] + b1 * x1[i] + b2 * x2[i] + a1 * y1[i] + a2 * y2[i]) >> 14;
|
||||||
y0[i] = MathUtil::Clamp(tmp, -32768, 32767);
|
y0[i] = std::clamp(tmp, -32768, 32767);
|
||||||
}
|
}
|
||||||
|
|
||||||
x2 = x1;
|
x2 = x1;
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
#include "audio_core/hle/mixers.h"
|
#include "audio_core/hle/mixers.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
namespace HLE {
|
namespace HLE {
|
||||||
|
@ -87,7 +86,7 @@ void Mixers::ParseConfig(DspConfiguration& config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static s16 ClampToS16(s32 value) {
|
static s16 ClampToS16(s32 value) {
|
||||||
return static_cast<s16>(MathUtil::Clamp(value, -32768, 32767));
|
return static_cast<s16>(std::clamp(value, -32768, 32767));
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::array<s16, 2> AddAndClampToS16(const std::array<s16, 2>& a,
|
static std::array<s16, 2> AddAndClampToS16(const std::array<s16, 2>& a,
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include "audio_core/interpolate.h"
|
#include "audio_core/interpolate.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
namespace AudioInterp {
|
namespace AudioInterp {
|
||||||
|
@ -63,8 +63,8 @@ void Linear(State& state, StereoBuffer16& input, float rate, StereoFrame16& outp
|
||||||
StepOverSamples(state, input, rate, output, outputi,
|
StepOverSamples(state, input, rate, output, outputi,
|
||||||
[](u64 fraction, const auto& x0, const auto& x1, const auto& x2) {
|
[](u64 fraction, const auto& x0, const auto& x1, const auto& x2) {
|
||||||
// This is a saturated subtraction. (Verified by black-box fuzzing.)
|
// This is a saturated subtraction. (Verified by black-box fuzzing.)
|
||||||
s64 delta0 = MathUtil::Clamp<s64>(x1[0] - x0[0], -32768, 32767);
|
s64 delta0 = std::clamp<s64>(x1[0] - x0[0], -32768, 32767);
|
||||||
s64 delta1 = MathUtil::Clamp<s64>(x1[1] - x0[1], -32768, 32767);
|
s64 delta1 = std::clamp<s64>(x1[1] - x0[1], -32768, 32767);
|
||||||
|
|
||||||
return std::array<s16, 2>{
|
return std::array<s16, 2>{
|
||||||
static_cast<s16>(x0[0] + fraction * delta0 / scale_factor),
|
static_cast<s16>(x0[0] + fraction * delta0 / scale_factor),
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -10,7 +11,6 @@
|
||||||
#include "audio_core/time_stretch.h"
|
#include "audio_core/time_stretch.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
|
|
||||||
using steady_clock = std::chrono::steady_clock;
|
using steady_clock = std::chrono::steady_clock;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ constexpr double MIN_RATIO = 0.1;
|
||||||
constexpr double MAX_RATIO = 100.0;
|
constexpr double MAX_RATIO = 100.0;
|
||||||
|
|
||||||
static double ClampRatio(double ratio) {
|
static double ClampRatio(double ratio) {
|
||||||
return MathUtil::Clamp(ratio, MIN_RATIO, MAX_RATIO);
|
return std::clamp(ratio, MIN_RATIO, MAX_RATIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr double MIN_DELAY_TIME = 0.05; // Units: seconds
|
constexpr double MIN_DELAY_TIME = 0.05; // Units: seconds
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include "citra_qt/camera/camera_util.h"
|
#include "citra_qt/camera/camera_util.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
#include "core/frontend/camera/factory.h"
|
#include "core/frontend/camera/factory.h"
|
||||||
#include "core/frontend/camera/interface.h"
|
#include "core/frontend/camera/interface.h"
|
||||||
|
|
||||||
|
@ -191,9 +191,10 @@ std::vector<u16> Rgb2Yuv(const QImage& source, int width, int height) {
|
||||||
if (write) {
|
if (write) {
|
||||||
pu = (pu + u) / 2;
|
pu = (pu + u) / 2;
|
||||||
pv = (pv + v) / 2;
|
pv = (pv + v) / 2;
|
||||||
using MathUtil::Clamp;
|
*(dest++) =
|
||||||
*(dest++) = static_cast<u16>(Clamp(py, 0, 0xFF) | (Clamp(pu, 0, 0xFF) << 8));
|
static_cast<u16>(std::clamp(py, 0, 0xFF) | (std::clamp(pu, 0, 0xFF) << 8));
|
||||||
*(dest++) = static_cast<u16>(Clamp(y, 0, 0xFF) | (Clamp(pv, 0, 0xFF) << 8));
|
*(dest++) =
|
||||||
|
static_cast<u16>(std::clamp(y, 0, 0xFF) | (std::clamp(pv, 0, 0xFF) << 8));
|
||||||
} else {
|
} else {
|
||||||
py = y;
|
py = y;
|
||||||
pu = u;
|
pu = u;
|
||||||
|
|
|
@ -17,11 +17,6 @@ inline bool IntervalsIntersect(unsigned start0, unsigned length0, unsigned start
|
||||||
return (std::max(start0, start1) < std::min(start0 + length0, start1 + length1));
|
return (std::max(start0, start1) < std::min(start0 + length0, start1 + length1));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
inline T Clamp(const T val, const T& min, const T& max) {
|
|
||||||
return std::max(min, std::min(max, val));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct Rectangle {
|
struct Rectangle {
|
||||||
T left;
|
T left;
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/color.h"
|
#include "common/color.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
#include "common/vector_math.h"
|
#include "common/vector_math.h"
|
||||||
#include "core/hle/service/y2r_u.h"
|
#include "core/hle/service/y2r_u.h"
|
||||||
#include "core/hw/y2r.h"
|
#include "core/hw/y2r.h"
|
||||||
|
@ -70,10 +69,9 @@ static void ConvertYUVToRGB(InputFormat input_format, const u8* input_Y, const u
|
||||||
unsigned int tile = x / 8;
|
unsigned int tile = x / 8;
|
||||||
unsigned int tile_x = x % 8;
|
unsigned int tile_x = x % 8;
|
||||||
u32* out = &output[tile][y * 8 + tile_x];
|
u32* out = &output[tile][y * 8 + tile_x];
|
||||||
|
*out = ((u32)std::clamp(r >> 5, 0, 0xFF) << 24) |
|
||||||
using MathUtil::Clamp;
|
((u32)std::clamp(g >> 5, 0, 0xFF) << 16) |
|
||||||
*out = ((u32)Clamp(r >> 5, 0, 0xFF) << 24) | ((u32)Clamp(g >> 5, 0, 0xFF) << 16) |
|
((u32)std::clamp(b >> 5, 0, 0xFF) << 8);
|
||||||
((u32)Clamp(b >> 5, 0, 0xFF) << 8);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "common/math_util.h"
|
|
||||||
#include "core/hw/gpu.h"
|
#include "core/hw/gpu.h"
|
||||||
#include "core/perf_stats.h"
|
#include "core/perf_stats.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
|
@ -92,7 +92,7 @@ void FrameLimiter::DoFrameLimiting(u64 current_system_time_us) {
|
||||||
(current_system_time_us - previous_system_time_us) / sleep_scale));
|
(current_system_time_us - previous_system_time_us) / sleep_scale));
|
||||||
frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime);
|
frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime);
|
||||||
frame_limiting_delta_err =
|
frame_limiting_delta_err =
|
||||||
MathUtil::Clamp(frame_limiting_delta_err, -max_lag_time_us, max_lag_time_us);
|
std::clamp(frame_limiting_delta_err, -max_lag_time_us, max_lag_time_us);
|
||||||
|
|
||||||
if (frame_limiting_delta_err > microseconds::zero()) {
|
if (frame_limiting_delta_err > microseconds::zero()) {
|
||||||
std::this_thread::sleep_for(frame_limiting_delta_err);
|
std::this_thread::sleep_for(frame_limiting_delta_err);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
@ -44,7 +45,7 @@ public:
|
||||||
tilt_angle = 0;
|
tilt_angle = 0;
|
||||||
} else {
|
} else {
|
||||||
tilt_direction = mouse_move.Cast<float>();
|
tilt_direction = mouse_move.Cast<float>();
|
||||||
tilt_angle = MathUtil::Clamp(tilt_direction.Normalize() * sensitivity, 0.0f,
|
tilt_angle = std::clamp(tilt_direction.Normalize() * sensitivity, 0.0f,
|
||||||
MathUtil::PI * this->tilt_clamp / 180.0f);
|
MathUtil::PI * this->tilt_clamp / 180.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
@ -540,16 +541,16 @@ bool RasterizerOpenGL::Draw(bool accelerate, bool is_indexed) {
|
||||||
: (depth_surface == nullptr ? 1u : depth_surface->res_scale);
|
: (depth_surface == nullptr ? 1u : depth_surface->res_scale);
|
||||||
|
|
||||||
MathUtil::Rectangle<u32> draw_rect{
|
MathUtil::Rectangle<u32> draw_rect{
|
||||||
static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.left) +
|
static_cast<u32>(std::clamp<s32>(static_cast<s32>(surfaces_rect.left) +
|
||||||
viewport_rect_unscaled.left * res_scale,
|
viewport_rect_unscaled.left * res_scale,
|
||||||
surfaces_rect.left, surfaces_rect.right)), // Left
|
surfaces_rect.left, surfaces_rect.right)), // Left
|
||||||
static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.bottom) +
|
static_cast<u32>(std::clamp<s32>(static_cast<s32>(surfaces_rect.bottom) +
|
||||||
viewport_rect_unscaled.top * res_scale,
|
viewport_rect_unscaled.top * res_scale,
|
||||||
surfaces_rect.bottom, surfaces_rect.top)), // Top
|
surfaces_rect.bottom, surfaces_rect.top)), // Top
|
||||||
static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.left) +
|
static_cast<u32>(std::clamp<s32>(static_cast<s32>(surfaces_rect.left) +
|
||||||
viewport_rect_unscaled.right * res_scale,
|
viewport_rect_unscaled.right * res_scale,
|
||||||
surfaces_rect.left, surfaces_rect.right)), // Right
|
surfaces_rect.left, surfaces_rect.right)), // Right
|
||||||
static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.bottom) +
|
static_cast<u32>(std::clamp<s32>(static_cast<s32>(surfaces_rect.bottom) +
|
||||||
viewport_rect_unscaled.bottom * res_scale,
|
viewport_rect_unscaled.bottom * res_scale,
|
||||||
surfaces_rect.bottom, surfaces_rect.top))}; // Bottom
|
surfaces_rect.bottom, surfaces_rect.top))}; // Bottom
|
||||||
|
|
||||||
|
|
|
@ -1359,14 +1359,11 @@ SurfaceSurfaceRect_Tuple RasterizerCacheOpenGL::GetFramebufferSurfaces(
|
||||||
}
|
}
|
||||||
|
|
||||||
MathUtil::Rectangle<u32> viewport_clamped{
|
MathUtil::Rectangle<u32> viewport_clamped{
|
||||||
|
static_cast<u32>(std::clamp(viewport_rect.left, 0, static_cast<s32>(config.GetWidth()))),
|
||||||
|
static_cast<u32>(std::clamp(viewport_rect.top, 0, static_cast<s32>(config.GetHeight()))),
|
||||||
|
static_cast<u32>(std::clamp(viewport_rect.right, 0, static_cast<s32>(config.GetWidth()))),
|
||||||
static_cast<u32>(
|
static_cast<u32>(
|
||||||
MathUtil::Clamp(viewport_rect.left, 0, static_cast<s32>(config.GetWidth()))),
|
std::clamp(viewport_rect.bottom, 0, static_cast<s32>(config.GetHeight())))};
|
||||||
static_cast<u32>(
|
|
||||||
MathUtil::Clamp(viewport_rect.top, 0, static_cast<s32>(config.GetHeight()))),
|
|
||||||
static_cast<u32>(
|
|
||||||
MathUtil::Clamp(viewport_rect.right, 0, static_cast<s32>(config.GetWidth()))),
|
|
||||||
static_cast<u32>(
|
|
||||||
MathUtil::Clamp(viewport_rect.bottom, 0, static_cast<s32>(config.GetHeight())))};
|
|
||||||
|
|
||||||
// get color and depth surfaces
|
// get color and depth surfaces
|
||||||
SurfaceParams color_params;
|
SurfaceParams color_params;
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/color.h"
|
#include "common/color.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
#include "common/vector_math.h"
|
#include "common/vector_math.h"
|
||||||
#include "core/hw/gpu.h"
|
#include "core/hw/gpu.h"
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
|
@ -301,8 +299,8 @@ Math::Vec4<u8> EvaluateBlendEquation(const Math::Vec4<u8>& src, const Math::Vec4
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Math::Vec4<u8>(MathUtil::Clamp(result.r(), 0, 255), MathUtil::Clamp(result.g(), 0, 255),
|
return Math::Vec4<u8>(std::clamp(result.r(), 0, 255), std::clamp(result.g(), 0, 255),
|
||||||
MathUtil::Clamp(result.b(), 0, 255), MathUtil::Clamp(result.a(), 0, 255));
|
std::clamp(result.b(), 0, 255), std::clamp(result.a(), 0, 255));
|
||||||
};
|
};
|
||||||
|
|
||||||
u8 LogicOp(u8 src, u8 dest, FramebufferRegs::LogicOp op) {
|
u8 LogicOp(u8 src, u8 dest, FramebufferRegs::LogicOp op) {
|
||||||
|
@ -400,7 +398,7 @@ void DrawShadowMapPixel(int x, int y, u32 depth, u8 stencil) {
|
||||||
float16 linear = float16::FromRaw(shadow.linear);
|
float16 linear = float16::FromRaw(shadow.linear);
|
||||||
float16 x = float16::FromFloat32(static_cast<float>(depth) / ref_z);
|
float16 x = float16::FromFloat32(static_cast<float>(depth) / ref_z);
|
||||||
float16 stencil_new = float16::FromFloat32(stencil) / (constant + linear * x);
|
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)
|
if (stencil < ref_s)
|
||||||
EncodeX24S8Shadow(stencil, dst_pixel);
|
EncodeX24S8Shadow(stencil, dst_pixel);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include "common/math_util.h"
|
#include <algorithm>
|
||||||
#include "video_core/swrasterizer/lighting.h"
|
#include "video_core/swrasterizer/lighting.h"
|
||||||
|
|
||||||
namespace Pica {
|
namespace Pica {
|
||||||
|
@ -96,10 +96,10 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
|
||||||
size_t lut =
|
size_t lut =
|
||||||
static_cast<size_t>(LightingRegs::LightingSampler::DistanceAttenuation) + num;
|
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 =
|
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;
|
float delta = sample_loc * 256 - lutindex;
|
||||||
dist_atten = LookupLightingLut(lighting_state, lut, lutindex, delta);
|
dist_atten = LookupLightingLut(lighting_state, lut, lutindex, delta);
|
||||||
}
|
}
|
||||||
|
@ -158,11 +158,11 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
|
||||||
result = std::max(result, 0.0f);
|
result = std::max(result, 0.0f);
|
||||||
|
|
||||||
float flr = std::floor(result * 256.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;
|
delta = result * 256 - index;
|
||||||
} else {
|
} else {
|
||||||
float flr = std::floor(result * 128.0f);
|
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;
|
delta = result * 128.0f - signed_index;
|
||||||
index = static_cast<u8>(signed_index);
|
index = static_cast<u8>(signed_index);
|
||||||
}
|
}
|
||||||
|
@ -316,15 +316,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
|
||||||
|
|
||||||
diffuse_sum += Math::MakeVec(lighting.global_ambient.ToVec3f(), 0.0f);
|
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,
|
auto diffuse = Math::MakeVec<float>(std::clamp(diffuse_sum.x, 0.0f, 1.0f) * 255,
|
||||||
MathUtil::Clamp(diffuse_sum.y, 0.0f, 1.0f) * 255,
|
std::clamp(diffuse_sum.y, 0.0f, 1.0f) * 255,
|
||||||
MathUtil::Clamp(diffuse_sum.z, 0.0f, 1.0f) * 255,
|
std::clamp(diffuse_sum.z, 0.0f, 1.0f) * 255,
|
||||||
MathUtil::Clamp(diffuse_sum.w, 0.0f, 1.0f) * 255)
|
std::clamp(diffuse_sum.w, 0.0f, 1.0f) * 255)
|
||||||
.Cast<u8>();
|
.Cast<u8>();
|
||||||
auto specular = Math::MakeVec<float>(MathUtil::Clamp(specular_sum.x, 0.0f, 1.0f) * 255,
|
auto specular = Math::MakeVec<float>(std::clamp(specular_sum.x, 0.0f, 1.0f) * 255,
|
||||||
MathUtil::Clamp(specular_sum.y, 0.0f, 1.0f) * 255,
|
std::clamp(specular_sum.y, 0.0f, 1.0f) * 255,
|
||||||
MathUtil::Clamp(specular_sum.z, 0.0f, 1.0f) * 255,
|
std::clamp(specular_sum.z, 0.0f, 1.0f) * 255,
|
||||||
MathUtil::Clamp(specular_sum.w, 0.0f, 1.0f) * 255)
|
std::clamp(specular_sum.w, 0.0f, 1.0f) * 255)
|
||||||
.Cast<u8>();
|
.Cast<u8>();
|
||||||
return std::make_tuple(diffuse, specular);
|
return std::make_tuple(diffuse, specular);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include "common/color.h"
|
#include "common/color.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
#include "common/microprofile.h"
|
#include "common/microprofile.h"
|
||||||
#include "common/quaternion.h"
|
#include "common/quaternion.h"
|
||||||
#include "common/vector_math.h"
|
#include "common/vector_math.h"
|
||||||
|
@ -271,7 +270,7 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clamp the result
|
// Clamp the result
|
||||||
depth = MathUtil::Clamp(depth, 0.0f, 1.0f);
|
depth = std::clamp(depth, 0.0f, 1.0f);
|
||||||
|
|
||||||
// Perspective correct attribute interpolation:
|
// Perspective correct attribute interpolation:
|
||||||
// Attribute values cannot be calculated by simple linear interpolation since
|
// 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
|
// 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;
|
float fog_f = fog_index - fog_i;
|
||||||
const auto& fog_lut_entry = g_state.fog.lut[static_cast<unsigned int>(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;
|
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
|
// Blend the fog
|
||||||
for (unsigned i = 0; i < 3; i++) {
|
for (unsigned i = 0; i < 3; i++) {
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
#include "common/vector_math.h"
|
#include "common/vector_math.h"
|
||||||
#include "video_core/regs_texturing.h"
|
#include "video_core/regs_texturing.h"
|
||||||
#include "video_core/swrasterizer/texturing.h"
|
#include "video_core/swrasterizer/texturing.h"
|
||||||
|
@ -148,9 +146,9 @@ Math::Vec3<u8> ColorCombine(TevStageConfig::Operation op, const Math::Vec3<u8> i
|
||||||
// (byte) 128 is correct
|
// (byte) 128 is correct
|
||||||
auto result =
|
auto result =
|
||||||
input[0].Cast<int>() + input[1].Cast<int>() - Math::MakeVec<int>(128, 128, 128);
|
input[0].Cast<int>() + input[1].Cast<int>() - Math::MakeVec<int>(128, 128, 128);
|
||||||
result.r() = MathUtil::Clamp<int>(result.r(), 0, 255);
|
result.r() = std::clamp<int>(result.r(), 0, 255);
|
||||||
result.g() = MathUtil::Clamp<int>(result.g(), 0, 255);
|
result.g() = std::clamp<int>(result.g(), 0, 255);
|
||||||
result.b() = MathUtil::Clamp<int>(result.b(), 0, 255);
|
result.b() = std::clamp<int>(result.b(), 0, 255);
|
||||||
return result.Cast<u8>();
|
return result.Cast<u8>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +216,7 @@ u8 AlphaCombine(TevStageConfig::Operation op, const std::array<u8, 3>& input) {
|
||||||
case Operation::AddSigned: {
|
case Operation::AddSigned: {
|
||||||
// TODO(bunnei): Verify that the color conversion from (float) 0.5f to (byte) 128 is correct
|
// 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;
|
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:
|
case Operation::Lerp:
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "common/bit_field.h"
|
#include "common/bit_field.h"
|
||||||
#include "common/color.h"
|
#include "common/color.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
#include "common/vector_math.h"
|
#include "common/vector_math.h"
|
||||||
#include "video_core/texture/etc1.h"
|
#include "video_core/texture/etc1.h"
|
||||||
|
|
||||||
|
@ -110,9 +110,9 @@ union ETC1Tile {
|
||||||
if (GetNegationFlag(texel))
|
if (GetNegationFlag(texel))
|
||||||
modifier *= -1;
|
modifier *= -1;
|
||||||
|
|
||||||
ret.r() = MathUtil::Clamp(ret.r() + modifier, 0, 255);
|
ret.r() = std::clamp(ret.r() + modifier, 0, 255);
|
||||||
ret.g() = MathUtil::Clamp(ret.g() + modifier, 0, 255);
|
ret.g() = std::clamp(ret.g() + modifier, 0, 255);
|
||||||
ret.b() = MathUtil::Clamp(ret.b() + modifier, 0, 255);
|
ret.b() = std::clamp(ret.b() + modifier, 0, 255);
|
||||||
|
|
||||||
return ret.Cast<u8>();
|
return ret.Cast<u8>();
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue