| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "GLHashMap.h" |
| 4 |
|
| 5 |
#include <Containers/StringView.h> |
| 6 |
|
| 7 |
using namespace Death::Containers; |
| 8 |
|
| 9 |
namespace nCine::RHI::GL |
| 10 |
{ |
| 11 |
/** |
| 12 |
@brief Wraps an OpenGL vertex array object |
| 13 |
|
| 14 |
Manages the lifetime of a single OpenGL vertex array object (VAO), which captures the set of |
| 15 |
enabled vertex attribute arrays and their bindings. The currently bound VAO is cached so that |
| 16 |
redundant `glBindVertexArray()` calls are skipped. |
| 17 |
*/ |
| 18 |
class GLVertexArrayObject |
| 19 |
{ |
| 20 |
public: |
| 21 |
GLVertexArrayObject(); |
| 22 |
~GLVertexArrayObject(); |
| 23 |
|
| 24 |
GLVertexArrayObject(const GLVertexArrayObject&) = delete; |
| 25 |
GLVertexArrayObject& operator=(const GLVertexArrayObject&) = delete; |
| 26 |
|
| 27 |
/** @brief Returns the OpenGL handle of the vertex array object */ |
| 28 |
inline GLuint GetGLHandle() const { |
| 29 |
return _glHandle; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @brief Binds the vertex array object |
| 34 |
* |
| 35 |
* @return `true` if a `glBindVertexArray()` call was issued, `false` if it was already bound |
| 36 |
*/ |
| 37 |
bool Bind() const; |
| 38 |
/** |
| 39 |
* @brief Unbinds any vertex array object |
| 40 |
* |
| 41 |
* @return `true` if a `glBindVertexArray()` call was issued, `false` if nothing was bound |
| 42 |
*/ |
| 43 |
static bool Unbind(); |
| 44 |
|
| 45 |
/** @brief Sets an OpenGL object label for the vertex array object, for debugging */ |
| 46 |
void SetObjectLabel(StringView label); |
| 47 |
|
| 48 |
/** @brief Drops the cached bound VAO so the next bind re-applies (external code changed it) */ |
| 49 |
static void InvalidateCachedBinding() { |
| 50 |
_boundVAO = ~0u; |
| 51 |
} |
| 52 |
|
| 53 |
private: |
| 54 |
static GLuint _boundVAO; |
| 55 |
|
| 56 |
GLuint _glHandle; |
| 57 |
}; |
| 58 |
} |