OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
drawbuckets.h
Go to the documentation of this file.
1#pragma once
2
3#include <Tempest/DescriptorArray>
4#include <Tempest/StorageBuffer>
5
6#include "material.h"
7
8class StaticMesh;
9class AnimMesh;
10
12 public:
14
15 struct Bucket {
16 const StaticMesh* staticMesh = nullptr;
17 const AnimMesh* animMesh = nullptr;
19 };
20
21 class Id {
22 public:
23 Id() = default;
24 Id(DrawBuckets& owner):owner(&owner){}
25 Id(Id&& other) noexcept;
26 Id& operator = (Id&& other) noexcept;
27 ~Id();
28
29 uint16_t toInt() const { return id; }
30
31 Bucket& operator * () { return owner->bucketsCpu[id]; }
32 Bucket* operator -> () { return &owner->bucketsCpu[id]; }
33
34 private:
35 Id(DrawBuckets* owner, size_t id);
36
37 DrawBuckets* owner = nullptr;
38 uint16_t id = 0;
39 friend class DrawBuckets;
40 };
41
42 Id alloc(const Material& mat, const StaticMesh& mesh);
43 Id alloc(const Material& mat, const AnimMesh& mesh);
44
45 const Bucket& operator[](size_t i) { return bucketsCpu[i]; }
46
47 auto ssbo() const -> const Tempest::StorageBuffer& { return bucketsGpu; }
48 auto buckets() -> const std::vector<Bucket>&;
49
50 auto& textures() const { return desc.tex; }
51 auto& vbo() const { return desc.vbo; }
52 auto& ibo() const { return desc.ibo; }
53 auto& morphId() const { return desc.morphId; }
54 auto& morph() const { return desc.morph; }
55
56 bool commit(Tempest::Encoder<Tempest::CommandBuffer>& cmd, uint8_t fId);
57
58 private:
59 void updateBindlessArrays();
60
61 enum BucketFlg : uint32_t {
62 BK_SOLID = 0x1,
63 BK_SKIN = 0x2,
64 BK_MORPH = 0x4,
65 BK_WATER = 0x8,
66 };
67
68 struct BucketGpu final {
69 Tempest::Vec4 bbox[2];
70 Tempest::Point texAniMapDirPeriod;
71 float bboxRadius = 0;
72 float waveMaxAmplitude = 0;
73 float alphaWeight = 1;
74 float envMapping = 0;
75 uint32_t flags = 0;
76 uint32_t padd[1] = {};
77 };
78
79 struct {
80 Tempest::DescriptorArray tex;
81 Tempest::DescriptorArray vbo;
82 Tempest::DescriptorArray ibo;
83 Tempest::DescriptorArray morphId;
84 Tempest::DescriptorArray morph;
85 } desc;
86
87 std::vector<Bucket> bucketsCpu;
88 Tempest::StorageBuffer bucketsGpu;
89 bool bucketsDurtyBit = false;
90 };
Id(DrawBuckets &owner)
Definition drawbuckets.h:24
Id & operator=(Id &&other) noexcept
uint16_t toInt() const
Definition drawbuckets.h:29
Bucket * operator->()
Definition drawbuckets.h:32
Bucket & operator*()
Definition drawbuckets.h:31
Id alloc(const Material &mat, const StaticMesh &mesh)
Tempest::DescriptorArray tex
Definition drawbuckets.h:80
bool commit(Tempest::Encoder< Tempest::CommandBuffer > &cmd, uint8_t fId)
Tempest::DescriptorArray ibo
Definition drawbuckets.h:82
auto & ibo() const
Definition drawbuckets.h:52
Tempest::DescriptorArray morphId
Definition drawbuckets.h:83
auto buckets() -> const std::vector< Bucket > &
auto & morph() const
Definition drawbuckets.h:54
const Bucket & operator[](size_t i)
Definition drawbuckets.h:45
auto & vbo() const
Definition drawbuckets.h:51
auto & morphId() const
Definition drawbuckets.h:53
auto ssbo() const -> const Tempest::StorageBuffer &
Definition drawbuckets.h:47
auto & textures() const
Definition drawbuckets.h:50
Tempest::DescriptorArray vbo
Definition drawbuckets.h:81
Tempest::DescriptorArray morph
Definition drawbuckets.h:84
const StaticMesh * staticMesh
Definition drawbuckets.h:16
const AnimMesh * animMesh
Definition drawbuckets.h:17