Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_mesh.hpp
Go to the documentation of this file.
1#pragma once
2#include "../as/foray_blas.hpp"
3#include "../foray_basics.hpp"
4#include "../scene/foray_geo.hpp"
6
7namespace foray::scene {
8
12 struct Primitive
13 {
14 enum class EType
15 {
16 Vertex,
17 Index
18 };
19 EType Type = {};
20
22 uint32_t First = 0;
24 uint32_t VertexOrIndexCount = 0;
26 int32_t MaterialIndex = 0;
29
30 std::vector<foray::scene::Vertex> Vertices;
31 std::vector<uint32_t> Indices;
32
33 inline Primitive() {}
34 inline Primitive(
35 EType type, uint32_t first, uint32_t count, int32_t materialIndex, int32_t highestRef, std::vector<foray::scene::Vertex>& vertices, std::vector<uint32_t> indices)
36 : Type(type), First(first), VertexOrIndexCount(count), MaterialIndex(materialIndex), HighestReferencedIndex(highestRef), Vertices(vertices), Indices(indices)
37 {
38 }
39
40 bool IsValid() const { return VertexOrIndexCount > 0; }
41 void CmdDraw(VkCommandBuffer commandBuffer);
42 void CmdDrawInstanced(VkCommandBuffer commandBuffer, uint32_t instanceCount);
43 };
44
48 class Mesh
49 {
50 public:
51 inline Mesh() {}
52
53 virtual ~Mesh(){};
54
55 virtual void CmdDraw(SceneDrawInfo& drawInfo);
56 virtual void CmdDrawInstanced(SceneDrawInfo& drawInfo, uint32_t instanceCount);
57
58 virtual void BuildAccelerationStructure(core::Context* context, gcomp::GeometryStore* store) { mBlas.CreateOrUpdate(context, this, store); }
59
60 FORAY_PROPERTY_R(Primitives)
61 FORAY_GETTER_MR(Blas)
63
64 protected:
65 std::vector<Primitive> mPrimitives;
67 std::string mName = "";
68 };
69} // namespace foray::scene
A Blas (Bottom Level Acceleration Structure) is the raytracing equivalent concept of a mesh.
Definition foray_blas.hpp:15
virtual void CreateOrUpdate(core::Context *context, const scene::Mesh *mesh, const scene::gcomp::GeometryStore *store, bench::HostBenchmark *benchmark=nullptr)
Recreates the acceleration structure.
Type describing a single mesh object, described by multiple Primitive objects.
Definition foray_mesh.hpp:49
as::Blas mBlas
Definition foray_mesh.hpp:66
virtual ~Mesh()
Definition foray_mesh.hpp:53
virtual void CmdDraw(SceneDrawInfo &drawInfo)
std::vector< Primitive > mPrimitives
Definition foray_mesh.hpp:65
std::string mName
Definition foray_mesh.hpp:67
virtual void BuildAccelerationStructure(core::Context *context, gcomp::GeometryStore *store)
Definition foray_mesh.hpp:58
virtual void CmdDrawInstanced(SceneDrawInfo &drawInfo, uint32_t instanceCount)
Mesh()
Definition foray_mesh.hpp:51
Stores all geometry in a single set of index and vertex buffers.
Definition foray_geometrymanager.hpp:12
#define FORAY_GETTER_MR(member)
Return mutable reference.
Definition foray_basics.hpp:54
#define FORAY_PROPERTY_R(member)
Getter+Setter shorthand for reference types.
Definition foray_basics.hpp:86
Definition foray_animation.hpp:8
Non owning context object.
Definition foray_context.hpp:16
"An object binding indexed or non-indexed geometry with a material." according to the glTF spec....
Definition foray_mesh.hpp:13
bool IsValid() const
Definition foray_mesh.hpp:40
Primitive(EType type, uint32_t first, uint32_t count, int32_t materialIndex, int32_t highestRef, std::vector< foray::scene::Vertex > &vertices, std::vector< uint32_t > indices)
Definition foray_mesh.hpp:34
EType
Definition foray_mesh.hpp:15
Primitive()
Definition foray_mesh.hpp:33
uint32_t VertexOrIndexCount
Number of indices/vertices used for this primitive.
Definition foray_mesh.hpp:24
std::vector< foray::scene::Vertex > Vertices
Definition foray_mesh.hpp:30
void CmdDraw(VkCommandBuffer commandBuffer)
void CmdDrawInstanced(VkCommandBuffer commandBuffer, uint32_t instanceCount)
int32_t MaterialIndex
Index into the material buffer. Negative will cause use of fallback material.
Definition foray_mesh.hpp:26
EType Type
Definition foray_mesh.hpp:19
std::vector< uint32_t > Indices
Definition foray_mesh.hpp:31
uint32_t First
Index to the first index/vertex in a buffer.
Definition foray_mesh.hpp:22
uint32_t HighestReferencedIndex
The highest index into the vertex buffer referenced by this primitive. Used in Blas creation.
Definition foray_mesh.hpp:28
Temporary type passed to components when drawing the scene.
Definition foray_scenedrawing.hpp:63