| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <vector> |
| 4 |
#include <limits> |
| 5 |
#include <cstdint> |
| 6 |
#include "igeometrystore.h" |
| 7 |
#include "render/RenderVertex.h" |
| 8 |
#include "math/AABB.h" |
| 9 |
|
| 10 |
namespace render |
| 11 |
{ |
| 12 |
|
| 13 |
enum class GeometryType |
| 14 |
{ |
| 15 |
Triangles, |
| 16 |
Quads, |
| 17 |
Lines, |
| 18 |
Points, |
| 19 |
}; |
| 20 |
|
| 21 |
/** |
| 22 |
* A geometry renderer accepts a variable number of indexed vertices and internally |
| 23 |
* arranges them into one or more continuous blocks for efficient rendering. |
| 24 |
* |
| 25 |
* The internal arrangement has the goal of reducing the amount of draw calls for |
| 26 |
* primitives sharing a single material. Allocating a geometry slot yields a handle which |
| 27 |
* allows for later update or deallocation of the slot. |
| 28 |
*/ |
| 29 |
class IGeometryRenderer |
| 30 |
{ |
| 31 |
public: |
| 32 |
virtual ~IGeometryRenderer() {} |
| 33 |
|
| 34 |
using Slot = std::uint64_t; |
| 35 |
static constexpr Slot InvalidSlot = std::numeric_limits<Slot>::max(); |
| 36 |
|
| 37 |
/// List of vertices |
| 38 |
using Vertices = std::vector<RenderVertex>; |
| 39 |
|
| 40 |
/// List of indices |
| 41 |
using Indices = std::vector<unsigned int>; |
| 42 |
|
| 43 |
/** |
| 44 |
* @brief Allocate a slot to hold the given indexed vertex data. |
| 45 |
* |
| 46 |
* Added geometry is active by default. |
| 47 |
* |
| 48 |
* @param primType Determines the primitive GLenum that is chosen to render this surface |
| 49 |
* @param vertices Vector of vertex data |
| 50 |
* @param indices Vector of index data |
| 51 |
* @return Slot which can be used to update or deallocate the data later |
| 52 |
*/ |
| 53 |
virtual Slot |
| 54 |
addGeometry(GeometryType primType, const Vertices& vertices, const Indices& indices) = 0; |
| 55 |
|
| 56 |
// Re-activates a previously deactivated geometry slot. |
| 57 |
virtual void activateGeometry(Slot slot) = 0; |
| 58 |
|
| 59 |
// Suspends the geometry in the given slot - it won't be rendered anymore. |
| 60 |
// Doesn't remove any of the vertex or index data (use removeGeometry() for that). |
| 61 |
// The slot handle will remain valid. |
| 62 |
// Inactive geometry can automatically be re-activated by updateGeometry(), |
| 63 |
// or an explicit activateGeometry() call. |
| 64 |
virtual void deactivateGeometry(Slot slot) = 0; |
| 65 |
|
| 66 |
// Releases a previously allocated slot. This invalidates the handle. |
| 67 |
virtual void removeGeometry(Slot slot) = 0; |
| 68 |
|
| 69 |
// Updates the vertex data. The size of the vertex and index array must be the same |
| 70 |
// as the one passed to addGeometry. To change the size the data needs to be removed and re-added. |
| 71 |
virtual void updateGeometry(Slot slot, const Vertices& vertices, const Indices& indices) = 0; |
| 72 |
|
| 73 |
// Submits all active geometry slots to GL |
| 74 |
virtual void renderAllVisibleGeometry() = 0; |
| 75 |
|
| 76 |
// Submits the geometry of a single slot to GL, regardless of its active state |
| 77 |
virtual void renderGeometry(Slot slot) = 0; |
| 78 |
|
| 79 |
// Returns the bounding box of the geometry stored in the given slot |
| 80 |
virtual AABB getGeometryBounds(Slot slot) const = 0; |
| 81 |
|
| 82 |
// Returns the storage handle to enable the backend renderer to get hold of the indexed vertex data |
| 83 |
virtual IGeometryStore::Slot getGeometryStorageLocation(Slot slot) = 0; |
| 84 |
}; |
| 85 |
|
| 86 |
} |