| 1 |
#pragma once |
| 2 |
|
| 3 |
#ifndef DOXYGEN_GENERATING_OUTPUT |
| 4 |
#define NCINE_INCLUDE_OPENGL |
| 5 |
#include "../../../CommonHeaders.h" |
| 6 |
#endif |
| 7 |
|
| 8 |
namespace nCine::RHI::GL |
| 9 |
{ |
| 10 |
/** |
| 11 |
@brief Manages the OpenGL face culling state |
| 12 |
|
| 13 |
Static wrapper that caches the current face culling state (`GL_CULL_FACE` |
| 14 |
enable flag and the `glCullFace` mode) so that redundant OpenGL calls are |
| 15 |
skipped when the requested state matches the cached one. |
| 16 |
*/ |
| 17 |
class GLCullFace |
| 18 |
{ |
| 19 |
public: |
| 20 |
GLCullFace() = delete; |
| 21 |
~GLCullFace() = delete; |
| 22 |
|
| 23 |
/** |
| 24 |
* @brief Holds the cached face culling state |
| 25 |
*/ |
| 26 |
struct State |
| 27 |
{ |
| 28 |
/** @brief Whether face culling is enabled */ |
| 29 |
bool enabled = false; |
| 30 |
/** @brief Culled face mode (`GL_FRONT`, `GL_BACK` or `GL_FRONT_AND_BACK`) */ |
| 31 |
GLenum mode = GL_BACK; |
| 32 |
}; |
| 33 |
|
| 34 |
/** @brief Returns whether face culling is enabled */ |
| 35 |
static bool IsEnabled() { |
| 36 |
return _state.enabled; |
| 37 |
} |
| 38 |
/** @brief Enables face culling */ |
| 39 |
static void Enable(); |
| 40 |
/** @brief Disables face culling */ |
| 41 |
static void Disable(); |
| 42 |
/** |
| 43 |
* @brief Sets the culled face mode |
| 44 |
* |
| 45 |
* @param mode Culled face mode (`GL_FRONT`, `GL_BACK` or `GL_FRONT_AND_BACK`) |
| 46 |
*/ |
| 47 |
static void SetMode(GLenum mode); |
| 48 |
|
| 49 |
/** @brief Returns the whole cached face culling state */ |
| 50 |
static State GetState() { |
| 51 |
return _state; |
| 52 |
} |
| 53 |
/** @brief Restores the whole face culling state */ |
| 54 |
static void SetState(State newState); |
| 55 |
|
| 56 |
/** @brief Re-applies the cached state to the driver (external code changed the real state) */ |
| 57 |
static void Reapply(); |
| 58 |
|
| 59 |
private: |
| 60 |
static State _state; |
| 61 |
}; |
| 62 |
|
| 63 |
} |