From b584c39295c7d40375d27feb0d72e1123efc8871 Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 22 Nov 2018 19:13:59 +0000 Subject: [PATCH] ITexture::lock interface changed. - mipmapLevel is now the second parameter as it was in Irrlicht 1.8 (but currently not doing anything) - layer moved to third parameter - New parameter lockFlags which allows to disabled flipping the texture upside down for RTT's on OpenGL. Sorry for any inconvenience this change causes, but as I had to break the interface now anyway I decided to make it backward compatible to Irrlicht 1.8. Anyone already using the new "layers" feature in trunk will have to move the layer parameter now. But the last interface change which replaced the mipmaplevel with another variable with very different meaning wasn't a solution. Mipmap support can also likely be re-introduced. At least I still haven't seen a real reason why it shouldn't be possible to have that anymore. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5663 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/ITexture.h | 30 +++++++++++++++++++++++++++- source/Irrlicht/CD3D9Texture.cpp | 2 +- source/Irrlicht/CD3D9Texture.h | 2 +- source/Irrlicht/CNullDriver.h | 2 +- source/Irrlicht/COpenGLCoreTexture.h | 4 ++-- source/Irrlicht/CSoftwareTexture.cpp | 2 +- source/Irrlicht/CSoftwareTexture.h | 2 +- source/Irrlicht/CSoftwareTexture2.h | 10 ++-------- tests/main.cpp | 2 +- tests/tests-last-passed-at.txt | 8 ++++---- 10 files changed, 43 insertions(+), 21 deletions(-) diff --git a/include/ITexture.h b/include/ITexture.h index 4e4313db..be2f8bd3 100644 --- a/include/ITexture.h +++ b/include/ITexture.h @@ -94,6 +94,30 @@ enum E_TEXTURE_LOCK_MODE ETLM_WRITE_ONLY }; +//! Additional bitflags for ITexture::lock() call +enum E_TEXTURE_LOCK_FLAGS +{ + ETLF_NONE = 0, + + //! Flip left-bottom origin rendertarget textures upside-down + /** Irrlicht usually has all textures with left-top as origin. + And for drivers with a left-bottom origin coordinate system (OpenGL) + Irrlicht modifies the texture-matrix in the fixed function pipeline to make + the textures show up correctly (shader coders have to handle upside down + textures themselves). + But rendertarget textures (RTT's) are written by drivers the way the + coordinate system of that driver works. So on OpenGL images tend to look + upside down (aka Y coordinate going up) on lock() when this flag isn't set. + When the flag is set it will flip such textures on lock() to make them look + like non-rtt textures (origin left-top). Note that this also means the texture + will be uploaded flipped on unlock. So mostly you want to have this flag set + when you want to look at the texture or save it, but unset if you want to + upload it again to the card. + If you disable this flag you get the memory just as it is on the graphic card. + For backward compatibility reasons this flag is enabled by default. */ + ETLF_FLIP_Y_UP_RTT = 1 +}; + //! Where did the last IVideoDriver::getTexture call find this texture enum E_TEXTURE_SOURCE { @@ -151,11 +175,15 @@ public: only mode or read from in write only mode. Support for this feature depends on the driver, so don't rely on the texture being write-protected when locking with read-only, etc. + \param mipmapLevel NOTE: Currently broken, sorry, we try if we can repair it for 1.9 release. + Number of the mipmapLevel to lock. 0 is main texture. + Non-existing levels will silently fail and return 0. \param layer It determines which cubemap face or texture array layer should be locked. + \param lockFlags See E_TEXTURE_LOCK_FLAGS documentation. \return Returns a pointer to the pixel data. The format of the pixel can be determined by using getColorFormat(). 0 is returned, if the texture cannot be locked. */ - virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) = 0; + virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel=0, u32 layer = 0, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) = 0; //! Unlock function. Must be called after a lock() to the texture. /** One should avoid to call unlock more than once before another lock. diff --git a/source/Irrlicht/CD3D9Texture.cpp b/source/Irrlicht/CD3D9Texture.cpp index d11022bf..b71458ab 100644 --- a/source/Irrlicht/CD3D9Texture.cpp +++ b/source/Irrlicht/CD3D9Texture.cpp @@ -177,7 +177,7 @@ CD3D9Texture::~CD3D9Texture() Device->Release(); } -void* CD3D9Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 layer) +void* CD3D9Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel, u32 layer, E_TEXTURE_LOCK_FLAGS lockFlags) { if (LockData) return LockData; diff --git a/source/Irrlicht/CD3D9Texture.h b/source/Irrlicht/CD3D9Texture.h index aa09d4e0..015465ec 100644 --- a/source/Irrlicht/CD3D9Texture.h +++ b/source/Irrlicht/CD3D9Texture.h @@ -32,7 +32,7 @@ public: virtual ~CD3D9Texture(); - virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) _IRR_OVERRIDE_; + virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel=0, u32 layer = 0, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) _IRR_OVERRIDE_; virtual void unlock() _IRR_OVERRIDE_; diff --git a/source/Irrlicht/CNullDriver.h b/source/Irrlicht/CNullDriver.h index 8ae042cf..a312848d 100644 --- a/source/Irrlicht/CNullDriver.h +++ b/source/Irrlicht/CNullDriver.h @@ -783,7 +783,7 @@ namespace video { SDummyTexture(const io::path& name, E_TEXTURE_TYPE type) : ITexture(name, type) {}; - virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) _IRR_OVERRIDE_ { return 0; } + virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel=0, u32 layer = 0, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) _IRR_OVERRIDE_ { return 0; } virtual void unlock()_IRR_OVERRIDE_ {} virtual void regenerateMipMapLevels(void* data = 0, u32 layer = 0) _IRR_OVERRIDE_ {} }; diff --git a/source/Irrlicht/COpenGLCoreTexture.h b/source/Irrlicht/COpenGLCoreTexture.h index abe6fe1a..2f490a30 100644 --- a/source/Irrlicht/COpenGLCoreTexture.h +++ b/source/Irrlicht/COpenGLCoreTexture.h @@ -206,7 +206,7 @@ public: Image[i]->drop(); } - virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) _IRR_OVERRIDE_ + virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel=0, u32 layer = 0, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) _IRR_OVERRIDE_ { if (LockImage) return LockImage->getData(); @@ -248,7 +248,7 @@ public: glGetTexImage(tmpTextureType, 0, PixelFormat, PixelType, tmpImage->getData()); - if (IsRenderTarget) + if (IsRenderTarget && lockFlags == ETLF_FLIP_Y_UP_RTT) { const s32 pitch = tmpImage->getPitch(); diff --git a/source/Irrlicht/CSoftwareTexture.cpp b/source/Irrlicht/CSoftwareTexture.cpp index 78a64cb5..76c22623 100644 --- a/source/Irrlicht/CSoftwareTexture.cpp +++ b/source/Irrlicht/CSoftwareTexture.cpp @@ -76,7 +76,7 @@ CSoftwareTexture::~CSoftwareTexture() //! lock function -void* CSoftwareTexture::lock(E_TEXTURE_LOCK_MODE mode, u32 layer) +void* CSoftwareTexture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel, u32 layer, E_TEXTURE_LOCK_FLAGS lockFlags) { return Image->getData(); } diff --git a/source/Irrlicht/CSoftwareTexture.h b/source/Irrlicht/CSoftwareTexture.h index 55efb8c8..5d6d97e4 100644 --- a/source/Irrlicht/CSoftwareTexture.h +++ b/source/Irrlicht/CSoftwareTexture.h @@ -30,7 +30,7 @@ public: virtual ~CSoftwareTexture(); //! lock function - virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) _IRR_OVERRIDE_; + virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel=0, u32 layer = 0, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) _IRR_OVERRIDE_; //! unlock function virtual void unlock() _IRR_OVERRIDE_; diff --git a/source/Irrlicht/CSoftwareTexture2.h b/source/Irrlicht/CSoftwareTexture2.h index 42eb880f..ac3c1fc5 100644 --- a/source/Irrlicht/CSoftwareTexture2.h +++ b/source/Irrlicht/CSoftwareTexture2.h @@ -38,11 +38,11 @@ public: virtual ~CSoftwareTexture2(); //! lock function - virtual void* lock(E_TEXTURE_LOCK_MODE mode, u32 level, u32 layer) + virtual void* lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel, u32 layer, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) _IRR_OVERRIDE_ { if (Flags & GEN_MIPMAP) { - MipMapLOD = level; + MipMapLOD = mipmapLevel; Size = MipMap[MipMapLOD]->getDimension(); Pitch = MipMap[MipMapLOD]->getPitch(); } @@ -50,12 +50,6 @@ public: return MipMap[MipMapLOD]->getData(); } - //! lock function - virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 layer = 0) _IRR_OVERRIDE_ - { - return lock(mode, 0, layer); - } - //! unlock function virtual void unlock() _IRR_OVERRIDE_ { diff --git a/tests/main.cpp b/tests/main.cpp index a3e98a78..a0a73b9d 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -49,7 +49,7 @@ int main(int argumentCount, char * arguments[]) #if 0 // To interactively debug a test, move it (temporarily) in here and enable the define to only run this test // Otherwise debugging is slightly tricky as each test runs in it's own process. - TEST(renderTargetTexture); + TEST(textureFeatures); #else TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory. // Now the simple tests without device diff --git a/tests/tests-last-passed-at.txt b/tests/tests-last-passed-at.txt index 5abd9a42..4dc6fcf9 100644 --- a/tests/tests-last-passed-at.txt +++ b/tests/tests-last-passed-at.txt @@ -1,4 +1,4 @@ -Tests finished. 1 test of 1 passed. -Compiled as DEBUG -Test suite pass at GMT Tue Nov 7 00:42:08 2017 - +Tests finished. 1 test of 1 passed. +Compiled as DEBUG +Test suite pass at GMT Mon Nov 19 21:48:32 2018 +