summaryrefslogtreecommitdiffstats
path: root/Common/interface
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-04-04 05:38:37 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-04-04 05:38:37 +0000
commit29658532537e1db4ea4ab8142133407fd1e2f8ed (patch)
tree95311f98f4741741d26994b74e879e73064aff6c /Common/interface
parentTextureUploaderGL: fixed issue with row stride that must be at least 32-bit a... (diff)
downloadDiligentCore-29658532537e1db4ea4ab8142133407fd1e2f8ed.tar.gz
DiligentCore-29658532537e1db4ea4ab8142133407fd1e2f8ed.zip
Math lib: added RGBA8Unorm_To_F4Color and F4Color_To_RGBA8Unorm functions
Diffstat (limited to 'Common/interface')
-rw-r--r--Common/interface/BasicMath.hpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/Common/interface/BasicMath.hpp b/Common/interface/BasicMath.hpp
index 81f646fb..867c91cd 100644
--- a/Common/interface/BasicMath.hpp
+++ b/Common/interface/BasicMath.hpp
@@ -1919,6 +1919,29 @@ T min3(const T& x, const T& y, const T& z)
return std::min(std::min(x, y), z);
}
+inline float4 RGBA8Unorm_To_F4Color(Uint32 RGBA8)
+{
+ // clang-format off
+ return float4
+ {
+ static_cast<float>((RGBA8 >> 0u) & 0xFF) / 255.f,
+ static_cast<float>((RGBA8 >> 8u) & 0xFF) / 255.f,
+ static_cast<float>((RGBA8 >> 16u) & 0xFF) / 255.f,
+ static_cast<float>((RGBA8 >> 24u) & 0xFF) / 255.f
+ };
+ // clang-format on
+}
+
+inline Uint32 F4Color_To_RGBA8Unorm(const float4& f4Color)
+{
+ Uint32 RGBA8U = 0;
+ RGBA8U |= static_cast<Uint32>(clamp(f4Color.r, 0.f, 1.f) * 255.f) << 0u;
+ RGBA8U |= static_cast<Uint32>(clamp(f4Color.g, 0.f, 1.f) * 255.f) << 8u;
+ RGBA8U |= static_cast<Uint32>(clamp(f4Color.b, 0.f, 1.f) * 255.f) << 16u;
+ RGBA8U |= static_cast<Uint32>(clamp(f4Color.a, 0.f, 1.f) * 255.f) << 24u;
+ return RGBA8U;
+}
+
} // namespace Diligent