Skip to content

Commit

Permalink
OpenGLRenderer: Add support for clearing while scissor is active
Browse files Browse the repository at this point in the history
Fixes: issue #1195
  • Loading branch information
dscharrer committed Oct 25, 2018
1 parent 48af4b6 commit 87b6324
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
52 changes: 26 additions & 26 deletions src/graphics/opengl/OpenGLRenderer.cpp
Expand Up @@ -51,8 +51,7 @@ OpenGLRenderer::OpenGLRenderer()
, m_maximumAnisotropy(1.f)
, m_maximumSupportedAnisotropy(1.f)
, m_glcull(GL_NONE)
, m_glscissor(false)
, m_scissor(false)
, m_scissor(Rect::ZERO)
, m_MSAALevel(0)
, m_hasMSAA(false)
, m_hasTextureNPOT(false)
Expand Down Expand Up @@ -433,8 +432,6 @@ void OpenGLRenderer::reinit() {
glEnable(GL_BLEND);
m_glstate.setBlend(BlendOne, BlendZero);

m_glscissor = false;

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);

Expand Down Expand Up @@ -601,13 +598,24 @@ void OpenGLRenderer::SetViewport(const Rect & _viewport) {

void OpenGLRenderer::SetScissor(const Rect & rect) {

if(m_scissor == rect) {
return;
}

if(rect.isValid()) {
m_scissor = true;
if(!m_scissor.isValid()) {
glEnable(GL_SCISSOR_TEST);
}
int height = mainApp->getWindow()->getSize().y;
glScissor(rect.left, height - rect.bottom, rect.width(), rect.height());
} else {
m_scissor = false;
if(m_scissor.isValid()) {
glDisable(GL_SCISSOR_TEST);
}
}

m_scissor = rect;

}

void OpenGLRenderer::Clear(BufferFlags bufferFlags, Color clearColor, float clearDepth, size_t nrects, Rect * rect) {
Expand Down Expand Up @@ -641,29 +649,30 @@ void OpenGLRenderer::Clear(BufferFlags bufferFlags, Color clearColor, float clea

if(nrects) {

arx_assert(!m_scissor);

if(!m_glscissor) {
glEnable(GL_SCISSOR_TEST);
m_glscissor = true;
}

int height = mainApp->getWindow()->getSize().y;
Rect scissor = m_scissor;

for(size_t i = 0; i < nrects; i++) {
glScissor(rect[i].left, height - rect[i].bottom, rect[i].width(), rect[i].height());

SetScissor(rect[i]);

glClear(buffers);

}

SetScissor(scissor);

} else {

if(m_glscissor) {
if(m_scissor.isValid()) {
glDisable(GL_SCISSOR_TEST);
m_glscissor = false;
}

glClear(buffers);

if(m_scissor.isValid()) {
glEnable(GL_SCISSOR_TEST);
}

}
}

Expand Down Expand Up @@ -898,15 +907,6 @@ static const GLenum arxToGlBlendFactor[] = {

void OpenGLRenderer::flushState() {

if(m_glscissor != m_scissor) {
if(m_scissor) {
glEnable(GL_SCISSOR_TEST);
} else {
glDisable(GL_SCISSOR_TEST);
}
m_glscissor = m_scissor;
}

if(m_glstate != m_state) {

if(m_glstate.getCull() != m_state.getCull()) {
Expand Down
3 changes: 1 addition & 2 deletions src/graphics/opengl/OpenGLRenderer.h
Expand Up @@ -135,8 +135,7 @@ class OpenGLRenderer arx_final : public Renderer {
RenderState m_glstate;
GLenum m_glcull;

bool m_glscissor;
bool m_scissor;
Rect m_scissor;

int m_MSAALevel;
bool m_hasMSAA;
Expand Down

0 comments on commit 87b6324

Please sign in to comment.