3 #include <alicorn/cpp/math.hpp>
4 #include <alicorn/std/string.hpp>
5 #include <alicorn/std.fast/unordered-map.hpp>
6 #include "GraphicApi.hpp"
17 class GraphicApi::Constants
24 using CameraId_t = String_t;
26 using DataPtr_t = ::std::shared_ptr<Data<T>>;
35 template<
class,
template <
class>
class,
class ... TArgs>
36 void Create(TArgs && ...);
38 Data<T> & GetBuffer(
void);
42 ::alicorn::extension::std::fast::unordered_map<::std::size_t, ::covellite::Any_t> m_Data;
43 CameraId_t m_CurrentCameraId;
47 class GraphicApi::Constants::Data
53 virtual void Update(
void)
const = 0;
56 Data(
void) noexcept { memset(&m_Data, 0,
sizeof(m_Data)); }
57 Data(
const Data &) =
delete;
58 Data(Data &&) =
delete;
59 Data & operator= (
const Data &) =
delete;
60 Data & operator= (Data &&) =
delete;
61 virtual ~Data(
void) =
default;
64 template<
class T,
template <
class>
class TBuffer,
class ... TArgs>
65 void GraphicApi::Constants::Create(TArgs && ... _Args)
67 static const auto hCode =
typeid(T).hash_code();
69 const DataPtr_t<T> pBuffer = ::std::make_shared<TBuffer<T>>(_Args ...);
70 m_Data[hCode] = pBuffer;
74 inline T & GraphicApi::Constants::Get(
void)
76 return GetBuffer<T>().m_Data;
80 inline void GraphicApi::Constants::Update(
void)
82 GetBuffer<T>().Update();
86 auto GraphicApi::Constants::GetBuffer(
void) -> Data<T> &
88 static const auto hCode =
typeid(T).hash_code();
90 const auto itConstant = m_Data.find(hCode);
91 if (itConstant == m_Data.end())
93 throw STD_EXCEPTION <<
"Unexpected type: " <<
typeid(T).name();
96 return *::covellite::any_cast<DataPtr_t<T> &>(itConstant->second);
99 template<
template <
class>
class TBuffer,
class ... TArgs>
100 void GraphicApi::MakeConstants(TArgs && ... _Args)
102 m_pConstants = ::std::make_shared<Constants>();
103 m_pConstants->Create<::Camera, TBuffer>(_Args ...);
104 m_pConstants->Create<::Object, TBuffer>(_Args ...);
107 template<
class TColor>
108 TColor GraphicApi::ARGBtoFloat4(uint32_t _HexColor)
112 ((_HexColor & 0x00FF0000) >> 16) / 255.0f,
113 ((_HexColor & 0x0000FF00) >> 8) / 255.0f,
114 ((_HexColor & 0x000000FF) >> 0) / 255.0f,
115 ((_HexColor & 0xFF000000) >> 24) / 255.0f