aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authornumzero <numzer0@yandex.ru>2023-04-08 01:45:11 +0300
committersfan5 <sfan5@live.de>2023-04-08 19:07:16 +0200
commite01f285c8fee31bffa4b34dc8a393085f2d0d143 (patch)
tree30af54be4826e0df12aa21a50b3e3eb7b7ad359b /source
parent5eb607f86fa514c24da80650a507889fa0c871e9 (diff)
downloadirrlicht-e01f285c8fee31bffa4b34dc8a393085f2d0d143.tar.xz
Extract and use singular CNullDriver::checkImage
Diffstat (limited to 'source')
-rw-r--r--source/Irrlicht/CNullDriver.cpp170
-rw-r--r--source/Irrlicht/CNullDriver.h2
2 files changed, 84 insertions, 88 deletions
diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp
index 43b59d0..6ef7c17 100644
--- a/source/Irrlicht/CNullDriver.cpp
+++ b/source/Irrlicht/CNullDriver.cpp
@@ -344,10 +344,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))
{
t = createDeviceDependentTexture(name, image);
}
@@ -376,10 +373,7 @@ 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))
{
t = createDeviceDependentTexture(name, image);
}
@@ -559,9 +553,7 @@ video::ITexture* CNullDriver::loadTextureFromFile(io::IReadFile* file, const io:
if (!image)
return nullptr;
- core::array<IImage*> imageArray;
- imageArray.push_back(image);
- if (checkImage(imageArray)) {
+ if (checkImage(image)) {
texture = createDeviceDependentTexture(hashName.size() ? hashName : file->getFileName(), image);
if (texture)
os::Printer::log("Loaded texture", file->getFileName(), ELL_DEBUG);
@@ -1039,90 +1031,92 @@ bool CNullDriver::checkPrimitiveCount(u32 prmCount) const
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)
+ switch (format)
{
- ECOLOR_FORMAT lastFormat = image[0]->getColorFormat();
- core::dimension2d<u32> lastSize = image[0]->getDimension();
-
- for (u32 i = 0; i < image.size() && status; ++i)
+ case ECF_DXT1:
+ case ECF_DXT2:
+ case ECF_DXT3:
+ case ECF_DXT4:
+ case ECF_DXT5:
+ if (!queryFeature(EVDF_TEXTURE_COMPRESSED_DXT))
{
- 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;
+ 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;
}
- else
- {
- status = false;
- }
+ return true;
+}
+
+bool CNullDriver::checkImage(const core::array<IImage*>& image) const
+{
+ if (!image.size())
+ return false;
- return status;
+ 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)
+ return false;
+ }
+ return true;
}
//! Enables or disables a texture creation flag.
diff --git a/source/Irrlicht/CNullDriver.h b/source/Irrlicht/CNullDriver.h
index 95fc0d9..d3d933c 100644
--- a/source/Irrlicht/CNullDriver.h
+++ b/source/Irrlicht/CNullDriver.h
@@ -670,6 +670,8 @@ namespace video
//! checks triangle count and print warning if wrong
bool checkPrimitiveCount(u32 prmcnt) const;
+ bool checkImage(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