| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "irenderableobject.h" |
| 4 |
#include "igeometrystore.h" |
| 5 |
|
| 6 |
#include <vector> |
| 7 |
#include <limits> |
| 8 |
#include <cstdint> |
| 9 |
#include "render/MeshVertex.h" |
| 10 |
#include "math/Matrix4.h" |
| 11 |
|
| 12 |
namespace render |
| 13 |
{ |
| 14 |
|
| 15 |
/** |
| 16 |
* Surface type consisting of triangles, oriented by a transformation matrix. |
| 17 |
* |
| 18 |
* The ISurfaceRenderer will reacquire the transformation matrix each frame, |
| 19 |
* whereas the vertices and indices won't be requested every time. |
| 20 |
*/ |
| 21 |
class IRenderableSurface : |
| 22 |
public IRenderableObject |
| 23 |
{ |
| 24 |
public: |
| 25 |
using Ptr = std::shared_ptr<IRenderableSurface>; |
| 26 |
|
| 27 |
virtual ~IRenderableSurface() {} |
| 28 |
|
| 29 |
// Returns the vertex array of this surface |
| 30 |
virtual const std::vector<MeshVertex>& getVertices() = 0; |
| 31 |
|
| 32 |
// Returns the indices to render the triangle primitives |
| 33 |
virtual const std::vector<unsigned int>& getIndices() = 0; |
| 34 |
}; |
| 35 |
|
| 36 |
/** |
| 37 |
* A surface renderer accepts a variable number of IRenderableSurfaces |
| 38 |
* each of which is oriented by its own transformation matrix. |
| 39 |
* |
| 40 |
* Surfaces are rendered separately, the transformation matrix is requested |
| 41 |
* each frame before drawing it. |
| 42 |
* The vertices and indices of the surface are buffered and won't be requested |
| 43 |
* every frame. Invoke the updateSurface() method to schedule an update. |
| 44 |
*/ |
| 45 |
class ISurfaceRenderer |
| 46 |
{ |
| 47 |
public: |
| 48 |
virtual ~ISurfaceRenderer() {} |
| 49 |
|
| 50 |
using Slot = std::uint64_t; |
| 51 |
static constexpr Slot InvalidSlot = std::numeric_limits<Slot>::max(); |
| 52 |
|
| 53 |
// Allocate a slot to hold the given surface data, indexed to render triangles. |
| 54 |
// Returns the handle which can be used to update or deallocate the data later |
| 55 |
virtual Slot addSurface(IRenderableSurface& surface) = 0; |
| 56 |
|
| 57 |
// Releases a previously allocated slot. This invalidates the handle. |
| 58 |
virtual void removeSurface(Slot slot) = 0; |
| 59 |
|
| 60 |
// Schedules an update of the vertex data contained in the surface. |
| 61 |
virtual void updateSurface(Slot slot) = 0; |
| 62 |
|
| 63 |
// Submits the surface of a single slot to GL |
| 64 |
virtual void renderSurface(Slot slot) = 0; |
| 65 |
|
| 66 |
// Get the key to access the vertex data of this surface within the renderer's backend geometry store |
| 67 |
virtual IGeometryStore::Slot getSurfaceStorageLocation(ISurfaceRenderer::Slot slot) = 0; |
| 68 |
}; |
| 69 |
|
| 70 |
} |