-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwander.h
203 lines (158 loc) · 3.25 KB
/
wander.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#pragma once
#include <string>
#include <vector>
namespace wander
{
class IRuntime;
typedef int ObjectID;
enum class EPalType
{
D3D11,
OpenGL
};
class Object
{
public:
virtual void Release() = 0;
};
enum class BufferType
{
Vertex,
Index,
Texture2D
};
enum class BufferFormat
{
Unknown,
Custom,
CustomVertex,
Index16,
Index32,
R8,
RG8,
RGB8,
RGBA8,
R16F,
RG16F,
RGB16F,
RGBA16F,
R32F,
RG32F,
RGB32F,
RGBA32F
};
class BufferDescriptor
{
public:
BufferDescriptor(BufferType type,
BufferFormat format = BufferFormat::Custom,
int width = 0, int height = 0, int depth = 0) :
m_type(type), m_format(format),
m_width(width), m_height(height), m_depth(depth)
{
}
BufferType Type() const
{
return m_type;
}
BufferFormat Format() const
{
return m_format;
}
int Width() const
{
return m_width;
}
int Height() const
{
return m_height;
}
int Depth() const
{
return m_depth;
}
private:
BufferType m_type;
BufferFormat m_format;
int m_width;
int m_height;
int m_depth;
};
class IPal : public Object
{
public:
virtual EPalType Type() = 0;
};
class RenderTreeNode
{
public:
RenderTreeNode(ObjectID buffer_id, const BufferType& buffer_type, const std::string& metadata, int offset, int length) :
m_buffer_id(buffer_id), m_buffer_type(buffer_type), m_metadata(metadata),
m_offset(offset), m_length(length) { }
void RenderFixedStride(IRuntime* runtime, unsigned int stride) const;
void RenderVector(IRuntime *runtime, int slot, int width, int height) const;
void SetPooledBuffer(ObjectID buffer_id, int offset);
std::string Metadata() const;
// This should be private
ObjectID BufferID() const
{
return m_buffer_id;
}
BufferType Type() const
{
return m_buffer_type;
}
private:
ObjectID m_buffer_id;
BufferType m_buffer_type;
std::string m_metadata;
int m_offset;
int m_length;
};
class RenderTree
{
public:
RenderTree(const std::vector<RenderTreeNode> &nodes) :
m_nodes(nodes)
{
}
const RenderTreeNode* NodeAt(int index) const
{
return &m_nodes[index]; // bounds check
}
void Clear()
{
m_nodes.clear();
}
int Length() const
{
return m_nodes.size();
}
private:
std::vector<RenderTreeNode> m_nodes;
};
class IRuntime : public Object
{
public:
virtual ObjectID LoadFromFile(const std::wstring& path) = 0;
virtual ObjectID LoadFromFile(const std::wstring& path, const std::string& function) = 0;
virtual void PushParam(ObjectID renderlet_id, float value) = 0;
virtual void PushParam(ObjectID renderlet_id, double value) = 0;
virtual void PushParam(ObjectID renderlet_id, uint32_t value) = 0;
virtual void PushParam(ObjectID renderlet_id, uint64_t value) = 0;
virtual void ResetStack(ObjectID renderlet_id) = 0;
virtual ObjectID Render(ObjectID renderlet_id, ObjectID tree_id = -1, bool pool = false) = 0;
virtual const float* const ExecuteFloat4(ObjectID renderlet_id, const std::string &function) = 0;
virtual void UploadBufferPool(unsigned int stride) = 0;
virtual const RenderTree* GetRenderTree(ObjectID tree_id) = 0;
virtual void DestroyRenderTree(ObjectID tree_id) = 0;
virtual void Unload(ObjectID renderlet_id) = 0;
};
class Factory
{
public:
template <typename... ARGs>
static IPal* CreatePal(EPalType type, ARGs &&...args);
static IRuntime* CreateRuntime(IPal *pal);
};
}