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
This commit is contained in:
cutealien 2022-04-06 20:20:36 +00:00
parent 2ddd6f5355
commit 64fc9113fc
3 changed files with 84 additions and 88 deletions

View File

@ -441,10 +441,7 @@ ITexture* CNullDriver::addTexture(const core::dimension2d<u32>& size, const io::
IImage* image = new CImage(format, size);
ITexture* t = 0;
core::array<IImage*> imageArray(1);
imageArray.push_back(image);
if (checkImage(imageArray))
if (checkImage(image->getColorFormat(), image->getDimension()))
{
t = createDeviceDependentTexture(name, image);
}
@ -473,19 +470,15 @@ ITexture* CNullDriver::addTexture(const io::path& name, IImage* image)
ITexture* t = 0;
core::array<IImage*> 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();
}
}
return t;
}
@ -509,13 +502,12 @@ ITexture* CNullDriver::addTextureCubemap(const io::path& name, IImage* imagePosX
if (checkImage(imageArray))
{
t = createDeviceDependentTextureCubemap(name, imageArray);
}
if (t)
{
addTexture(t);
t->drop();
}
}
return t;
}
@ -1430,18 +1422,30 @@ bool CNullDriver::checkPrimitiveCount(u32 prmCount) const
bool CNullDriver::checkImage(const core::array<IImage*>& image) const
{
bool status = true;
if (image.size() > 0)
{
ECOLOR_FORMAT lastFormat = image[0]->getColorFormat();
core::dimension2d<u32> 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<u32> size = image[i]->getDimension();
if (format != lastFormat || size != lastSize)
return false;
if ( !checkImage(format, size) )
return false;
}
return true;
}
return false;
}
bool CNullDriver::checkImage(ECOLOR_FORMAT format, const core::dimension2du& size) const
{
switch (format)
{
case ECF_DXT1:
@ -1452,12 +1456,12 @@ bool CNullDriver::checkImage(const core::array<IImage*>& image) const
if (!queryFeature(EVDF_TEXTURE_COMPRESSED_DXT))
{
os::Printer::log("DXT texture compression not available.", ELL_ERROR);
status = false;
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);
status = false;
return false;
}
break;
case ECF_PVRTC_RGB2:
@ -1467,12 +1471,12 @@ bool CNullDriver::checkImage(const core::array<IImage*>& image) const
if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC))
{
os::Printer::log("PVRTC texture compression not available.", ELL_ERROR);
status = false;
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);
status = false;
return false;
}
break;
case ECF_PVRTC2_ARGB2:
@ -1480,14 +1484,14 @@ bool CNullDriver::checkImage(const core::array<IImage*>& image) const
if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC2))
{
os::Printer::log("PVRTC2 texture compression not available.", ELL_ERROR);
status = false;
return false;
}
break;
case ECF_ETC1:
if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC1))
{
os::Printer::log("ETC1 texture compression not available.", ELL_ERROR);
status = false;
return false;
}
break;
case ECF_ETC2_RGB:
@ -1495,23 +1499,14 @@ bool CNullDriver::checkImage(const core::array<IImage*>& image) const
if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC2))
{
os::Printer::log("ETC2 texture compression not available.", ELL_ERROR);
status = false;
return false;
}
break;
default:
break;
}
if (format != lastFormat || size != lastSize)
status = false;
}
}
else
{
status = false;
}
return status;
return true;
}
//! Enables or disables a texture creation flag.

View File

@ -707,6 +707,7 @@ namespace video
bool checkPrimitiveCount(u32 prmcnt) const;
bool checkImage(const core::array<IImage*>& 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);

View File

@ -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