Debian Codegraph @

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

raw
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 blending state
12
13 Static wrapper that caches the current blending state (`GL_BLEND` enable flag
14 and the `glBlendFunc`/`glBlendFuncSeparate` factors) so that redundant OpenGL
15 calls are skipped when the requested state matches the cached one.
16 */
17 class GLBlending
18 {
19 public:
20 GLBlending() = delete;
21 ~GLBlending() = delete;
22
23 /**
24 * @brief Holds the cached blending state
25 */
26 struct State
27 {
28 /** @brief Whether blending is enabled */
29 bool enabled = false;
30 /** @brief Source RGB blend factor */
31 GLenum srcRgb = GL_ONE;
32 /** @brief Destination RGB blend factor */
33 GLenum dstRgb = GL_ZERO;
34 /** @brief Source alpha blend factor */
35 GLenum srcAlpha = GL_ONE;
36 /** @brief Destination alpha blend factor */
37 GLenum dstAlpha = GL_ZERO;
38 };
39
40 /** @brief Returns whether blending is enabled */
41 static bool IsEnabled() {
42 return _state.enabled;
43 }
44 /** @brief Enables blending */
45 static void Enable();
46 /** @brief Disables blending */
47 static void Disable();
48 /**
49 * @brief Sets the same source and destination blend factors for both RGB and alpha
50 *
51 * @param sfactor Source blend factor for RGB and alpha
52 * @param dfactor Destination blend factor for RGB and alpha
53 */
54 static void SetBlendFunc(GLenum sfactor, GLenum dfactor);
55 /**
56 * @brief Sets separate source and destination blend factors for RGB and alpha
57 *
58 * @param srcRgb Source blend factor for RGB
59 * @param dstRgb Destination blend factor for RGB
60 * @param srcAlpha Source blend factor for alpha
61 * @param dstAlpha Destination blend factor for alpha
62 */
63 static void SetBlendFunc(GLenum srcRgb, GLenum dstRgb, GLenum srcAlpha, GLenum dstAlpha);
64
65 /** @brief Returns the whole cached blending state */
66 static State GetState() {
67 return _state;
68 }
69 /** @brief Restores the whole blending state */
70 static void SetState(State newState);
71
72 /** @brief Re-applies the cached state to the driver (external code changed the real state) */
73 static void Reapply();
74
75 private:
76 static State _state;
77 };
78
79 }