mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-18 05:33:52 +01:00
Extract and use singular CNullDriver::checkImage
This commit is contained in:
parent
5eb607f86f
commit
e01f285c8f
@ -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,19 +1031,10 @@ 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;
|
||||
|
||||
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();
|
||||
ECOLOR_FORMAT format = image->getColorFormat();
|
||||
core::dimension2d<u32> size = image->getDimension();
|
||||
|
||||
switch (format)
|
||||
{
|
||||
@ -1063,12 +1046,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:
|
||||
@ -1078,12 +1061,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:
|
||||
@ -1091,14 +1074,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:
|
||||
@ -1106,23 +1089,34 @@ 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;
|
||||
}
|
||||
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)
|
||||
status = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = false;
|
||||
}
|
||||
|
||||
return status;
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Enables or disables a texture creation flag.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user