Debian Codegraph @

Sources/nCine/Graphics/RHI/GL/GLViewport.h

raw
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 viewport rectangle
14
15 Static wrapper that caches the current viewport rectangle (set with
16 `glViewport`) so that redundant OpenGL calls are skipped when the requested
17 rectangle matches the cached one.
18 */
19 class GLViewport
20 {
21 friend class GLDevice; // for `InitRect()`
22
23 public:
24 GLViewport() = delete;
25 ~GLViewport() = delete;
26
27 /**
28 * @brief Holds the cached viewport state
29 */
30 struct State
31 {
32 /** @brief Viewport rectangle */
33 Recti rect = Recti(0, 0, 0, 0);
34 };
35
36 /** @brief Returns the current viewport rectangle */
37 static Recti GetRect() {
38 return _state.rect;
39 }
40 /**
41 * @brief Sets the viewport rectangle
42 *
43 * @param rect Viewport rectangle
44 */
45 static void SetRect(const Recti& rect);
46 /**
47 * @brief Sets the viewport rectangle
48 *
49 * @param x Left coordinate of the viewport rectangle
50 * @param y Bottom coordinate of the viewport rectangle
51 * @param width Width of the viewport rectangle
52 * @param height Height of the viewport rectangle
53 */
54 static void SetRect(GLint x, GLint y, GLsizei width, GLsizei height);
55
56 /** @brief Returns the whole cached viewport state */
57 static State GetState() {
58 return _state;
59 }
60 /** @brief Restores the whole viewport state */
61 static void SetState(State newState);
62
63 /** @brief Re-applies the cached state to the driver (external code changed the real state) */
64 static void Reapply();
65
66 private:
67 static State _state;
68
69 static void InitRect(GLint x, GLint y, GLsizei width, GLsizei height);
70 };
71 }