Debian Codegraph @

Sources/nCine/Graphics/RHI/GL/GLScissorTest.cpp

raw
1 #include "GLScissorTest.h"
2 #include "../../../../Main.h"
3
4 namespace nCine::RHI::GL
5 {
6 GLScissorTest::State GLScissorTest::_state;
7
8 void GLScissorTest::Enable(const Recti& rect)
9 {
10 if (!_state.enabled) {
11 glEnable(GL_SCISSOR_TEST);
12 _state.enabled = true;
13 }
14
15 if (rect.X != _state.rect.X || rect.Y != _state.rect.Y ||
16 rect.W != _state.rect.W || rect.H != _state.rect.H) {
17 FATAL_ASSERT(rect.W >= 0 && rect.H >= 0);
18 glScissor(rect.X, rect.Y, rect.W, rect.H);
19 _state.rect = rect;
20 }
21 }
22
23 void GLScissorTest::Enable(GLint x, GLint y, GLsizei width, GLsizei height)
24 {
25 Enable(Recti(x, y, width, height));
26 }
27
28 void GLScissorTest::Enable()
29 {
30 if (!_state.enabled) {
31 FATAL_ASSERT(_state.rect.W >= 0 && _state.rect.H >= 0);
32 glEnable(GL_SCISSOR_TEST);
33 _state.enabled = true;
34 }
35 }
36
37 void GLScissorTest::Disable()
38 {
39 if (_state.enabled) {
40 glDisable(GL_SCISSOR_TEST);
41 _state.enabled = false;
42 }
43 }
44
45 void GLScissorTest::Reapply()
46 {
47 if (_state.enabled) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
48 glScissor(_state.rect.X, _state.rect.Y, _state.rect.W, _state.rect.H);
49 }
50
51 void GLScissorTest::SetState(State newState)
52 {
53 if (newState.enabled) {
54 Enable(newState.rect);
55 } else {
56 Disable();
57 }
58 _state = newState;
59 }
60 }