#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_SOFTWARE_
#include "CSoftwareTexture.h"
#include "os.h"
namespace irr
{
namespace video
{
CSoftwareTexture::CSoftwareTexture(IImage* image, const io::path& name,
bool renderTarget, void* mipmapData)
: ITexture(name), Texture(0), IsRenderTarget(renderTarget)
{
#ifdef _DEBUG
setDebugName("CSoftwareTexture");
#endif
if (image)
{
OrigSize = image->getDimension();
core::dimension2d<u32> optSize=OrigSize.getOptimalSize();
Image = new CImage(ECF_A1R5G5B5, OrigSize);
image->copyTo(Image);
if (optSize == OrigSize)
{
Texture = Image;
Texture->grab();
}
else
{
Texture = new CImage(ECF_A1R5G5B5, optSize);
Image->copyToScaling(Texture);
}
}
}
CSoftwareTexture::~CSoftwareTexture()
{
if (Image)
Image->drop();
if (Texture)
Texture->drop();
}
void* CSoftwareTexture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
{
return Image->lock();
}
void CSoftwareTexture::unlock()
{
if (Image != Texture)
{
os::Printer::log("Performance warning, slow unlock of non power of 2 texture.", ELL_WARNING);
Image->copyToScaling(Texture);
}
Image->unlock();
}
const core::dimension2d<u32>& CSoftwareTexture::getOriginalSize() const
{
return OrigSize;
}
const core::dimension2d<u32>& CSoftwareTexture::getSize() const
{
return Image->getDimension();
}
CImage* CSoftwareTexture::getImage()
{
return Image;
}
CImage* CSoftwareTexture::getTexture()
{
return Texture;
}
E_DRIVER_TYPE CSoftwareTexture::getDriverType() const
{
return EDT_SOFTWARE;
}
ECOLOR_FORMAT CSoftwareTexture::getColorFormat() const
{
return ECF_A1R5G5B5;
}
u32 CSoftwareTexture::getPitch() const
{
return Image->getDimension().Width * 2;
}
void CSoftwareTexture::regenerateMipMapLevels(void* mipmapData)
{
}
bool CSoftwareTexture::isRenderTarget() const
{
return IsRenderTarget;
}
}
}
#endif