| 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 depth test state |
| 12 |
|
| 13 |
Static wrapper that caches the current depth test state (`GL_DEPTH_TEST` |
| 14 |
enable flag and the depth buffer write mask set with `glDepthMask`) so that |
| 15 |
redundant OpenGL calls are skipped when the requested state matches the |
| 16 |
cached one. |
| 17 |
*/ |
| 18 |
class GLDepthTest |
| 19 |
{ |
| 20 |
public: |
| 21 |
GLDepthTest() = delete; |
| 22 |
~GLDepthTest() = delete; |
| 23 |
|
| 24 |
/** |
| 25 |
* @brief Holds the cached depth test state |
| 26 |
*/ |
| 27 |
struct State |
| 28 |
{ |
| 29 |
/** @brief Whether the depth test is enabled */ |
| 30 |
bool enabled = false; |
| 31 |
/** @brief Whether writing to the depth buffer is enabled */ |
| 32 |
bool depthMaskEnabled = true; |
| 33 |
}; |
| 34 |
|
| 35 |
/** @brief Returns whether the depth test is enabled */ |
| 36 |
static bool IsEnabled() { |
| 37 |
return _state.enabled; |
| 38 |
} |
| 39 |
/** @brief Enables the depth test */ |
| 40 |
static void Enable(); |
| 41 |
/** @brief Disables the depth test */ |
| 42 |
static void Disable(); |
| 43 |
|
| 44 |
/** @brief Returns whether writing to the depth buffer is enabled */ |
| 45 |
static bool IsDepthMaskEnabled() { |
| 46 |
return _state.depthMaskEnabled; |
| 47 |
} |
| 48 |
/** @brief Enables writing to the depth buffer */ |
| 49 |
static void EnableDepthMask(); |
| 50 |
/** @brief Disables writing to the depth buffer */ |
| 51 |
static void DisableDepthMask(); |
| 52 |
|
| 53 |
/** @brief Returns the whole cached depth test state */ |
| 54 |
static State GetState() { |
| 55 |
return _state; |
| 56 |
} |
| 57 |
/** @brief Restores the whole depth test state */ |
| 58 |
static void SetState(State newState); |
| 59 |
|
| 60 |
/** @brief Re-applies the cached state to the driver (external code changed the real state) */ |
| 61 |
static void Reapply(); |
| 62 |
|
| 63 |
private: |
| 64 |
static State _state; |
| 65 |
}; |
| 66 |
|
| 67 |
} |