stk-code_catmod/lib/graphics_engine/src/ge_texture.cpp

78 lines
2.2 KiB
C++
Raw Normal View History

#include "ge_main.hpp"
2021-04-17 00:44:25 -04:00
#include "ge_gl_texture.hpp"
#include "ge_texture.hpp"
#include <IVideoDriver.h>
#include <IAttributes.h>
namespace GE
{
using namespace irr;
2021-04-17 00:44:25 -04:00
video::IImage* getResizedImage(const std::string& path,
core::dimension2d<u32>* orig_size)
{
video::IImage* image = getDriver()->createImageFromFile(path.c_str());
if (image == NULL)
return NULL;
2021-04-17 00:44:25 -04:00
if (orig_size)
*orig_size = image->getDimension();
core::dimension2du img_size = image->getDimension();
bool has_npot = !getGEConfig()->m_disable_npot_texture &&
getDriver()->queryFeature(video::EVDF_TEXTURE_NPOT);
core::dimension2du tex_size = img_size.getOptimalSize(!has_npot);
const core::dimension2du& max_size = getDriver()->getDriverAttributes().
getAttributeAsDimension2d("MAX_TEXTURE_SIZE");
if (tex_size.Width > max_size.Width)
tex_size.Width = max_size.Width;
if (tex_size.Height > max_size.Height)
tex_size.Height = max_size.Height;
if (image->getColorFormat() != video::ECF_A8R8G8B8 ||
tex_size != img_size)
{
video::IImage* new_texture = getDriver()->createImage(
video::ECF_A8R8G8B8, tex_size);
if (tex_size != img_size)
image->copyToScaling(new_texture);
else
image->copyTo(new_texture);
image->drop();
return new_texture;
}
return image;
2021-04-17 00:44:25 -04:00
} // getResizedImage
// ----------------------------------------------------------------------------
irr::video::ITexture* createTexture(const std::string& path,
std::function<void(irr::video::IImage*)> image_mani)
{
switch (GE::getDriver()->getDriverType())
{
case video::EDT_OPENGL:
case video::EDT_OGLES2:
return new GEGLTexture(path, image_mani);
default:
return NULL;
}
} // createTexture
// ----------------------------------------------------------------------------
irr::video::ITexture* createTexture(video::IImage* img,
const std::string& name)
{
switch (GE::getDriver()->getDriverType())
{
case video::EDT_OPENGL:
case video::EDT_OGLES2:
return new GEGLTexture(img, name);
default:
return NULL;
}
} // createTexture
}