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

@ -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,18 +470,14 @@ 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();
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<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();
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.

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

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