| 1 |
#pragma once |
| 2 |
|
| 3 |
#ifndef DOXYGEN_GENERATING_OUTPUT |
| 4 |
#define NCINE_INCLUDE_OPENGL |
| 5 |
#include "../../../CommonHeaders.h" |
| 6 |
#endif |
| 7 |
|
| 8 |
#include "../../../Primitives/Colorf.h" |
| 9 |
|
| 10 |
namespace nCine::RHI::GL |
| 11 |
{ |
| 12 |
/** |
| 13 |
@brief Manages the OpenGL clear color |
| 14 |
|
| 15 |
Static wrapper that caches the clear color used by `glClear` (set with |
| 16 |
`glClearColor`) so that redundant OpenGL calls are skipped when the requested |
| 17 |
color matches the cached one. |
| 18 |
*/ |
| 19 |
class GLClearColor |
| 20 |
{ |
| 21 |
public: |
| 22 |
GLClearColor() = delete; |
| 23 |
~GLClearColor() = delete; |
| 24 |
|
| 25 |
/** |
| 26 |
* @brief Holds the cached clear color state |
| 27 |
*/ |
| 28 |
struct State |
| 29 |
{ |
| 30 |
/** @brief Clear color */ |
| 31 |
Colorf color = Colorf(0.0f, 0.0f, 0.0f, 0.0f); |
| 32 |
}; |
| 33 |
|
| 34 |
/** @brief Returns the current clear color */ |
| 35 |
static Colorf GetColor() { |
| 36 |
return _state.color; |
| 37 |
} |
| 38 |
/** @brief Sets the clear color */ |
| 39 |
static void SetColor(const Colorf& color); |
| 40 |
/** |
| 41 |
* @brief Sets the clear color from individual components |
| 42 |
* |
| 43 |
* @param red Red component |
| 44 |
* @param green Green component |
| 45 |
* @param blue Blue component |
| 46 |
* @param alpha Alpha component |
| 47 |
*/ |
| 48 |
static void SetColor(float red, float green, float blue, float alpha); |
| 49 |
|
| 50 |
/** @brief Returns the whole cached clear color state */ |
| 51 |
static State GetState() { |
| 52 |
return _state; |
| 53 |
} |
| 54 |
/** @brief Restores the whole clear color state */ |
| 55 |
static void SetState(State newState); |
| 56 |
|
| 57 |
/** @brief Re-applies the cached state to the driver (external code changed the real state) */ |
| 58 |
static void Reapply(); |
| 59 |
|
| 60 |
private: |
| 61 |
static State _state; |
| 62 |
}; |
| 63 |
|
| 64 |
} |