From 78d1a3f73e55b84b612b8c9a38b50fd0063394f4 Mon Sep 17 00:00:00 2001 From: Vincent Robinson Date: Mon, 21 Jun 2021 14:16:38 -0700 Subject: [PATCH] Fix `getViewPort` returning incorrect results --- source/Irrlicht/COGLES2Driver.cpp | 11 +++++++++-- source/Irrlicht/COGLES2Driver.h | 3 +++ source/Irrlicht/COGLESDriver.cpp | 11 +++++++++-- source/Irrlicht/COGLESDriver.h | 3 +++ source/Irrlicht/COpenGLDriver.cpp | 13 ++++++++++--- source/Irrlicht/COpenGLDriver.h | 5 ++++- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/source/Irrlicht/COGLES2Driver.cpp b/source/Irrlicht/COGLES2Driver.cpp index f506114..a36f911 100644 --- a/source/Irrlicht/COGLES2Driver.cpp +++ b/source/Irrlicht/COGLES2Driver.cpp @@ -2099,6 +2099,13 @@ COGLES2Driver::~COGLES2Driver() } + void COGLES2Driver::setViewPortRaw(u32 width, u32 height) + { + CacheHandler->setViewport(0, 0, width, height); + ViewPort = core::recti(0, 0, width, height); + } + + //! Draws a shadow volume into the stencil buffer. void COGLES2Driver::drawStencilShadowVolume(const core::array& triangles, bool zfail, u32 debugDataVisible) { @@ -2460,7 +2467,7 @@ COGLES2Driver::~COGLES2Driver() destRenderTargetSize = renderTarget->getSize(); - CacheHandler->setViewport(0, 0, destRenderTargetSize.Width, destRenderTargetSize.Height); + setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height); } else { @@ -2468,7 +2475,7 @@ COGLES2Driver::~COGLES2Driver() destRenderTargetSize = core::dimension2d(0, 0); - CacheHandler->setViewport(0, 0, ScreenSize.Width, ScreenSize.Height); + setViewPortRaw(ScreenSize.Width, ScreenSize.Height); } if (CurrentRenderTargetSize != destRenderTargetSize) diff --git a/source/Irrlicht/COGLES2Driver.h b/source/Irrlicht/COGLES2Driver.h index 06e80a6..1ce1179 100644 --- a/source/Irrlicht/COGLES2Driver.h +++ b/source/Irrlicht/COGLES2Driver.h @@ -379,6 +379,9 @@ namespace video bool setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture* texture); + //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` + virtual void setViewPortRaw(u32 width, u32 height); + COGLES2CacheHandler* CacheHandler; core::stringw Name; core::stringc VendorName; diff --git a/source/Irrlicht/COGLESDriver.cpp b/source/Irrlicht/COGLESDriver.cpp index cca937c..2bce88a 100644 --- a/source/Irrlicht/COGLESDriver.cpp +++ b/source/Irrlicht/COGLESDriver.cpp @@ -2330,6 +2330,13 @@ void COGLES1Driver::setViewPort(const core::rect& area) } +void COGLES1Driver::setViewPortRaw(u32 width, u32 height) +{ + CacheHandler->setViewport(0, 0, width, height); + ViewPort = core::recti(0, 0, width, height); +} + + //! Draws a shadow volume into the stencil buffer. void COGLES1Driver::drawStencilShadowVolume(const core::array& triangles, bool zfail, u32 debugDataVisible) { @@ -2779,7 +2786,7 @@ bool COGLES1Driver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SCol destRenderTargetSize = renderTarget->getSize(); - CacheHandler->setViewport(0, 0, destRenderTargetSize.Width, destRenderTargetSize.Height); + setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height); } else { @@ -2805,7 +2812,7 @@ bool COGLES1Driver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SCol destRenderTargetSize = core::dimension2d(0, 0); - CacheHandler->setViewport(0, 0, ScreenSize.Width, ScreenSize.Height); + setViewPortRaw(ScreenSize.Width, ScreenSize.Height); } if (CurrentRenderTargetSize != destRenderTargetSize) diff --git a/source/Irrlicht/COGLESDriver.h b/source/Irrlicht/COGLESDriver.h index 6ffaaaf..92dcd22 100644 --- a/source/Irrlicht/COGLESDriver.h +++ b/source/Irrlicht/COGLESDriver.h @@ -342,6 +342,9 @@ namespace video //! \param[in] lightIndex: the index of the requesting light void assignHardwareLight(u32 lightIndex); + //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` + virtual void setViewPortRaw(u32 width, u32 height); + COGLES1CacheHandler* CacheHandler; core::stringw Name; diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index cbbc61a..604bd7e 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -3240,6 +3240,13 @@ void COpenGLDriver::setViewPort(const core::rect& area) } +void COpenGLDriver::setViewPortRaw(u32 width, u32 height) +{ + CacheHandler->setViewport(0, 0, width, height); + ViewPort = core::recti(0, 0, width, height); +} + + //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do //! this: First, draw all geometry. Then use this method, to draw the shadow //! volume. Next use IVideoDriver::drawStencilShadow() to visualize the shadow. @@ -3872,7 +3879,7 @@ bool COpenGLDriver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SCol destRenderTargetSize = renderTarget->getSize(); - CacheHandler->setViewport(0, 0, destRenderTargetSize.Width, destRenderTargetSize.Height); + setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height); } else { @@ -3898,7 +3905,7 @@ bool COpenGLDriver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SCol destRenderTargetSize = core::dimension2d(0, 0); - CacheHandler->setViewport(0, 0, ScreenSize.Width, ScreenSize.Height); + setViewPortRaw(ScreenSize.Width, ScreenSize.Height); } if (CurrentRenderTargetSize != destRenderTargetSize) @@ -3972,7 +3979,7 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE if (format==video::ECF_UNKNOWN) format=getColorFormat(); - // TODO: Maybe we could support more formats (floating point and some of those beyond ECF_R8), didn't really try yet + // TODO: Maybe we could support more formats (floating point and some of those beyond ECF_R8), didn't really try yet if (IImage::isCompressedFormat(format) || IImage::isDepthFormat(format) || IImage::isFloatingPointFormat(format) || format >= ECF_R8) return 0; diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h index 7c9f869..f3d89fd 100644 --- a/source/Irrlicht/COpenGLDriver.h +++ b/source/Irrlicht/COpenGLDriver.h @@ -428,7 +428,7 @@ namespace video virtual ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) _IRR_OVERRIDE_; virtual ITexture* createDeviceDependentTextureCubemap(const io::path& name, const core::array& image) _IRR_OVERRIDE_; - + //! creates a transposed matrix in supplied GLfloat array to pass to OpenGL inline void getGLMatrix(GLfloat gl_matrix[16], const core::matrix4& m); inline void getGLTextureMatrix(GLfloat gl_matrix[16], const core::matrix4& m); @@ -456,6 +456,9 @@ namespace video void renderArray(const void* indexList, u32 primitiveCount, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType); + //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` + virtual void setViewPortRaw(u32 width, u32 height); + COpenGLCacheHandler* CacheHandler; core::stringw Name;