This repository was archived by the owner on Mar 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawable.hpp
More file actions
50 lines (42 loc) · 1.39 KB
/
Drawable.hpp
File metadata and controls
50 lines (42 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#include <Tkge/Graphics/Renderer.hpp>
#include <Tkge/Graphics/Shape.hpp>
#include <concepts>
namespace Tkge::Graphics
{
class IDrawable : public klib::Polymorphic
{
public:
[[nodiscard]] virtual Primitive GetPrimitive() const = 0;
[[nodiscard]] virtual std::span<const RenderInstance> GetInstances() const = 0;
virtual void Draw(Renderer& renderer) const { renderer.Draw(GetPrimitive(), GetInstances()); }
};
template <std::derived_from<IGeometry> TGeometry>
class BasicDrawable : public TGeometry, public IDrawable
{
public:
[[nodiscard]] Primitive GetPrimitive() const final
{
return Primitive{
.vertices = this->GetVertices(),
.indices = this->GetIndices(),
.topology = this->GetTopology(),
};
}
};
template <std::derived_from<IGeometry> TGeometry>
class Drawable : public BasicDrawable<TGeometry>, public RenderInstance
{
public:
[[nodiscard]] std::span<const RenderInstance> GetInstances() const final { return {static_cast<const RenderInstance*>(this), 1}; }
};
template <std::derived_from<IGeometry> TGeometry>
class InstancedDrawable : public BasicDrawable<TGeometry>
{
public:
[[nodiscard]] std::span<const RenderInstance> GetInstances() const final { return instances; }
std::vector<RenderInstance> instances{};
};
using Quad = Drawable<QuadShape>;
using InstancedQuad = InstancedDrawable<QuadShape>;
} // namespace Tkge::Graphics