-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawableBase.h
More file actions
44 lines (42 loc) · 1.3 KB
/
DrawableBase.h
File metadata and controls
44 lines (42 loc) · 1.3 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
#pragma once
#include "Drawable.h"
#include "IndexBuffer.h"
template<class T>
class DrawableBase : public Drawable
{
protected:
static bool IsStaticInitialized() noexcept
{
return !staticBinds.empty();
}
static void AddStaticBind(std::unique_ptr<Bindable> bind) noexcept(!IS_DEBUG)
{
assert("*Must* use AddIndexBuffer to bind index buffer" && typeid(*bind) != typeid(IndexBuffer));
staticBinds.push_back(std::move(bind));
}
void AddStaticIndexBuffer(std::unique_ptr<IndexBuffer> ibuf) noexcept(!IS_DEBUG)
{
assert("Attempting to add index buffer a second time" && pIndexBuffer == nullptr);
pIndexBuffer = ibuf.get();
staticBinds.push_back(std::move(ibuf));
}
void SetIndexFromStatic() noexcept(!IS_DEBUG) {
assert("Attempting to add index buffer a second time" && pIndexBuffer == nullptr);
for (const auto& bind : staticBinds) {
if (const auto p = dynamic_cast<IndexBuffer*>(bind.get())) {
pIndexBuffer = p;
return;
}
}
assert("Failed to find index buffer in static binds" && pIndexBuffer != nullptr);
}
private:
const std::vector<std::unique_ptr<Bindable>>& GetStaticBinds() const noexcept override
{
return staticBinds;
}
private:
static std::vector<std::unique_ptr<Bindable>> staticBinds;
};
template<class T>
std::vector<std::unique_ptr<Bindable>> DrawableBase<T>::staticBinds;