Extract and use singular CNullDriver::checkImage

This commit is contained in:
numzero 2023-04-08 01:45:11 +03:00 committed by sfan5
parent 5eb607f86f
commit e01f285c8f
2 changed files with 84 additions and 88 deletions

@ -344,10 +344,7 @@ ITexture* CNullDriver::addTexture(const core::dimension2d<u32>& size, const io::
IImage* image = new CImage(format, size); IImage* image = new CImage(format, size);
ITexture* t = 0; ITexture* t = 0;
core::array<IImage*> imageArray(1); if (checkImage(image))
imageArray.push_back(image);
if (checkImage(imageArray))
{ {
t = createDeviceDependentTexture(name, image); t = createDeviceDependentTexture(name, image);
} }
@ -376,10 +373,7 @@ ITexture* CNullDriver::addTexture(const io::path& name, IImage* image)
ITexture* t = 0; ITexture* t = 0;
core::array<IImage*> imageArray(1); if (checkImage(image))
imageArray.push_back(image);
if (checkImage(imageArray))
{ {
t = createDeviceDependentTexture(name, image); t = createDeviceDependentTexture(name, image);
} }
@ -559,9 +553,7 @@ video::ITexture* CNullDriver::loadTextureFromFile(io::IReadFile* file, const io:
if (!image) if (!image)
return nullptr; return nullptr;
core::array<IImage*> imageArray; if (checkImage(image)) {
imageArray.push_back(image);
if (checkImage(imageArray)) {
texture = createDeviceDependentTexture(hashName.size() ? hashName : file->getFileName(), image); texture = createDeviceDependentTexture(hashName.size() ? hashName : file->getFileName(), image);
if (texture) if (texture)
os::Printer::log("Loaded texture", file->getFileName(), ELL_DEBUG); os::Printer::log("Loaded texture", file->getFileName(), ELL_DEBUG);
@ -1039,19 +1031,10 @@ bool CNullDriver::checkPrimitiveCount(u32 prmCount) const
return true; return true;
} }
bool CNullDriver::checkImage(const core::array<IImage*>& image) const bool CNullDriver::checkImage(IImage *image) const
{ {
bool status = true; ECOLOR_FORMAT format = image->getColorFormat();
core::dimension2d<u32> size = image->getDimension();
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)
{
ECOLOR_FORMAT format = image[i]->getColorFormat();
core::dimension2d<u32> size = image[i]->getDimension();
switch (format) switch (format)
{ {
@ -1063,12 +1046,12 @@ bool CNullDriver::checkImage(const core::array<IImage*>& image) const
if (!queryFeature(EVDF_TEXTURE_COMPRESSED_DXT)) if (!queryFeature(EVDF_TEXTURE_COMPRESSED_DXT))
{ {
os::Printer::log("DXT texture compression not available.", ELL_ERROR); os::Printer::log("DXT texture compression not available.", ELL_ERROR);
status = false; return false;
} }
else if (size.getOptimalSize(true, false) != size) 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); 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; break;
case ECF_PVRTC_RGB2: case ECF_PVRTC_RGB2:
@ -1078,12 +1061,12 @@ bool CNullDriver::checkImage(const core::array<IImage*>& image) const
if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC)) if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC))
{ {
os::Printer::log("PVRTC texture compression not available.", ELL_ERROR); os::Printer::log("PVRTC texture compression not available.", ELL_ERROR);
status = false; return false;
} }
else if (size.getOptimalSize(true, false) != size) 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); 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; break;
case ECF_PVRTC2_ARGB2: case ECF_PVRTC2_ARGB2:
@ -1091,14 +1074,14 @@ bool CNullDriver::checkImage(const core::array<IImage*>& image) const
if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC2)) if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC2))
{ {
os::Printer::log("PVRTC2 texture compression not available.", ELL_ERROR); os::Printer::log("PVRTC2 texture compression not available.", ELL_ERROR);
status = false; return false;
} }
break; break;
case ECF_ETC1: case ECF_ETC1:
if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC1)) if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC1))
{ {
os::Printer::log("ETC1 texture compression not available.", ELL_ERROR); os::Printer::log("ETC1 texture compression not available.", ELL_ERROR);
status = false; return false;
} }
break; break;
case ECF_ETC2_RGB: case ECF_ETC2_RGB:
@ -1106,23 +1089,34 @@ bool CNullDriver::checkImage(const core::array<IImage*>& image) const
if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC2)) if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC2))
{ {
os::Printer::log("ETC2 texture compression not available.", ELL_ERROR); os::Printer::log("ETC2 texture compression not available.", ELL_ERROR);
status = false; return false;
} }
break; break;
default: default:
break; break;
} }
return true;
}
bool CNullDriver::checkImage(const core::array<IImage*>& image) const
{
if (!image.size())
return false;
ECOLOR_FORMAT lastFormat = image[0]->getColorFormat();
core::dimension2d<u32> lastSize = image[0]->getDimension();
for (u32 i = 0; i < image.size(); ++i) {
ECOLOR_FORMAT format = image[i]->getColorFormat();
core::dimension2d<u32> size = image[i]->getDimension();
if (!checkImage(image[i]))
return false;
if (format != lastFormat || size != lastSize) if (format != lastFormat || size != lastSize)
status = false; return false;
} }
} return true;
else
{
status = false;
}
return status;
} }
//! Enables or disables a texture creation flag. //! Enables or disables a texture creation flag.

@ -670,6 +670,8 @@ namespace video
//! checks triangle count and print warning if wrong //! checks triangle count and print warning if wrong
bool checkPrimitiveCount(u32 prmcnt) const; bool checkPrimitiveCount(u32 prmcnt) const;
bool checkImage(IImage *image) const;
bool checkImage(const core::array<IImage*>& image) const; bool checkImage(const core::array<IImage*>& image) const;
// adds a material renderer and drops it afterwards. To be used for internal creation // adds a material renderer and drops it afterwards. To be used for internal creation