-
Notifications
You must be signed in to change notification settings - Fork 47
/
isurfacerenderer.h
64 lines (51 loc) · 1.94 KB
/
isurfacerenderer.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
#pragma once
#include <vector>
#include <limits>
#include <cstdint>
#include "render/ArbitraryMeshVertex.h"
#include "math/Matrix4.h"
namespace render
{
/**
* Surface type consisting of triangles, oriented by a transformation matrix.
*
* The ISurfaceRenderer will reacquire the transformation matrix each frame,
* whereas the vertices and indices won't be requested every time.
*/
class IRenderableSurface
{
public:
virtual ~IRenderableSurface() {}
// Returns the vertex array of this surface
virtual const std::vector<ArbitraryMeshVertex>& getVertices() = 0;
// Returns the indices to render the triangle primitives
virtual const std::vector<unsigned int>& getIndices() = 0;
// The model view matrix used to render this surface
virtual const Matrix4& getSurfaceTransform() = 0;
};
/**
* A surface renderer accepts a variable number of IRenderableSurfaces
* each of which is oriented by its own transformation matrix.
*
* Surfaces are rendered separately, the transformation matrix is requested
* each frame before drawing it.
* The vertices and indices of the surface are buffered and won't be requested
* every frame. Invoke the updateSurface() method to schedule an update.
*/
class ISurfaceRenderer
{
public:
virtual ~ISurfaceRenderer() {}
using Slot = std::uint64_t;
static constexpr Slot InvalidSlot = std::numeric_limits<Slot>::max();
// Allocate a slot to hold the given surface data, indexed to render triangles.
// Returns the handle which can be used to update or deallocate the data later
virtual Slot addSurface(IRenderableSurface& surface) = 0;
// Releases a previously allocated slot. This invalidates the handle.
virtual void removeSurface(Slot slot) = 0;
// Schedules an update of the vertex data contained in the surface.
virtual void updateSurface(Slot slot) = 0;
// Submits the surface of a single slot to GL
virtual void renderSurface(Slot slot) = 0;
};
}