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