57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <XCEngine/Core/Math/Vector4.h>
|
|
#include <XCEngine/Core/Types.h>
|
|
|
|
namespace XCEngine {
|
|
namespace Rendering {
|
|
|
|
using RenderObjectId = Core::uint32;
|
|
using EncodedObjectId = RenderObjectId;
|
|
|
|
static constexpr RenderObjectId kInvalidRenderObjectId = 0u;
|
|
|
|
inline bool IsValidRenderObjectId(RenderObjectId renderObjectId) {
|
|
return renderObjectId != kInvalidRenderObjectId;
|
|
}
|
|
|
|
inline EncodedObjectId EncodeRenderObjectIdToEncodedId(RenderObjectId renderObjectId) {
|
|
return renderObjectId;
|
|
}
|
|
|
|
inline EncodedObjectId EncodeRenderObjectIdToUInt32(RenderObjectId renderObjectId) {
|
|
return EncodeRenderObjectIdToEncodedId(renderObjectId);
|
|
}
|
|
|
|
inline Math::Vector4 EncodeRenderObjectIdToColor(RenderObjectId renderObjectId) {
|
|
const EncodedObjectId encodedId = EncodeRenderObjectIdToEncodedId(renderObjectId);
|
|
constexpr float kInv255 = 1.0f / 255.0f;
|
|
return Math::Vector4(
|
|
static_cast<float>((encodedId >> 0) & 0xFFu) * kInv255,
|
|
static_cast<float>((encodedId >> 8) & 0xFFu) * kInv255,
|
|
static_cast<float>((encodedId >> 16) & 0xFFu) * kInv255,
|
|
static_cast<float>((encodedId >> 24) & 0xFFu) * kInv255);
|
|
}
|
|
|
|
inline EncodedObjectId DecodeEncodedObjectIdFromColor(
|
|
Core::uint8 r,
|
|
Core::uint8 g,
|
|
Core::uint8 b,
|
|
Core::uint8 a) {
|
|
return static_cast<EncodedObjectId>(r) |
|
|
(static_cast<EncodedObjectId>(g) << 8u) |
|
|
(static_cast<EncodedObjectId>(b) << 16u) |
|
|
(static_cast<EncodedObjectId>(a) << 24u);
|
|
}
|
|
|
|
inline RenderObjectId DecodeRenderObjectIdFromColor(
|
|
Core::uint8 r,
|
|
Core::uint8 g,
|
|
Core::uint8 b,
|
|
Core::uint8 a) {
|
|
return DecodeEncodedObjectIdFromColor(r, g, b, a);
|
|
}
|
|
|
|
} // namespace Rendering
|
|
} // namespace XCEngine
|