From 1325fa7940a8a5dac12a82422c0c03ed5bc97213 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 20 Feb 2014 18:43:51 +0100 Subject: [PATCH] Fix UI clipping. --- src/graphics/glwrap.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index cb539f66b..466594ec0 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -424,12 +424,24 @@ void draw2DImage(const video::ITexture* texture, const core::rect& destRect { glDisable(GL_BLEND); } + if (clipRect) + { + if (!clipRect->isValid()) + return; + + glEnable(GL_SCISSOR_TEST); + const core::dimension2d& renderTargetSize = irr_driver->getVideoDriver()->getCurrentRenderTargetSize(); + glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + clipRect->getWidth(), clipRect->getHeight()); + } if (colors) drawTexColoredQuad(texture, colors, width, height, center_pos_x, center_pos_y, tex_center_pos_x, tex_center_pos_y, tex_width, tex_height); else drawTexQuad(texture, width, height, center_pos_x, center_pos_y, tex_center_pos_x, tex_center_pos_y, tex_width, tex_height); + if (clipRect) + glDisable(GL_SCISSOR_TEST); glUseProgram(0); } @@ -468,6 +480,17 @@ void GL32_draw2DRectangle(video::SColor color, const core::rect& position, glDisable(GL_BLEND); } + if (clip) + { + if (!clip->isValid()) + return; + + glEnable(GL_SCISSOR_TEST); + const core::dimension2d& renderTargetSize = irr_driver->getVideoDriver()->getCurrentRenderTargetSize(); + glScissor(clip->UpperLeftCorner.X, renderTargetSize.Height - clip->LowerRightCorner.Y, + clip->getWidth(), clip->getHeight()); + } + glUseProgram(UIShader::ColoredRectShader::Program); glBindVertexArray(UIShader::ColoredRectShader::vao); UIShader::ColoredRectShader::setUniforms(center_pos_x, center_pos_y, width, height, color); @@ -475,5 +498,7 @@ void GL32_draw2DRectangle(video::SColor color, const core::rect& position, glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); + if (clip) + glDisable(GL_SCISSOR_TEST); glUseProgram(0); }