3#include <alicorn/std/string.hpp>
4#include <alicorn/std/string/encoding.hpp>
5#include <alicorn/std/regex.hpp>
6#include <alicorn/std/vector.hpp>
7#include <boost/algorithm/string/replace.hpp>
8#include <Covellite/Api/Component.inl>
9#include <Covellite/Api/Defines.hpp>
11namespace covellite::api::renderer
31 using String_t = ::alicorn::extension::std::String;
49class Component::Rasterizer
52 const String_t CullMode;
55 explicit Rasterizer(Component_t & _Component) :
56 CullMode(_Component[uT(
"cull")].Default(uT(
"Back")))
60 Rasterizer(
const Rasterizer &) =
delete;
61 Rasterizer(Rasterizer &&) =
delete;
62 Rasterizer & operator= (
const Rasterizer &) =
delete;
63 Rasterizer & operator= (Rasterizer &&) =
delete;
64 ~Rasterizer(
void) =
default;
67class Component::Scissor
75 const uint8_t Align[3] = { 0 };
78 explicit Scissor(Component_t & _Component) :
79 Left(_Component[uT(
"left")].Default(0)),
80 Top(_Component[uT(
"top")].Default(0)),
81 Right(_Component[uT(
"right")].Default(0)),
82 Bottom(_Component[uT(
"bottom")].Default(0)),
83 IsEnabled(_Component[uT(
"enabled")].Default(false))
87 Scissor(
const Scissor &) =
delete;
88 Scissor(Scissor &&) =
delete;
89 Scissor & operator= (
const Scissor &) =
delete;
90 Scissor & operator= (Scissor &&) =
delete;
91 ~Scissor(
void) =
default;
95class Component::Buffer
97 using Buffers_t = ::std::vector<Buffer_t<T>>;
99 static const Buffer_t<T> & GetFakeData(
void)
noexcept
101 static const Buffer_t<T> FakeData;
106 const size_t DataCount;
107 const Buffer_t<T> Data;
109 const uint8_t Align[4] = { 0 };
112 inline static size_t GetDataCount(
113 Component_t & _Component,
114 const Buffer_t<T> & _Data)
116 return _Component[uT(
"content")].IsType<Buffers_t>() ?
117 ::std::size((Buffers_t &)_Component[uT(
"content")].Default(Buffers_t{ _Data })) : 1;
120 inline static Buffer_t<T> GetContent(
121 Component_t & _Component,
122 const Buffer_t<T> & _Data)
124 if (_Component[uT(
"content")].IsType<Buffer_t<T>>())
126 return ::std::move((Buffer_t<T> &)_Component[uT(
"content")].Default(_Data));
129 using namespace ::alicorn::extension::std;
131 const Buffers_t Buffers =
132 ::std::move((Buffers_t &)_Component[uT(
"content")].Default(Buffers_t{ _Data }));
134 Buffer_t<T> AllTextureArrayData;
135 for (
const auto & Data : Buffers) AllTextureArrayData += Data;
137 return AllTextureArrayData;
141 explicit Buffer(Component_t & _Component,
const Buffer_t<T> & _Data = GetFakeData()) :
142 DataCount(GetDataCount(_Component, _Data)),
143 Data(GetContent(_Component, _Data)),
144 Dimension(_Component[uT(
"dimension")].Default(3))
147 Buffer(
const Buffer &) =
delete;
148 Buffer(Buffer &&) =
delete;
149 Buffer & operator= (
const Buffer &) =
delete;
150 Buffer & operator= (Buffer &&) =
delete;
151 ~Buffer(
void) =
default;
154class Component::Texture :
155 public Buffer<uint8_t>
158 const uint8_t *
const pTextureData;
162 const String_t Destination;
165 const bool IsUsingMipmapping;
166 const bool IsMapping;
168 const uint8_t Align[6] = { 0 };
171 Texture(Component_t & _Component,
const String_t & _DefaultDestination) :
173 pTextureData(Data.empty() ? nullptr : Data.data()),
174 Width(_Component[uT(
"width")].Default(0)),
175 Height(_Component[uT(
"height")].Default(0)),
176 Name(_Component[uT(
"name")].Default(uT(
"Unknown"))),
177 Destination(_Component[uT(
"destination")].Default(_DefaultDestination)),
178 Index(_Component[uT(
"index")].Default(-1)),
179 Capacity(_Component[uT(
"capacity")].Default(8)),
180 IsUsingMipmapping(_Component[uT(
"mipmapping")].Default(false)),
181 IsMapping(_Component[uT(
"mapper")].IsType<const cbBufferMap_t<const void> &>())
185 Texture(
const Texture &) =
delete;
186 Texture(Texture &&) =
delete;
187 Texture & operator= (
const Texture &) =
delete;
188 Texture & operator= (Texture &&) =
delete;
189 ~Texture(
void) =
default;
192class Component::Shader :
193 public Buffer<uint8_t>
196 const ::std::string Entry;
197 ::std::string ReturnType;
199 const ::std::vector<String_t> Instance;
202 static String_t GetShaderType(
203 const ::std::string & _Entry,
204 const uint8_t * _pBegin,
205 const uint8_t * _pEnd,
206 ::std::string & _ReturnType)
211 const auto * pLastBreak = _pBegin;
215 const auto * pBreak = ::std::find(pLastBreak, _pEnd,
'\n');
218 throw STD_EXCEPTION <<
"Entry point not found: " << _Entry;
221 const ::std::string Line{ pLastBreak, pBreak };
222 const auto EntryPosition = Line.find(
" " + _Entry +
"(", 0);
223 if (EntryPosition != ::std::string::npos)
225 _ReturnType = Line.substr(0, Line.find(
" ", 0));
227 const auto TypeBegin = EntryPosition + _Entry.length()
229 const auto TypeEnd = Line.find(
" ", TypeBegin);
231 using namespace ::alicorn::extension::std;
233 return string_cast<String, Encoding::Ascii128>(
234 Line.substr(TypeBegin, TypeEnd - TypeBegin));
237 pLastBreak = pBreak + 1;
241 static ::std::vector<String_t> GetInstance(
const String_t _Value)
243 ::std::vector<String_t> Result;
245 if (_Value == uT(
""))
return Result;
247 namespace regex = ::alicorn::extension::std::regex;
249 regex::Match mInstanceDataStruct{ uT(
"(?:[if]4)*") };
250 if (!mInstanceDataStruct.IsMatch(_Value))
252 throw STD_EXCEPTION <<
"Unexpected instance value: " << _Value;
255 regex::Search sInstanceDataStruct{ uT(
"(?:([if])4)") };
256 if (!sInstanceDataStruct.IsSearch(_Value))
return Result;
258 const auto & Elements = sInstanceDataStruct.GetCoincided();
260 for (::std::size_t i = 0; i < Elements.size(); i++)
262 Result.push_back(Elements[i].second[0]);
268 ::std::string GetInstanceInput(const ::std::string & _Input)
const
270 static const ::std::string InstanceBlockDeclaration =
271 "/* place for instance variables */";
272 ::std::string InstanceBlockImplementation;
274 for (::std::size_t i = 0; i < Instance.size(); i++)
276 const auto Index = ::std::to_string(i + 1);
278 (Instance[i] == uT(
"f")) ?
"float4" :
279 (Instance[i] == uT(
"i")) ?
"int4" :
"";
281 InstanceBlockImplementation += ::std::string{
"COVELLITE_IN " } +
282 Type +
" iValue" + Index +
" COVELLITE_INPUT_SEMANTIC(TEXCOORD" +
283 Index +
");" +
char{ 0x5C } +
"\r\n";
286 return ::boost::algorithm::replace_first_copy(_Input,
287 InstanceBlockDeclaration, InstanceBlockImplementation);
291 inline BinaryData_t GetInstanceInput(
const BinaryData_t & _Input)
const
293 if (Instance.empty())
return _Input;
295 const auto strInput =
296 GetInstanceInput(::std::string{ _Input.cbegin(), _Input.cend() });
297 return BinaryData_t{ strInput.cbegin(), strInput.cend() };
300 ::std::string GetInstanceCopyData(
void)
const
302 ::std::string InstanceCopyDataImplementation;
304 for (::std::size_t i = 0; i < Instance.size(); i++)
306 const auto iValue =
"iValue" + ::std::to_string(i + 1);
308 InstanceCopyDataImplementation +=
309 " InputData." + iValue +
" = " + iValue +
";\r\n";
312 return InstanceCopyDataImplementation;
316 Shader(Component_t & _Component,
const BinaryData_t & _Data) :
317 Buffer(_Component, _Data),
318 Entry((const ::std::string &)_Component[uT(
"entry")].Default(
"Unknown")),
319 Kind(GetShaderType(Entry, Data.data(), Data.data() + Data.size(), ReturnType)),
320 Instance{ GetInstance(_Component[uT(
"instance")].Default(uT(
""))) }
323 Shader(
const Shader &) =
delete;
324 Shader(Shader &&) =
delete;
325 Shader & operator= (
const Shader &) =
delete;
326 Shader & operator= (Shader &&) =
delete;
327 ~Shader(
void) =
default;
330class Component::Transform
333 inline static size_t GetHashX(
void)
335 static const size_t Hash = ::std::hash<String_t>{}(uT(
"x"));
339 inline static size_t GetHashY(
void)
341 static const size_t Hash = ::std::hash<String_t>{}(uT(
"y"));
345 inline static size_t GetHashZ(
void)
347 static const size_t Hash = ::std::hash<String_t>{}(uT(
"z"));
357 Transform(Component_t & _Component,
const float _DefaultValue) :
358 X(_Component[GetHashX()].Default(_DefaultValue)),
359 Y(_Component[GetHashY()].Default(_DefaultValue)),
360 Z(_Component[GetHashZ()].Default(_DefaultValue))
364 Transform(
const Transform &) =
delete;
365 Transform(Transform &&) =
delete;
366 Transform & operator= (
const Transform &) =
delete;
367 Transform & operator= (Transform &&) =
delete;
368 ~Transform(
void) =
default;
371class Component::Position :
375 explicit Position(Component_t & _Component) :
376 Transform(_Component, 0.0f)
380 Position(
const Position &) =
delete;
381 Position(Position &&) =
delete;
382 Position & operator= (
const Position &) =
delete;
383 Position & operator= (Position &&) =
delete;
384 ~Position(
void) =
default;
387class Component::Rotation :
391 explicit Rotation(Component_t & _Component) :
392 Transform(_Component, 0.0f)
396 Rotation(
const Rotation &) =
delete;
397 Rotation(Rotation &&) =
delete;
398 Rotation & operator= (
const Rotation &) =
delete;
399 Rotation & operator= (Rotation &&) =
delete;
400 ~Rotation(
void) =
default;
403class Component::Scale :
407 explicit Scale(Component_t & _Component) :
408 Transform(_Component, 1.0f)
412 Scale(
const Scale &) =
delete;
413 Scale(Scale &&) =
delete;
414 Scale & operator= (
const Scale &) =
delete;
415 Scale & operator= (Scale &&) =
delete;
416 ~Scale(
void) =
default;
422 const uint32_t Color;
428 explicit Fog(Component_t & _Component) :
429 Color(_Component[uT(
"color")].Default(0xFFFFFFFF)),
430 Near(_Component[uT(
"near")].Default(10.0f)),
431 Far(_Component[uT(
"far")].Default(100.0f)),
432 Density(_Component[uT(
"density")].Default(1.0f))
436 Fog(
const Fog &) =
delete;
437 Fog(Fog &&) =
delete;
438 Fog & operator= (
const Fog &) =
delete;
439 Fog & operator= (Fog &&) =
delete;
440 ~Fog(
void) =
default;
Класс входит в проект Covellite.Api Класс компонента.
Definition Component.hpp:35
Класс входит в проект Covellite.Api Вспомогательный класс для извлечения данных компонентов.
Definition Component.hpp:30