candlewick 0.1.0
A renderer
Loading...
Searching...
No Matches
Internal.h
Go to the documentation of this file.
1#pragma once
4#include "../utils/MeshData.h"
5
6namespace candlewick {
7
8struct alignas(16) PosOnlyVertex {
10};
11
12template <> struct VertexTraits<PosOnlyVertex> {
13 static auto layout() {
14 return MeshLayout{}
15 .addBinding(0, sizeof(PosOnlyVertex))
17 SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3,
18 offsetof(PosOnlyVertex, pos));
19 }
20};
21
22struct alignas(16) PosNormalVertex {
24 alignas(16) GpuVec3 normal;
25};
26
27template <> struct VertexTraits<PosNormalVertex> {
28 static auto layout() {
29 return MeshLayout{}
30 .addBinding(0, sizeof(PosNormalVertex))
32 SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3,
33 offsetof(PosNormalVertex, pos))
35 SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3,
36 offsetof(PosNormalVertex, normal));
37 }
38};
39
40namespace detail {
41
42 struct ConeCylinderBuilder {
43 Uint32 currentVertices() const { return Uint32(positions.size()); }
44 void add(const Float3 &pos, const Float3 &normal);
45 void addFace(const Uint32 (&face)[3]);
46 Float3 previousPos(std::size_t offset) const;
47 Float3 previousNormal(std::size_t offset) const;
48
50 void addBottomDisk(Uint32 segments, float radius, float z);
52 void addTopDisk(Uint32 segments, float radius, float z);
53 void addCone(Uint32 segments, float radius, float zBottom, float length);
54 void addCylinderFloors(Uint32 numFloors, Uint32 segments, Float2 basePoint,
55 Float2 upDir, Uint32 startIdx);
56 void addHemisphereVertices(Uint32 count, Uint32 segments, float zCenter,
57 Radf ringStart, float ringIncrement,
58 Uint32 startIdx);
59
60 std::vector<Float3> positions;
61 std::vector<Float3> normals;
62 std::vector<MeshData::IndexType> indices;
63 };
64
65 inline void ConeCylinderBuilder::add(const Float3 &pos,
66 const Float3 &normal) {
67 positions.push_back(pos);
68 normals.push_back(normal.normalized());
69 }
70
71 inline void ConeCylinderBuilder::addFace(const Uint32 (&face)[3]) {
72 indices.push_back(face[0]);
73 indices.push_back(face[1]);
74 indices.push_back(face[2]);
75 }
76
77 inline Float3 ConeCylinderBuilder::previousPos(std::size_t offset) const {
78 return positions[positions.size() - offset];
79 }
80
81 inline Float3 ConeCylinderBuilder::previousNormal(std::size_t offset) const {
82 return normals[normals.size() - offset];
83 }
84
85} // namespace detail
86} // namespace candlewick
This class defines the layout of a mesh's vertices.
Definition MeshLayout.h:98
constexpr MeshLayout & addAttribute(VertexAttrib loc, Uint32 binding, SDL_GPUVertexElementFormat format, Uint32 offset)
Add a vertex attribute.
Definition MeshLayout.h:123
MeshLayout & addBinding(Uint32 slot, Uint32 pitch)
Add a binding (i.e. a vertex binding) for the mesh.
Definition MeshLayout.h:111
Rad< float > Radf
Definition math_types.h:125
Definition Camera.h:8
Eigen::Vector3f Float3
Definition math_types.h:8
@ Position
Definition MeshLayout.h:81
@ Normal
Definition MeshLayout.h:82
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > GpuVec3
Definition math_types.h:18
Eigen::Vector2f Float2
Definition math_types.h:7
Definition Internal.h:22
GpuVec3 normal
Definition Internal.h:24
GpuVec3 pos
Definition Internal.h:23
Definition Internal.h:8
GpuVec3 pos
Definition Internal.h:9
static auto layout()
Definition Internal.h:28
static auto layout()
Definition Internal.h:13
Definition MeshLayout.h:208