19#include "aeongames/ProtoBufUtils.hpp"
20#include "aeongames/CRC.hpp"
21#include "aeongames/Mesh.hpp"
23#pragma warning( push )
24#pragma warning( disable : PROTOBUF_WARNINGS )
26#include "reference.pb.h"
27#include "pipeline.pb.h"
28#include "property.pb.h"
29#include "vector3.pb.h"
30#include "quaternion.pb.h"
31#include "transform.pb.h"
40 static_assert (
static_cast<uint32_t
> (
Mesh::BYTE ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeType_BYTE ),
"Mesh AttributeType and MeshMSG AttributeType do not match" );
41 static_assert (
static_cast<uint32_t
> (
Mesh::UNSIGNED_BYTE ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeType_UNSIGNED_BYTE ),
"Mesh AttributeType and MeshMSG AttributeType do not match" );
42 static_assert (
static_cast<uint32_t
> (
Mesh::HALF_FLOAT ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeType_HALF_FLOAT ),
"Mesh AttributeType and MeshMSG AttributeType do not match" );
43 static_assert (
static_cast<uint32_t
> (
Mesh::INT ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeType_INT ),
"Mesh AttributeType and MeshMSG AttributeType do not match" );
44 static_assert (
static_cast<uint32_t
> (
Mesh::UNSIGNED_INT ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeType_UNSIGNED_INT ),
"Mesh AttributeType and MeshMSG AttributeType do not match" );
45 static_assert (
static_cast<uint32_t
> (
Mesh::FLOAT ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeType_FLOAT ),
"Mesh AttributeType and MeshMSG AttributeType do not match" );
46 static_assert (
static_cast<uint32_t
> (
Mesh::FIXED ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeType_FIXED ),
"Mesh AttributeType and MeshMSG AttributeType do not match" );
47 static_assert (
static_cast<uint32_t
> (
Mesh::DOUBLE ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeType_DOUBLE ),
"Mesh AttributeType and MeshMSG AttributeType do not match" );
48 static_assert (
static_cast<uint32_t
> (
Mesh::SHORT ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeType_SHORT ),
"Mesh AttributeType and MeshMSG AttributeType do not match" );
49 static_assert (
static_cast<uint32_t
> (
Mesh::UNSIGNED_SHORT ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeType_UNSIGNED_SHORT ),
"Mesh AttributeType and MeshMSG AttributeType do not match" );
51 static_assert (
static_cast<uint32_t
> (
Mesh::POSITION ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeSemantic_POSITION ),
"Mesh AttributeSemantic and MeshMSG AttributeSemantic do not match" );
52 static_assert (
static_cast<uint32_t
> (
Mesh::NORMAL ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeSemantic_NORMAL ),
"Mesh AttributeSemantic and MeshMSG AttributeSemantic do not match" );
53 static_assert (
static_cast<uint32_t
> (
Mesh::TANGENT ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeSemantic_TANGENT ),
"Mesh AttributeSemantic and MeshMSG AttributeSemantic do not match" );
54 static_assert (
static_cast<uint32_t
> (
Mesh::BITANGENT ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeSemantic_BITANGENT ),
"Mesh AttributeSemantic and MeshMSG AttributeSemantic do not match" );
55 static_assert (
static_cast<uint32_t
> (
Mesh::TEXCOORD ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeSemantic_TEXCOORD ),
"Mesh AttributeSemantic and MeshMSG AttributeSemantic do not match" );
56 static_assert (
static_cast<uint32_t
> (
Mesh::WEIGHT_INDEX ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeSemantic_WEIGHT_INDEX ),
"Mesh AttributeSemantic and MeshMSG AttributeSemantic do not match" );
57 static_assert (
static_cast<uint32_t
> (
Mesh::WEIGHT_VALUE ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeSemantic_WEIGHT_VALUE ),
"Mesh AttributeSemantic and MeshMSG AttributeSemantic do not match" );
58 static_assert (
static_cast<uint32_t
> (
Mesh::COLOR ) ==
static_cast<uint32_t
> ( AttributeMsg_AttributeSemantic_COLOR ),
"Mesh AttributeSemantic and MeshMSG AttributeSemantic do not match" );
62 switch ( reference_buffer.reference_case() )
64 case ReferenceMsg::kPath:
65 return crc32i ( reference_buffer.path().c_str(), reference_buffer.path().size() );
66 case ReferenceMsg::kId:
67 return reference_buffer.id();
75 return {aVector3.x(), aVector3.y(), aVector3.z() };
79 return {aQuaternion.w(), aQuaternion.x(), aQuaternion.y(), aQuaternion.z() };
94 switch ( aComponentPropertyMsg.value_case() )
96 case ComponentPropertyMsg::kInt:
97 return static_cast<int> ( aComponentPropertyMsg.int_() );
98 case ComponentPropertyMsg::kLong:
99 return static_cast<long> ( aComponentPropertyMsg.long_() );
100 case ComponentPropertyMsg::kLongLong:
101 return static_cast<long long> ( aComponentPropertyMsg.long_long() );
102 case ComponentPropertyMsg::kUnsigned:
103 return static_cast<unsigned> ( aComponentPropertyMsg.int_() );
104 case ComponentPropertyMsg::kUnsignedLong:
105 return static_cast<long> ( aComponentPropertyMsg.unsigned_long() );
106 case ComponentPropertyMsg::kUnsignedLongLong:
107 return static_cast<long long> ( aComponentPropertyMsg.unsigned_long_long() );
108 case ComponentPropertyMsg::kFloat:
109 return static_cast<float> ( aComponentPropertyMsg.float_() );
110 case ComponentPropertyMsg::kDouble:
111 return static_cast<double> ( aComponentPropertyMsg.double_() );
112 case ComponentPropertyMsg::kString:
113 return aComponentPropertyMsg.string();
114 case ComponentPropertyMsg::kPath:
115 return std::filesystem::path ( aComponentPropertyMsg.string() );
116 case ComponentPropertyMsg::VALUE_NOT_SET:
118 throw std::runtime_error (
"Component property value not set." );
127 for (
auto& i : aPipelineMsg.uniform() )
131 case UniformDescriptorMsg::SCALAR_FLOAT:
132 size += ( size %
sizeof ( float ) ) ?
sizeof (
float ) - ( size %
sizeof ( float ) ) : 0;
133 size +=
sizeof ( float );
135 case UniformDescriptorMsg::SCALAR_UINT:
136 size += ( size %
sizeof ( uint32_t ) ) ?
sizeof ( uint32_t ) - ( size %
sizeof ( uint32_t ) ) : 0;
137 size +=
sizeof ( uint32_t );
139 case UniformDescriptorMsg::SCALAR_INT:
140 size += ( size %
sizeof ( int32_t ) ) ?
sizeof ( int32_t ) - ( size %
sizeof ( int32_t ) ) : 0;
141 size +=
sizeof ( int32_t );
143 case UniformDescriptorMsg::VECTOR_FLOAT_2:
144 size += ( size % (
sizeof ( float ) * 2 ) ) ? (
sizeof (
float ) * 2 ) - ( size % (
sizeof ( float ) * 2 ) ) : 0;
145 size +=
sizeof ( float ) * 2;
147 case UniformDescriptorMsg::VECTOR_FLOAT_3:
148 size += ( size % (
sizeof ( float ) * 4 ) ) ? (
sizeof (
float ) * 4 ) - ( size % (
sizeof ( float ) * 4 ) ) : 0;
149 size +=
sizeof ( float ) * 3;
151 case UniformDescriptorMsg::VECTOR_FLOAT_4:
152 size += ( size % (
sizeof ( float ) * 4 ) ) ? (
sizeof (
float ) * 4 ) - ( size % (
sizeof ( float ) * 4 ) ) : 0;
153 size +=
sizeof ( float ) * 4;
159 return size + ( size % (
sizeof ( float ) * 4 ) ) ? (
sizeof (
float ) * 4 ) - ( size % (
sizeof ( float ) * 4 ) ) : 0;
164 switch ( aProperty.value_case() )
166 case PropertyMsg::ValueCase::kScalarFloat:
168 case PropertyMsg::ValueCase::kScalarUint:
170 case PropertyMsg::ValueCase::kScalarInt:
172 case PropertyMsg::ValueCase::kVector2:
174 case PropertyMsg::ValueCase::kVector3:
176 case PropertyMsg::ValueCase::kVector4:
177 return Material::UniformKeyValue{aProperty.name(),
Vector4{aProperty.vector4().x(), aProperty.vector4().y(), aProperty.vector4().z(), aProperty.vector4().w() }};
178 case PropertyMsg::ValueCase::kMatrix4X4:
181 aProperty.matrix4x4().m0(),
182 aProperty.matrix4x4().m1(),
183 aProperty.matrix4x4().m2(),
184 aProperty.matrix4x4().m3(),
185 aProperty.matrix4x4().m4(),
186 aProperty.matrix4x4().m5(),
187 aProperty.matrix4x4().m6(),
188 aProperty.matrix4x4().m7(),
189 aProperty.matrix4x4().m8(),
190 aProperty.matrix4x4().m9(),
191 aProperty.matrix4x4().m10(),
192 aProperty.matrix4x4().m11(),
193 aProperty.matrix4x4().m12(),
194 aProperty.matrix4x4().m13(),
195 aProperty.matrix4x4().m14(),
196 aProperty.matrix4x4().m15()
201 throw std::runtime_error (
"Property contained no value." );
Provides the DLL_PROTOBUF export/import macro for protobuf wrapper classes.
std::tuple< std::string, UniformValue > UniformKeyValue
Key-value pair mapping a uniform name to its value.
4 by 4 matrix in colum mayor order.
@ WEIGHT_INDEX
Bone weight indices.
@ TEXCOORD
Texture coordinate.
@ BITANGENT
Vertex bitangent.
@ POSITION
Vertex position.
@ WEIGHT_VALUE
Bone weight values.
@ UNSIGNED_SHORT
Unsigned 16-bit integer.
@ HALF_FLOAT
16-bit floating point.
@ BYTE
Signed 8-bit integer.
@ DOUBLE
64-bit floating point.
@ SHORT
Signed 16-bit integer.
@ UNSIGNED_BYTE
Unsigned 8-bit integer.
@ FLOAT
32-bit floating point.
@ INT
Signed 32-bit integer.
@ UNSIGNED_INT
Unsigned 32-bit integer.
<- This is here just for the literals
Property GetProperty(const ComponentPropertyMsg &aComponentPropertyMsg)
Convert a ComponentPropertyMsg protobuf message to a Property.
Transform GetTransform(const TransformMsg &aTransform)
Convert a TransformMsg protobuf message to a Transform.
std::variant< int, long, long long, unsigned, unsigned long, unsigned long long, float, double, std::string, std::filesystem::path > Property
A variant type that can hold any commonly used property value.
uint32_t crc32i(const char *message, size_t size, uint32_t previous_crc)
Compute the CRC32 of a given message, continuing from a previous CRC value.
DLL Material::UniformKeyValue PropertyToKeyValue(const PropertyMsg &aProperty)
Convert a PropertyMsg to a Material uniform key-value pair.
Vector3 GetVector3(const Vector3Msg &aVector3)
Convert a Vector3Msg protobuf message to a Vector3.
DLL uint32_t GetReferenceMsgId(const ReferenceMsg &reference_buffer)
Retrieve the identifier from a ReferenceMsg.
Quaternion GetQuaternion(const QuaternionMsg &aQuaternion)
Convert a QuaternionMsg protobuf message to a Quaternion.
size_t GetUniformBufferSize(const PipelineMsg &aPipelineMsg)
Calculate the uniform buffer size required by a pipeline.