| 1 |
#include "GLDepthTest.h" |
| 2 |
|
| 3 |
namespace nCine::RHI::GL |
| 4 |
{ |
| 5 |
GLDepthTest::State GLDepthTest::_state; |
| 6 |
|
| 7 |
void GLDepthTest::Enable() |
| 8 |
{ |
| 9 |
if (_state.enabled == false) { |
| 10 |
glEnable(GL_DEPTH_TEST); |
| 11 |
_state.enabled = true; |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
void GLDepthTest::Disable() |
| 16 |
{ |
| 17 |
if (_state.enabled == true) { |
| 18 |
glDisable(GL_DEPTH_TEST); |
| 19 |
_state.enabled = false; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
void GLDepthTest::EnableDepthMask() |
| 24 |
{ |
| 25 |
if (_state.depthMaskEnabled == false) { |
| 26 |
glDepthMask(GL_TRUE); |
| 27 |
_state.depthMaskEnabled = true; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
void GLDepthTest::DisableDepthMask() |
| 32 |
{ |
| 33 |
if (_state.depthMaskEnabled == true) { |
| 34 |
glDepthMask(GL_FALSE); |
| 35 |
_state.depthMaskEnabled = false; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
void GLDepthTest::Reapply() |
| 40 |
{ |
| 41 |
if (_state.enabled) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); |
| 42 |
glDepthMask(_state.depthMaskEnabled ? GL_TRUE : GL_FALSE); |
| 43 |
} |
| 44 |
|
| 45 |
void GLDepthTest::SetState(State newState) |
| 46 |
{ |
| 47 |
if (newState.enabled) { |
| 48 |
Enable(); |
| 49 |
} else { |
| 50 |
Disable(); |
| 51 |
} |
| 52 |
if (newState.depthMaskEnabled) { |
| 53 |
EnableDepthMask(); |
| 54 |
} else { |
| 55 |
DisableDepthMask(); |
| 56 |
} |
| 57 |
_state = newState; |
| 58 |
} |
| 59 |
} |