11#ifndef FOOLSENGINE_VERTEX_H
12#define FOOLSENGINE_VERTEX_H
16#include <nlohmann/json.hpp>
55 assert(
mType == GL_FLOAT ||
mType == GL_UNSIGNED_INT ||
mType == GL_INT);
118 std::size_t componentSize;
124 case GL_UNSIGNED_INT:
125 componentSize =
sizeof(GLfloat);
128 assert(
false &&
"Unsupported or invalid attribute component type specified");
130 return componentSize;
165 std::size_t stride {0};
167 stride += attribute.mSize;
180 std::size_t baseOffset {0};
181 for(std::size_t i {0}; i < attributeIndex; ++i) {
201 std::size_t myAttributeIndex {0};
274 inline void from_json(
const nlohmann::json& json,
BuiltinVertexData& builtinVertexData) {
275 json.at(
"position").at(0).get_to(builtinVertexData.
mPosition.x);
276 json.at(
"position").at(1).get_to(builtinVertexData.
mPosition.y);
277 json.at(
"position").at(2).get_to(builtinVertexData.
mPosition.z);
278 json.at(
"position").at(3).get_to(builtinVertexData.
mPosition.w);
279 json.at(
"normal").at(0).get_to(builtinVertexData.
mNormal.x);
280 json.at(
"normal").at(1).get_to(builtinVertexData.
mNormal.y);
281 json.at(
"normal").at(2).get_to(builtinVertexData.
mNormal.z);
282 json.at(
"normal").at(3).get_to(builtinVertexData.
mNormal.w);
283 json.at(
"tangent").at(0).get_to(builtinVertexData.
mTangent.x);
284 json.at(
"tangent").at(1).get_to(builtinVertexData.
mTangent.y);
285 json.at(
"tangent").at(2).get_to(builtinVertexData.
mTangent.z);
286 json.at(
"tangent").at(3).get_to(builtinVertexData.
mTangent.w);
287 json.at(
"color").at(0).get_to(builtinVertexData.
mColor.r);
288 json.at(
"color").at(1).get_to(builtinVertexData.
mColor.g);
289 json.at(
"color").at(2).get_to(builtinVertexData.
mColor.b);
290 json.at(
"color").at(3).get_to(builtinVertexData.
mColor.a);
291 json.at(
"uv1").at(0).get_to(builtinVertexData.
mUV1.s);
292 json.at(
"uv1").at(1).get_to(builtinVertexData.
mUV1.t);
293 json.at(
"uv2").at(0).get_to(builtinVertexData.
mUV2.s);
294 json.at(
"uv2").at(1).get_to(builtinVertexData.
mUV2.t);
295 json.at(
"uv3").at(0).get_to(builtinVertexData.
mUV3.s);
296 json.at(
"uv3").at(1).get_to(builtinVertexData.
mUV3.t);
300 inline void to_json(nlohmann::json& json,
const BuiltinVertexData& builtinVertexData) {
304 builtinVertexData.mPosition.x,
305 builtinVertexData.mPosition.y,
306 builtinVertexData.mPosition.z,
307 builtinVertexData.mPosition.w
312 builtinVertexData.mNormal.x,
313 builtinVertexData.mNormal.y,
314 builtinVertexData.mNormal.z,
315 builtinVertexData.mNormal.w,
320 builtinVertexData.mTangent.x,
321 builtinVertexData.mTangent.y,
322 builtinVertexData.mTangent.z,
323 builtinVertexData.mTangent.w,
328 builtinVertexData.mColor.r,
329 builtinVertexData.mColor.g,
330 builtinVertexData.mColor.b,
331 builtinVertexData.mColor.a,
336 builtinVertexData.mUV1.s,
337 builtinVertexData.mUV1.t,
342 builtinVertexData.mUV2.s,
343 builtinVertexData.mUV2.t,
348 builtinVertexData.mUV3.s,
349 builtinVertexData.mUV3.t,
362 {
"position", LOCATION_POSITION, 4, GL_FLOAT},
363 {
"normal", LOCATION_NORMAL, 4, GL_FLOAT},
364 {
"tangent", LOCATION_TANGENT, 4, GL_FLOAT},
365 {
"color", LOCATION_COLOR, 4, GL_FLOAT},
366 {
"UV1", LOCATION_UV1, 2, GL_FLOAT},
367 {
"UV2", LOCATION_UV2, 2, GL_FLOAT},
368 {
"UV3", LOCATION_UV3, 2, GL_FLOAT}
DefaultAttributeLocation
Values for different attribute locations used by the engine's built-in shader programs.
Definition vertex.hpp:25
VertexLayout BuiltinVertexLayout
The vertex layout used by most shader programs built into the engine.
Definition vertex.hpp:360
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition camera_system.hpp:20
The vertex data used by all this engine's in-built shader program's vertex shaders.
Definition vertex.hpp:225
glm::vec4 mNormal
The normal vector to the vertex (with w set to 0.f)
Definition vertex.hpp:236
glm::vec4 mColor
This vertex's color, where each color component is a value between 0.f and 1.f.
Definition vertex.hpp:248
glm::vec4 mPosition
The position of the vertex (normally with w set to 1.f).
Definition vertex.hpp:230
glm::vec2 mUV1
The UV coordinates corresponding to this vertex, with coordinates pointing into the first texture set...
Definition vertex.hpp:254
glm::vec2 mUV2
(currently unused) Coordinates pointing into the second texture set used by this vertex's owning mode...
Definition vertex.hpp:262
glm::vec4 mTangent
The tangent vector to the vertex (with w set to 0.f)
Definition vertex.hpp:242
glm::vec2 mUV3
(currently unused) Coordinates pointing into the third texture set used by this vertex's owning model...
Definition vertex.hpp:270
bool operator==(const VertexAttributeDescriptor &other) const
Compares two vertex attribute descriptors for equality.
Definition vertex.hpp:99
GLint mLayoutLocation
The layout location ID of the attribute, as specified by the shader.
Definition vertex.hpp:68
GLuint mNComponents
The number of components making up the attribute.
Definition vertex.hpp:74
static std::size_t GetGLTypeSize(GLenum type)
Gets the size of the type of a single component of an attribute.
Definition vertex.hpp:117
std::string mName
The name of the attribute, per the shader.
Definition vertex.hpp:62
VertexAttributeDescriptor(const std::string &name, GLint layoutLocation, GLuint nComponents=1, GLenum type=GL_FLOAT)
Creates a single vertex attribute descriptor.
Definition vertex.hpp:49
GLenum mType
The type of component used by the attribute, such as GL_FLOAT or GL_UNSIGNED_BYTE.
Definition vertex.hpp:80
std::size_t mSize
The computed size of the attribute, in bytes.
Definition vertex.hpp:88
A list of attribute descriptors that together define the layout and size of the vertex they make up i...
Definition vertex.hpp:141
bool isSubsetOf(const VertexLayout &other) const
Tests whether this vertex layout is the subset of another.
Definition vertex.hpp:198
std::size_t computeStride() const
Computes the total space occupied by a single vertex including all its attributes in memory.
Definition vertex.hpp:164
std::vector< VertexAttributeDescriptor > getAttributeList() const
Gets the list of attribute descriptors making up this layout.
Definition vertex.hpp:154
std::size_t computeRelativeOffset(std::size_t attributeIndex) const
Given the index of an attribute descriptor within the layout, computes the offset to that attribute f...
Definition vertex.hpp:178
std::vector< VertexAttributeDescriptor > mAttributeList
The list of attribute descriptors that define this layout.
Definition vertex.hpp:217
VertexLayout(std::vector< VertexAttributeDescriptor > attributeList)
Create a vertex layout from a list of attribute descriptors.
Definition vertex.hpp:147