Move scissor test to IVideoDriver

This commit is contained in:
Benau 2021-04-19 12:17:10 +08:00
parent 2c3922f64f
commit af7d6cf391
6 changed files with 37 additions and 6 deletions

View File

@ -1479,6 +1479,8 @@ namespace video
virtual void convertColor(const void* sP, ECOLOR_FORMAT sF, s32 sN,
void* dP, ECOLOR_FORMAT dF) const =0;
virtual u32 getDefaultFramebuffer() const =0;
virtual void enableScissorTest(const core::rect<s32>& r) {}
virtual void disableScissorTest() {}
};
} // end namespace video

View File

@ -2703,6 +2703,18 @@ namespace video
return Material;
}
void COGLES2Driver::enableScissorTest(const core::rect<s32>& r)
{
glEnable(GL_SCISSOR_TEST);
glScissor(r.UpperLeftCorner.X, r.UpperLeftCorner.Y,
r.getWidth(), r.getHeight());
}
void COGLES2Driver::disableScissorTest()
{
glDisable(GL_SCISSOR_TEST);
}
COGLES2CallBridge* COGLES2Driver::getBridgeCalls() const
{
return BridgeCalls;

View File

@ -68,6 +68,8 @@ namespace video
friend class COGLES2Texture;
public:
virtual void enableScissorTest(const core::rect<s32>& r);
virtual void disableScissorTest();
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
COGLES2Driver(const SIrrlichtCreationParameters& params,
const SExposedVideoData& data,

View File

@ -4939,6 +4939,17 @@ GLenum COpenGLDriver::getZBufferBits() const
return bits;
}
void COpenGLDriver::enableScissorTest(const core::rect<s32>& r)
{
glEnable(GL_SCISSOR_TEST);
glScissor(r.UpperLeftCorner.X, r.UpperLeftCorner.Y,
r.getWidth(), r.getHeight());
}
void COpenGLDriver::disableScissorTest()
{
glDisable(GL_SCISSOR_TEST);
}
} // end namespace
} // end namespace

View File

@ -38,6 +38,9 @@ namespace video
friend class COpenGLTexture;
public:
virtual void enableScissorTest(const core::rect<s32>& r);
virtual void disableScissorTest();
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWin32* device);
//! inits the windows specific parts of the open gl driver

View File

@ -165,15 +165,16 @@ void FontDrawer::draw()
if (g_clip)
{
glEnable(GL_SCISSOR_TEST);
const core::dimension2d<u32>& render_target_size =
irr_driver->getActualScreenSize();
glScissor(g_clip->UpperLeftCorner.X,
(s32)render_target_size.Height - g_clip->LowerRightCorner.Y,
g_clip->getWidth(), g_clip->getHeight());
s32 y = (s32)render_target_size.Height - g_clip->LowerRightCorner.Y;
core::rect<s32> r(g_clip->UpperLeftCorner.X, y,
g_clip->UpperLeftCorner.X + g_clip->getWidth(),
y + g_clip->getHeight());
irr_driver->getVideoDriver()->enableScissorTest(r);
}
else
glDisable(GL_SCISSOR_TEST);
irr_driver->getVideoDriver()->disableScissorTest();
for (auto& glyph : g_glyphs)
{
@ -258,7 +259,7 @@ void FontDrawer::draw()
if (g_clip)
{
glDisable(GL_SCISSOR_TEST);
irr_driver->getVideoDriver()->disableScissorTest();
g_clip.reset();
}