From 64fc9113fc150ff170d76854a70aaeec11de4500 Mon Sep 17 00:00:00 2001 From: cutealien Date: Wed, 6 Apr 2022 20:20:36 +0000 Subject: [PATCH] Split CNullDriver::checkImage into 2 functions to avoid some memory allocations in addTexture Avoid creating dummy arrays when we work with non array images. Just a minor speed improvement. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6329 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CNullDriver.cpp | 169 ++++++++++++++++---------------- source/Irrlicht/CNullDriver.h | 1 + tests/tests-last-passed-at.txt | 2 +- 3 files changed, 84 insertions(+), 88 deletions(-) diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 069b2cc..56925d4 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -441,10 +441,7 @@ ITexture* CNullDriver::addTexture(const core::dimension2d& size, const io:: IImage* image = new CImage(format, size); ITexture* t = 0; - core::array imageArray(1); - imageArray.push_back(image); - - if (checkImage(imageArray)) + if (checkImage(image->getColorFormat(), image->getDimension())) { t = createDeviceDependentTexture(name, image); } @@ -473,18 +470,14 @@ ITexture* CNullDriver::addTexture(const io::path& name, IImage* image) ITexture* t = 0; - core::array imageArray(1); - imageArray.push_back(image); - - if (checkImage(imageArray)) + if (checkImage(image->getColorFormat(), image->getDimension())) { t = createDeviceDependentTexture(name, image); - } - - if (t) - { - addTexture(t); - t->drop(); + if (t) + { + addTexture(t); + t->drop(); + } } return t; @@ -509,12 +502,11 @@ ITexture* CNullDriver::addTextureCubemap(const io::path& name, IImage* imagePosX if (checkImage(imageArray)) { t = createDeviceDependentTextureCubemap(name, imageArray); - } - - if (t) - { - addTexture(t); - t->drop(); + if (t) + { + addTexture(t); + t->drop(); + } } return t; @@ -1430,88 +1422,91 @@ bool CNullDriver::checkPrimitiveCount(u32 prmCount) const bool CNullDriver::checkImage(const core::array& image) const { - bool status = true; - if (image.size() > 0) { ECOLOR_FORMAT lastFormat = image[0]->getColorFormat(); core::dimension2d lastSize = image[0]->getDimension(); - for (u32 i = 0; i < image.size() && status; ++i) + for (u32 i = 0; i < image.size(); ++i) { ECOLOR_FORMAT format = image[i]->getColorFormat(); core::dimension2d size = image[i]->getDimension(); - switch (format) - { - case ECF_DXT1: - case ECF_DXT2: - case ECF_DXT3: - case ECF_DXT4: - case ECF_DXT5: - if (!queryFeature(EVDF_TEXTURE_COMPRESSED_DXT)) - { - os::Printer::log("DXT texture compression not available.", ELL_ERROR); - status = false; - } - else if (size.getOptimalSize(true, false) != size) - { - os::Printer::log("Invalid size of image for DXT texture, size of image must be power of two.", ELL_ERROR); - status = false; - } - break; - case ECF_PVRTC_RGB2: - case ECF_PVRTC_ARGB2: - case ECF_PVRTC_RGB4: - case ECF_PVRTC_ARGB4: - if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC)) - { - os::Printer::log("PVRTC texture compression not available.", ELL_ERROR); - status = false; - } - else if (size.getOptimalSize(true, false) != size) - { - os::Printer::log("Invalid size of image for PVRTC compressed texture, size of image must be power of two and squared.", ELL_ERROR); - status = false; - } - break; - case ECF_PVRTC2_ARGB2: - case ECF_PVRTC2_ARGB4: - if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC2)) - { - os::Printer::log("PVRTC2 texture compression not available.", ELL_ERROR); - status = false; - } - break; - case ECF_ETC1: - if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC1)) - { - os::Printer::log("ETC1 texture compression not available.", ELL_ERROR); - status = false; - } - break; - case ECF_ETC2_RGB: - case ECF_ETC2_ARGB: - if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC2)) - { - os::Printer::log("ETC2 texture compression not available.", ELL_ERROR); - status = false; - } - break; - default: - break; - } - if (format != lastFormat || size != lastSize) - status = false; + return false; + + if ( !checkImage(format, size) ) + return false; } + + return true; } - else + return false; +} + +bool CNullDriver::checkImage(ECOLOR_FORMAT format, const core::dimension2du& size) const +{ + switch (format) { - status = false; + case ECF_DXT1: + case ECF_DXT2: + case ECF_DXT3: + case ECF_DXT4: + case ECF_DXT5: + if (!queryFeature(EVDF_TEXTURE_COMPRESSED_DXT)) + { + os::Printer::log("DXT texture compression not available.", ELL_ERROR); + return false; + } + else if (size.getOptimalSize(true, false) != size) + { + os::Printer::log("Invalid size of image for DXT texture, size of image must be power of two.", ELL_ERROR); + return false; + } + break; + case ECF_PVRTC_RGB2: + case ECF_PVRTC_ARGB2: + case ECF_PVRTC_RGB4: + case ECF_PVRTC_ARGB4: + if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC)) + { + os::Printer::log("PVRTC texture compression not available.", ELL_ERROR); + return false; + } + else if (size.getOptimalSize(true, false) != size) + { + os::Printer::log("Invalid size of image for PVRTC compressed texture, size of image must be power of two and squared.", ELL_ERROR); + return false; + } + break; + case ECF_PVRTC2_ARGB2: + case ECF_PVRTC2_ARGB4: + if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC2)) + { + os::Printer::log("PVRTC2 texture compression not available.", ELL_ERROR); + return false; + } + break; + case ECF_ETC1: + if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC1)) + { + os::Printer::log("ETC1 texture compression not available.", ELL_ERROR); + return false; + } + break; + case ECF_ETC2_RGB: + case ECF_ETC2_ARGB: + if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC2)) + { + os::Printer::log("ETC2 texture compression not available.", ELL_ERROR); + return false; + } + break; + default: + break; } - return status; + return true; } //! Enables or disables a texture creation flag. diff --git a/source/Irrlicht/CNullDriver.h b/source/Irrlicht/CNullDriver.h index 33c96e6..e4cc569 100644 --- a/source/Irrlicht/CNullDriver.h +++ b/source/Irrlicht/CNullDriver.h @@ -707,6 +707,7 @@ namespace video bool checkPrimitiveCount(u32 prmcnt) const; bool checkImage(const core::array& image) const; + bool checkImage(ECOLOR_FORMAT format, const core::dimension2du& size) const; // adds a material renderer and drops it afterwards. To be used for internal creation s32 addAndDropMaterialRenderer(IMaterialRenderer* m); diff --git a/tests/tests-last-passed-at.txt b/tests/tests-last-passed-at.txt index c231e34..8d385b7 100644 --- a/tests/tests-last-passed-at.txt +++ b/tests/tests-last-passed-at.txt @@ -1,4 +1,4 @@ Tests finished. 72 tests of 72 passed. Compiled as DEBUG -Test suite pass at GMT Wed Mar 30 21:02:37 2022 +Test suite pass at GMT Wed Apr 06 20:16:43 2022