Files
XCEngine/tests/Rendering/unit/test_object_id_encoding.cpp

34 lines
1.1 KiB
C++

#include <gtest/gtest.h>
#include <XCEngine/Rendering/Picking/ObjectIdCodec.h>
using namespace XCEngine::Rendering;
TEST(ObjectIdEncoding_Test, EncodesOnlyLow32BitsIntoPickingId) {
constexpr uint64_t objectId = 0x123456789ABCDEF0ull;
EXPECT_FALSE(CanEncodeObjectIdWithoutLoss(objectId));
EXPECT_EQ(EncodeObjectIdToEncodedId(objectId), 0x9ABCDEF0u);
EXPECT_EQ(EncodeObjectIdToUInt32(objectId), 0x9ABCDEF0u);
}
TEST(ObjectIdEncoding_Test, DecodesColorBackToWidenedRuntimeId) {
constexpr uint8_t r = 0x12u;
constexpr uint8_t g = 0x34u;
constexpr uint8_t b = 0x56u;
constexpr uint8_t a = 0x78u;
EXPECT_EQ(DecodeEncodedObjectIdFromColor(r, g, b, a), 0x78563412u);
EXPECT_EQ(DecodeObjectIdFromColor(r, g, b, a), 0x78563412ull);
}
TEST(ObjectIdEncoding_Test, EncodesColorChannelsFromLow32Bits) {
const auto encodedColor = EncodeObjectIdToColor(0x78563412ull);
constexpr float kInv255 = 1.0f / 255.0f;
EXPECT_FLOAT_EQ(encodedColor.x, 0x12u * kInv255);
EXPECT_FLOAT_EQ(encodedColor.y, 0x34u * kInv255);
EXPECT_FLOAT_EQ(encodedColor.z, 0x56u * kInv255);
EXPECT_FLOAT_EQ(encodedColor.w, 0x78u * kInv255);
}