| 1 |
#pragma once |
| 2 |
|
| 3 |
#ifndef DOXYGEN_GENERATING_OUTPUT |
| 4 |
#define NCINE_INCLUDE_OPENGL |
| 5 |
#include "../../../CommonHeaders.h" |
| 6 |
#endif |
| 7 |
|
| 8 |
#include "../../../Primitives/Rect.h" |
| 9 |
|
| 10 |
namespace nCine::RHI::GL |
| 11 |
{ |
| 12 |
/** |
| 13 |
@brief Manages the OpenGL scissor test state |
| 14 |
|
| 15 |
Static wrapper that caches the current scissor test state (`GL_SCISSOR_TEST` |
| 16 |
enable flag and the `glScissor` rectangle) so that redundant OpenGL calls are |
| 17 |
skipped when the requested state matches the cached one. |
| 18 |
*/ |
| 19 |
class GLScissorTest |
| 20 |
{ |
| 21 |
public: |
| 22 |
GLScissorTest() = delete; |
| 23 |
~GLScissorTest() = delete; |
| 24 |
|
| 25 |
/** |
| 26 |
* @brief Holds the cached scissor test state |
| 27 |
*/ |
| 28 |
struct State |
| 29 |
{ |
| 30 |
/** @brief Whether the scissor test is enabled */ |
| 31 |
bool enabled = false; |
| 32 |
/** @brief Scissor rectangle */ |
| 33 |
Recti rect = Recti(0, 0, 0, 0); |
| 34 |
}; |
| 35 |
|
| 36 |
/** @brief Returns whether the scissor test is enabled */ |
| 37 |
static bool IsEnabled() { |
| 38 |
return _state.enabled; |
| 39 |
} |
| 40 |
/** @brief Returns the current scissor rectangle */ |
| 41 |
static Recti GetRect() { |
| 42 |
return _state.rect; |
| 43 |
} |
| 44 |
/** |
| 45 |
* @brief Enables the scissor test with the specified rectangle |
| 46 |
* |
| 47 |
* @param rect Scissor rectangle |
| 48 |
*/ |
| 49 |
static void Enable(const Recti& rect); |
| 50 |
/** |
| 51 |
* @brief Enables the scissor test with the specified rectangle |
| 52 |
* |
| 53 |
* @param x Left coordinate of the scissor rectangle |
| 54 |
* @param y Bottom coordinate of the scissor rectangle |
| 55 |
* @param width Width of the scissor rectangle |
| 56 |
* @param height Height of the scissor rectangle |
| 57 |
*/ |
| 58 |
static void Enable(GLint x, GLint y, GLsizei width, GLsizei height); |
| 59 |
/** @brief Enables the scissor test reusing the cached rectangle */ |
| 60 |
static void Enable(); |
| 61 |
/** @brief Disables the scissor test */ |
| 62 |
static void Disable(); |
| 63 |
|
| 64 |
/** @brief Returns the whole cached scissor test state */ |
| 65 |
static State GetState() { |
| 66 |
return _state; |
| 67 |
} |
| 68 |
/** @brief Restores the whole scissor test state */ |
| 69 |
static void SetState(State newState); |
| 70 |
|
| 71 |
/** @brief Re-applies the cached state to the driver (external code changed the real state) */ |
| 72 |
static void Reapply(); |
| 73 |
|
| 74 |
private: |
| 75 |
static State _state; |
| 76 |
}; |
| 77 |
|
| 78 |
} |