- Removed unnecessary virtual methods in ITexture and reduced double lines of code across video drivers.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5017 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
b9db93b6c6
commit
883ed034d4
|
@ -113,7 +113,8 @@ class ITexture : public virtual IReferenceCounted
|
|||
public:
|
||||
|
||||
//! constructor
|
||||
ITexture(const io::path& name) : NamedPath(name), Source(ETS_UNKNOWN)
|
||||
ITexture(const io::path& name) : NamedPath(name), DriverType(EDT_NULL), ColorFormat(ECF_UNKNOWN),
|
||||
Pitch(0), HasMipMaps(false), HasAlpha(false), IsRenderTarget(false), Source(ETS_UNKNOWN)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -144,6 +145,15 @@ public:
|
|||
The last locked mip level will be unlocked. */
|
||||
virtual void unlock() = 0;
|
||||
|
||||
//! Regenerates the mip map levels of the texture.
|
||||
/** Required after modifying the texture, usually after calling unlock().
|
||||
\param mipmapData Optional parameter to pass in image data which will be
|
||||
used instead of the previously stored or automatically generated mipmap
|
||||
data. The data has to be a continuous pixel data for all mipmaps until
|
||||
1x1 pixel. Each mipmap has to be half the width and height of the previous
|
||||
level. At least one pixel will be always kept.*/
|
||||
virtual void regenerateMipMapLevels(void* mipmapData = 0) = 0;
|
||||
|
||||
//! Get original size of the texture.
|
||||
/** The texture is usually scaled, if it was created with an unoptimal
|
||||
size. For example if the size was not a power of two. This method
|
||||
|
@ -152,53 +162,42 @@ public:
|
|||
exact size of the original texture. Use ITexture::getSize() if you want
|
||||
to know the real size it has now stored in the system.
|
||||
\return The original size of the texture. */
|
||||
virtual const core::dimension2d<u32>& getOriginalSize() const = 0;
|
||||
const core::dimension2d<u32>& getOriginalSize() const { return OriginalSize; };
|
||||
|
||||
//! Get dimension (=size) of the texture.
|
||||
/** \return The size of the texture. */
|
||||
virtual const core::dimension2d<u32>& getSize() const = 0;
|
||||
const core::dimension2d<u32>& getSize() const { return Size; };
|
||||
|
||||
//! Get driver type of texture.
|
||||
/** This is the driver, which created the texture. This method is used
|
||||
internally by the video devices, to check, if they may use a texture
|
||||
because textures may be incompatible between different devices.
|
||||
\return Driver type of texture. */
|
||||
virtual E_DRIVER_TYPE getDriverType() const = 0;
|
||||
E_DRIVER_TYPE getDriverType() const { return DriverType; };
|
||||
|
||||
//! Get the color format of texture.
|
||||
/** \return The color format of texture. */
|
||||
virtual ECOLOR_FORMAT getColorFormat() const = 0;
|
||||
ECOLOR_FORMAT getColorFormat() const { return ColorFormat; };
|
||||
|
||||
//! Get pitch of the main texture (in bytes).
|
||||
/** The pitch is the amount of bytes used for a row of pixels in a
|
||||
texture.
|
||||
\return Pitch of texture in bytes. */
|
||||
virtual u32 getPitch() const = 0;
|
||||
u32 getPitch() const { return Pitch; };
|
||||
|
||||
//! Check whether the texture has MipMaps
|
||||
/** \return True if texture has MipMaps, else false. */
|
||||
virtual bool hasMipMaps() const { return false; }
|
||||
bool hasMipMaps() const { return HasMipMaps; }
|
||||
|
||||
//! Returns if the texture has an alpha channel
|
||||
virtual bool hasAlpha() const {
|
||||
return getColorFormat () == video::ECF_A8R8G8B8 || getColorFormat () == video::ECF_A1R5G5B5;
|
||||
}
|
||||
|
||||
//! Regenerates the mip map levels of the texture.
|
||||
/** Required after modifying the texture, usually after calling unlock().
|
||||
\param mipmapData Optional parameter to pass in image data which will be
|
||||
used instead of the previously stored or automatically generated mipmap
|
||||
data. The data has to be a continuous pixel data for all mipmaps until
|
||||
1x1 pixel. Each mipmap has to be half the width and height of the previous
|
||||
level. At least one pixel will be always kept.*/
|
||||
virtual void regenerateMipMapLevels(void* mipmapData=0) = 0;
|
||||
bool hasAlpha() const { return HasAlpha; }
|
||||
|
||||
//! Check whether the texture is a render target
|
||||
/** Render targets can be set as such in the video driver, in order to
|
||||
render a scene into the texture. Once unbound as render target, they can
|
||||
be used just as usual textures again.
|
||||
\return True if this is a render target, otherwise false. */
|
||||
virtual bool isRenderTarget() const { return false; }
|
||||
bool isRenderTarget() const { return IsRenderTarget; }
|
||||
|
||||
//! Get name of texture (in most cases this is the filename)
|
||||
const io::SNamedPath& getName() const { return NamedPath; }
|
||||
|
@ -228,6 +227,14 @@ protected:
|
|||
}
|
||||
|
||||
io::SNamedPath NamedPath;
|
||||
core::dimension2d<u32> OriginalSize;
|
||||
core::dimension2d<u32> Size;
|
||||
E_DRIVER_TYPE DriverType;
|
||||
ECOLOR_FORMAT ColorFormat;
|
||||
u32 Pitch;
|
||||
bool HasMipMaps;
|
||||
bool HasAlpha;
|
||||
bool IsRenderTarget;
|
||||
E_TEXTURE_SOURCE Source;
|
||||
};
|
||||
|
||||
|
|
|
@ -33,8 +33,7 @@ namespace video
|
|||
CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, const core::dimension2d<u32>& size,
|
||||
const io::path& name, const ECOLOR_FORMAT format)
|
||||
: ITexture(name), Texture(0), RTTSurface(0), Driver(driver), DepthSurface(0),
|
||||
TextureSize(size), ImageSize(size), Pitch(0), ColorFormat(ECF_UNKNOWN),
|
||||
HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(true), IsCompressed(false)
|
||||
HardwareMipMaps(false), IsCompressed(false)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CD3D9Texture");
|
||||
|
@ -44,6 +43,11 @@ CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, const core::dimension2d<u32>& si
|
|||
if (Device)
|
||||
Device->AddRef();
|
||||
|
||||
DriverType = EDT_DIRECT3D9;
|
||||
OriginalSize = size;
|
||||
Size = size;
|
||||
IsRenderTarget = true;
|
||||
|
||||
createRenderTarget(format);
|
||||
}
|
||||
|
||||
|
@ -52,13 +56,13 @@ CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, const core::dimension2d<u32>& si
|
|||
CD3D9Texture::CD3D9Texture(IImage* image, CD3D9Driver* driver,
|
||||
u32 flags, const io::path& name, void* mipmapData)
|
||||
: ITexture(name), Texture(0), RTTSurface(0), Driver(driver), DepthSurface(0),
|
||||
TextureSize(0,0), ImageSize(0,0), Pitch(0), ColorFormat(ECF_UNKNOWN),
|
||||
HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false), IsCompressed(false)
|
||||
HardwareMipMaps(false), IsCompressed(false)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CD3D9Texture");
|
||||
#endif
|
||||
|
||||
DriverType = EDT_DIRECT3D9;
|
||||
HasMipMaps = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
|
||||
|
||||
Device=driver->getExposedVideoData().D3D9.D3DDev9;
|
||||
|
@ -67,7 +71,7 @@ CD3D9Texture::CD3D9Texture(IImage* image, CD3D9Driver* driver,
|
|||
|
||||
if (image)
|
||||
{
|
||||
if(image->getColorFormat() == ECF_DXT1 || image->getColorFormat() == ECF_DXT2 || image->getColorFormat() == ECF_DXT3 || image->getColorFormat() == ECF_DXT4 || image->getColorFormat() == ECF_DXT5)
|
||||
if (IImage::isCompressedFormat(image->getColorFormat()))
|
||||
{
|
||||
if(!Driver->queryFeature(EVDF_TEXTURE_COMPRESSED_DXT))
|
||||
{
|
||||
|
@ -132,10 +136,11 @@ void CD3D9Texture::createRenderTarget(const ECOLOR_FORMAT format)
|
|||
// are texture size restrictions there ?
|
||||
if(!Driver->queryFeature(EVDF_TEXTURE_NPOT))
|
||||
{
|
||||
if (TextureSize != ImageSize)
|
||||
if (Size != OriginalSize)
|
||||
os::Printer::log("RenderTarget size has to be a power of two", ELL_INFORMATION);
|
||||
}
|
||||
TextureSize = TextureSize.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT), !Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);
|
||||
|
||||
Size = Size.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT), !Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);
|
||||
|
||||
D3DFORMAT d3dformat = Driver->getD3DColorFormat();
|
||||
|
||||
|
@ -159,12 +164,24 @@ void CD3D9Texture::createRenderTarget(const ECOLOR_FORMAT format)
|
|||
d3dformat = Driver->getD3DFormatFromColorFormat(ColorFormat);
|
||||
}
|
||||
|
||||
switch (ColorFormat)
|
||||
{
|
||||
case ECF_A8R8G8B8:
|
||||
case ECF_A1R5G5B5:
|
||||
case ECF_A16B16G16R16F:
|
||||
case ECF_A32B32G32R32F:
|
||||
HasAlpha = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// create texture
|
||||
HRESULT hr;
|
||||
|
||||
hr = Device->CreateTexture(
|
||||
TextureSize.Width,
|
||||
TextureSize.Height,
|
||||
Size.Width,
|
||||
Size.Height,
|
||||
1, // mip map level count, we don't want mipmaps here
|
||||
D3DUSAGE_RENDERTARGET,
|
||||
d3dformat,
|
||||
|
@ -290,9 +307,9 @@ bool CD3D9Texture::createMipMaps(u32 level)
|
|||
//! creates the hardware texture
|
||||
bool CD3D9Texture::createTexture(u32 flags, IImage * image)
|
||||
{
|
||||
ImageSize = image->getDimension();
|
||||
OriginalSize = image->getDimension();
|
||||
|
||||
core::dimension2d<u32> optSize = ImageSize.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT), !Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);
|
||||
core::dimension2d<u32> optSize = OriginalSize.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT), !Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);
|
||||
|
||||
D3DFORMAT format = D3DFMT_A1R5G5B5;
|
||||
|
||||
|
@ -329,7 +346,7 @@ bool CD3D9Texture::createTexture(u32 flags, IImage * image)
|
|||
format = D3DFMT_R5G6B5;
|
||||
}
|
||||
|
||||
if(image->getColorFormat() == ECF_DXT1 || image->getColorFormat() == ECF_DXT2 || image->getColorFormat() == ECF_DXT3 || image->getColorFormat() == ECF_DXT4 || image->getColorFormat() == ECF_DXT5)
|
||||
if (IImage::isCompressedFormat(image->getColorFormat()))
|
||||
{
|
||||
ColorFormat = image->getColorFormat();
|
||||
|
||||
|
@ -402,6 +419,23 @@ bool CD3D9Texture::createTexture(u32 flags, IImage * image)
|
|||
if (!IsCompressed)
|
||||
ColorFormat = Driver->getColorFormatFromD3DFormat(format);
|
||||
|
||||
switch (ColorFormat)
|
||||
{
|
||||
case ECF_A8R8G8B8:
|
||||
case ECF_A1R5G5B5:
|
||||
case ECF_DXT1:
|
||||
case ECF_DXT2:
|
||||
case ECF_DXT3:
|
||||
case ECF_DXT4:
|
||||
case ECF_DXT5:
|
||||
case ECF_A16B16G16R16F:
|
||||
case ECF_A32B32G32R32F:
|
||||
HasAlpha = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
setPitch(format);
|
||||
|
||||
return (SUCCEEDED(hr));
|
||||
|
@ -416,8 +450,8 @@ bool CD3D9Texture::copyTexture(IImage * image)
|
|||
D3DSURFACE_DESC desc;
|
||||
Texture->GetLevelDesc(0, &desc);
|
||||
|
||||
TextureSize.Width = desc.Width;
|
||||
TextureSize.Height = desc.Height;
|
||||
Size.Width = desc.Width;
|
||||
Size.Height = desc.Height;
|
||||
|
||||
D3DLOCKED_RECT rect;
|
||||
HRESULT hr = Texture->LockRect(0, &rect, 0, 0);
|
||||
|
@ -432,16 +466,16 @@ bool CD3D9Texture::copyTexture(IImage * image)
|
|||
u32 compressedDataSize = 0;
|
||||
|
||||
if(ColorFormat == ECF_DXT1)
|
||||
compressedDataSize = ((TextureSize.Width + 3) / 4) * ((TextureSize.Height + 3) / 4) * 8;
|
||||
compressedDataSize = ((Size.Width + 3) / 4) * ((Size.Height + 3) / 4) * 8;
|
||||
else if (ColorFormat == ECF_DXT2 || ColorFormat == ECF_DXT3 || ColorFormat == ECF_DXT4 || ColorFormat == ECF_DXT5)
|
||||
compressedDataSize = ((TextureSize.Width + 3) / 4) * ((TextureSize.Height + 3) / 4) * 16;
|
||||
compressedDataSize = ((Size.Width + 3) / 4) * ((Size.Height + 3) / 4) * 16;
|
||||
|
||||
memcpy(rect.pBits, image->lock(), compressedDataSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
Pitch = rect.Pitch;
|
||||
image->copyToScaling(rect.pBits, TextureSize.Width, TextureSize.Height, ColorFormat, Pitch);
|
||||
image->copyToScaling(rect.pBits, Size.Width, Size.Height, ColorFormat, Pitch);
|
||||
}
|
||||
|
||||
hr = Texture->UnlockRect(0);
|
||||
|
@ -533,41 +567,6 @@ void CD3D9Texture::unlock()
|
|||
}
|
||||
|
||||
|
||||
//! Returns original size of the texture.
|
||||
const core::dimension2d<u32>& CD3D9Texture::getOriginalSize() const
|
||||
{
|
||||
return ImageSize;
|
||||
}
|
||||
|
||||
|
||||
//! Returns (=size) of the texture.
|
||||
const core::dimension2d<u32>& CD3D9Texture::getSize() const
|
||||
{
|
||||
return TextureSize;
|
||||
}
|
||||
|
||||
|
||||
//! returns driver type of texture (=the driver, who created the texture)
|
||||
E_DRIVER_TYPE CD3D9Texture::getDriverType() const
|
||||
{
|
||||
return EDT_DIRECT3D9;
|
||||
}
|
||||
|
||||
|
||||
//! returns color format of texture
|
||||
ECOLOR_FORMAT CD3D9Texture::getColorFormat() const
|
||||
{
|
||||
return ColorFormat;
|
||||
}
|
||||
|
||||
|
||||
//! returns pitch of texture (in bytes)
|
||||
u32 CD3D9Texture::getPitch() const
|
||||
{
|
||||
return Pitch;
|
||||
}
|
||||
|
||||
|
||||
//! returns the DIRECT3D9 Texture
|
||||
IDirect3DBaseTexture9* CD3D9Texture::getDX9Texture() const
|
||||
{
|
||||
|
@ -575,13 +574,6 @@ IDirect3DBaseTexture9* CD3D9Texture::getDX9Texture() const
|
|||
}
|
||||
|
||||
|
||||
//! returns if texture has mipmap levels
|
||||
bool CD3D9Texture::hasMipMaps() const
|
||||
{
|
||||
return HasMipMaps;
|
||||
}
|
||||
|
||||
|
||||
void CD3D9Texture::copy16BitMipMap(char* src, char* tgt,
|
||||
const s32 srcWidth, const s32 srcHeight,
|
||||
const s32 width, const s32 height,
|
||||
|
@ -687,7 +679,7 @@ void CD3D9Texture::regenerateMipMapLevels(void* mipmapData)
|
|||
if (mipmapData)
|
||||
{
|
||||
u32 compressedDataSize = 0;
|
||||
core::dimension2du size = TextureSize;
|
||||
core::dimension2du size = Size;
|
||||
u32 level=0;
|
||||
do
|
||||
{
|
||||
|
@ -728,8 +720,8 @@ void CD3D9Texture::regenerateMipMapLevels(void* mipmapData)
|
|||
}
|
||||
else
|
||||
{
|
||||
memcpy(miplr.pBits, mipmapData, size.getArea()*getPitch()/TextureSize.Width);
|
||||
mipmapData = (u8*)mipmapData+size.getArea()*getPitch()/TextureSize.Width;
|
||||
memcpy(miplr.pBits, mipmapData, size.getArea()*getPitch() / Size.Width);
|
||||
mipmapData = (u8*)mipmapData + size.getArea()*getPitch() / Size.Width;
|
||||
}
|
||||
|
||||
// unlock
|
||||
|
@ -753,13 +745,6 @@ void CD3D9Texture::regenerateMipMapLevels(void* mipmapData)
|
|||
}
|
||||
|
||||
|
||||
//! returns if it is a render target
|
||||
bool CD3D9Texture::isRenderTarget() const
|
||||
{
|
||||
return IsRenderTarget;
|
||||
}
|
||||
|
||||
|
||||
//! Returns pointer to the render target surface
|
||||
IDirect3DSurface9* CD3D9Texture::getRenderTargetSurface()
|
||||
{
|
||||
|
@ -783,27 +768,27 @@ void CD3D9Texture::setPitch(D3DFORMAT d3dformat)
|
|||
{
|
||||
case D3DFMT_X1R5G5B5:
|
||||
case D3DFMT_A1R5G5B5:
|
||||
Pitch = TextureSize.Width * 2;
|
||||
Pitch = Size.Width * 2;
|
||||
break;
|
||||
case D3DFMT_A8B8G8R8:
|
||||
case D3DFMT_A8R8G8B8:
|
||||
case D3DFMT_X8R8G8B8:
|
||||
Pitch = TextureSize.Width * 4;
|
||||
Pitch = Size.Width * 4;
|
||||
break;
|
||||
case D3DFMT_R5G6B5:
|
||||
Pitch = TextureSize.Width * 2;
|
||||
Pitch = Size.Width * 2;
|
||||
break;
|
||||
case D3DFMT_R8G8B8:
|
||||
Pitch = TextureSize.Width * 3;
|
||||
Pitch = Size.Width * 3;
|
||||
break;
|
||||
case D3DFMT_DXT1:
|
||||
Pitch = TextureSize.Width * 2;
|
||||
Pitch = Size.Width * 2;
|
||||
break;
|
||||
case D3DFMT_DXT2:
|
||||
case D3DFMT_DXT3:
|
||||
case D3DFMT_DXT4:
|
||||
case D3DFMT_DXT5:
|
||||
Pitch = TextureSize.Width * 4;
|
||||
Pitch = Size.Width * 4;
|
||||
default:
|
||||
Pitch = 0;
|
||||
};
|
||||
|
|
|
@ -47,34 +47,13 @@ public:
|
|||
//! unlock function
|
||||
virtual void unlock() _IRR_OVERRIDE_;
|
||||
|
||||
//! Returns original size of the texture.
|
||||
virtual const core::dimension2d<u32>& getOriginalSize() const _IRR_OVERRIDE_;
|
||||
|
||||
//! Returns (=size) of the texture.
|
||||
virtual const core::dimension2d<u32>& getSize() const _IRR_OVERRIDE_;
|
||||
|
||||
//! returns driver type of texture (=the driver, who created the texture)
|
||||
virtual E_DRIVER_TYPE getDriverType() const _IRR_OVERRIDE_;
|
||||
|
||||
//! returns color format of texture
|
||||
virtual ECOLOR_FORMAT getColorFormat() const _IRR_OVERRIDE_;
|
||||
|
||||
//! returns pitch of texture (in bytes)
|
||||
virtual u32 getPitch() const _IRR_OVERRIDE_;
|
||||
//! Regenerates the mip map levels of the texture. Useful after locking and
|
||||
//! modifying the texture
|
||||
virtual void regenerateMipMapLevels(void* mipmapData = 0) _IRR_OVERRIDE_;
|
||||
|
||||
//! returns the DIRECT3D9 Texture
|
||||
IDirect3DBaseTexture9* getDX9Texture() const;
|
||||
|
||||
//! returns if texture has mipmap levels
|
||||
bool hasMipMaps() const;
|
||||
|
||||
//! Regenerates the mip map levels of the texture. Useful after locking and
|
||||
//! modifying the texture
|
||||
virtual void regenerateMipMapLevels(void* mipmapData=0) _IRR_OVERRIDE_;
|
||||
|
||||
//! returns if it is a render target
|
||||
virtual bool isRenderTarget() const _IRR_OVERRIDE_;
|
||||
|
||||
//! Returns pointer to the render target surface
|
||||
IDirect3DSurface9* getRenderTargetSurface();
|
||||
|
||||
|
@ -112,15 +91,9 @@ private:
|
|||
IDirect3DSurface9* RTTSurface;
|
||||
CD3D9Driver* Driver;
|
||||
SDepthSurface* DepthSurface;
|
||||
core::dimension2d<u32> TextureSize;
|
||||
core::dimension2d<u32> ImageSize;
|
||||
s32 Pitch;
|
||||
u32 MipLevelLocked;
|
||||
ECOLOR_FORMAT ColorFormat;
|
||||
|
||||
bool HasMipMaps;
|
||||
bool HardwareMipMaps;
|
||||
bool IsRenderTarget;
|
||||
bool IsCompressed;
|
||||
};
|
||||
|
||||
|
|
|
@ -731,17 +731,11 @@ namespace video
|
|||
|
||||
struct SDummyTexture : public ITexture
|
||||
{
|
||||
SDummyTexture(const io::path& name) : ITexture(name), size(0,0) {};
|
||||
SDummyTexture(const io::path& name) : ITexture(name) {};
|
||||
|
||||
virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0) _IRR_OVERRIDE_ { return 0; }
|
||||
virtual void unlock()_IRR_OVERRIDE_ {}
|
||||
virtual const core::dimension2d<u32>& getOriginalSize() const _IRR_OVERRIDE_ { return size; }
|
||||
virtual const core::dimension2d<u32>& getSize() const _IRR_OVERRIDE_ { return size; }
|
||||
virtual E_DRIVER_TYPE getDriverType() const _IRR_OVERRIDE_ { return video::EDT_NULL; }
|
||||
virtual ECOLOR_FORMAT getColorFormat() const _IRR_OVERRIDE_ { return video::ECF_A1R5G5B5; }
|
||||
virtual u32 getPitch() const _IRR_OVERRIDE_ { return 0; }
|
||||
virtual void regenerateMipMapLevels(void* mipmapData=0) _IRR_OVERRIDE_ {}
|
||||
core::dimension2d<u32> size;
|
||||
};
|
||||
core::array<SSurface> Textures;
|
||||
|
||||
|
|
|
@ -21,28 +21,49 @@ namespace video
|
|||
|
||||
//! constructor for usual textures
|
||||
COpenGLTexture::COpenGLTexture(IImage* origImage, const io::path& name, void* mipmapData, COpenGLDriver* driver)
|
||||
: ITexture(name), ColorFormat(ECF_A8R8G8B8), Driver(driver), Image(0), MipImage(0),
|
||||
: ITexture(name), Driver(driver), Image(0), MipImage(0),
|
||||
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT),
|
||||
PixelType(GL_UNSIGNED_BYTE), MipLevelStored(0), MipmapLegacyMode(true),
|
||||
IsRenderTarget(false), IsCompressed(false), AutomaticMipmapUpdate(false),
|
||||
IsCompressed(false), AutomaticMipmapUpdate(false),
|
||||
ReadOnlyLock(false), KeepImage(true), IsDepthTexture(false), IsRenderBuffer(false)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("COpenGLTexture");
|
||||
#endif
|
||||
|
||||
DriverType = EDT_OPENGL;
|
||||
ColorFormat = ECF_A8R8G8B8;
|
||||
HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
|
||||
IsRenderTarget = false;
|
||||
|
||||
getImageValues(origImage);
|
||||
|
||||
if (ColorFormat == ECF_DXT1 || ColorFormat == ECF_DXT2 || ColorFormat == ECF_DXT3 || ColorFormat == ECF_DXT4 || ColorFormat == ECF_DXT5)
|
||||
switch (ColorFormat)
|
||||
{
|
||||
if(!Driver->queryFeature(EVDF_TEXTURE_COMPRESSED_DXT))
|
||||
case ECF_A8R8G8B8:
|
||||
case ECF_A1R5G5B5:
|
||||
case ECF_DXT1:
|
||||
case ECF_DXT2:
|
||||
case ECF_DXT3:
|
||||
case ECF_DXT4:
|
||||
case ECF_DXT5:
|
||||
case ECF_A16B16G16R16F:
|
||||
case ECF_A32B32G32R32F:
|
||||
HasAlpha = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (IImage::isCompressedFormat(ColorFormat))
|
||||
{
|
||||
if (!Driver->queryFeature(EVDF_TEXTURE_COMPRESSED_DXT))
|
||||
{
|
||||
os::Printer::log("DXT texture compression not available.", ELL_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if(ImageSize != TextureSize)
|
||||
if (OriginalSize != Size)
|
||||
{
|
||||
os::Printer::log("Invalid size of image for compressed texture, size of image must be POT.", ELL_ERROR);
|
||||
return;
|
||||
|
@ -55,17 +76,20 @@ COpenGLTexture::COpenGLTexture(IImage* origImage, const io::path& name, void* mi
|
|||
KeepImage = false;
|
||||
}
|
||||
}
|
||||
else if (ImageSize==TextureSize)
|
||||
else if (OriginalSize == Size)
|
||||
{
|
||||
Image = Driver->createImage(ColorFormat, ImageSize);
|
||||
Image = Driver->createImage(ColorFormat, OriginalSize);
|
||||
origImage->copyTo(Image);
|
||||
}
|
||||
else
|
||||
{
|
||||
Image = Driver->createImage(ColorFormat, TextureSize);
|
||||
Image = Driver->createImage(ColorFormat, Size);
|
||||
// scale texture
|
||||
origImage->copyToScaling(Image);
|
||||
}
|
||||
|
||||
Pitch = Image->getPitch();
|
||||
|
||||
glGenTextures(1, &TextureName);
|
||||
uploadTexture(true, mipmapData);
|
||||
if (!KeepImage)
|
||||
|
@ -78,16 +102,21 @@ COpenGLTexture::COpenGLTexture(IImage* origImage, const io::path& name, void* mi
|
|||
|
||||
//! constructor for basic setup (only for derived classes)
|
||||
COpenGLTexture::COpenGLTexture(const io::path& name, COpenGLDriver* driver)
|
||||
: ITexture(name), ColorFormat(ECF_A8R8G8B8), Driver(driver), Image(0), MipImage(0),
|
||||
: ITexture(name), Driver(driver), Image(0), MipImage(0),
|
||||
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT),
|
||||
PixelType(GL_UNSIGNED_BYTE), MipLevelStored(0), HasMipMaps(true),
|
||||
MipmapLegacyMode(true), IsRenderTarget(false), IsCompressed(false),
|
||||
PixelType(GL_UNSIGNED_BYTE), MipLevelStored(0),
|
||||
MipmapLegacyMode(true), IsCompressed(false),
|
||||
AutomaticMipmapUpdate(false), ReadOnlyLock(false), KeepImage(true),
|
||||
IsDepthTexture(false), IsRenderBuffer(false)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("COpenGLTexture");
|
||||
#endif
|
||||
|
||||
DriverType = EDT_OPENGL;
|
||||
ColorFormat = ECF_A8R8G8B8;
|
||||
HasMipMaps = true;
|
||||
HasAlpha = true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -368,28 +397,30 @@ void COpenGLTexture::getImageValues(IImage* image)
|
|||
return;
|
||||
}
|
||||
|
||||
ImageSize = image->getDimension();
|
||||
OriginalSize = image->getDimension();
|
||||
|
||||
if ( !ImageSize.Width || !ImageSize.Height)
|
||||
if (!OriginalSize.Width || !OriginalSize.Height)
|
||||
{
|
||||
os::Printer::log("Invalid size of image for OpenGL Texture.", ELL_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
const f32 ratio = (f32)ImageSize.Width/(f32)ImageSize.Height;
|
||||
if ((ImageSize.Width>Driver->MaxTextureSize) && (ratio >= 1.0f))
|
||||
{
|
||||
ImageSize.Width = Driver->MaxTextureSize;
|
||||
ImageSize.Height = (u32)(Driver->MaxTextureSize/ratio);
|
||||
}
|
||||
else if (ImageSize.Height>Driver->MaxTextureSize)
|
||||
{
|
||||
ImageSize.Height = Driver->MaxTextureSize;
|
||||
ImageSize.Width = (u32)(Driver->MaxTextureSize*ratio);
|
||||
}
|
||||
TextureSize=ImageSize.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT));
|
||||
const f32 ratio = (f32)OriginalSize.Width / (f32)OriginalSize.Height;
|
||||
|
||||
if(image->getColorFormat() == ECF_DXT1 || image->getColorFormat() == ECF_DXT2 || image->getColorFormat() == ECF_DXT3 || image->getColorFormat() == ECF_DXT4 || image->getColorFormat() == ECF_DXT5)
|
||||
if ((OriginalSize.Width>Driver->MaxTextureSize) && (ratio >= 1.0f))
|
||||
{
|
||||
OriginalSize.Width = Driver->MaxTextureSize;
|
||||
OriginalSize.Height = (u32)(Driver->MaxTextureSize / ratio);
|
||||
}
|
||||
else if (OriginalSize.Height>Driver->MaxTextureSize)
|
||||
{
|
||||
OriginalSize.Height = Driver->MaxTextureSize;
|
||||
OriginalSize.Width = (u32)(Driver->MaxTextureSize*ratio);
|
||||
}
|
||||
|
||||
Size = OriginalSize.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT));
|
||||
|
||||
if (IImage::isCompressedFormat(image->getColorFormat()))
|
||||
ColorFormat = image->getColorFormat();
|
||||
else
|
||||
ColorFormat = getBestColorFormat(image->getColorFormat());
|
||||
|
@ -563,8 +594,8 @@ void* COpenGLTexture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
|
|||
if (mipmapLevel)
|
||||
{
|
||||
u32 i=0;
|
||||
u32 width = TextureSize.Width;
|
||||
u32 height = TextureSize.Height;
|
||||
u32 width = Size.Width;
|
||||
u32 height = Size.Height;
|
||||
do
|
||||
{
|
||||
if (width>1)
|
||||
|
@ -577,7 +608,7 @@ void* COpenGLTexture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
|
|||
MipImage = image = Driver->createImage(ECF_A8R8G8B8, core::dimension2du(width,height));
|
||||
}
|
||||
else
|
||||
Image = image = Driver->createImage(ECF_A8R8G8B8, ImageSize);
|
||||
Image = image = Driver->createImage(ECF_A8R8G8B8, OriginalSize);
|
||||
ColorFormat = ECF_A8R8G8B8;
|
||||
}
|
||||
if (!image)
|
||||
|
@ -675,44 +706,6 @@ void COpenGLTexture::unlock()
|
|||
}
|
||||
|
||||
|
||||
//! Returns size of the original image.
|
||||
const core::dimension2d<u32>& COpenGLTexture::getOriginalSize() const
|
||||
{
|
||||
return ImageSize;
|
||||
}
|
||||
|
||||
|
||||
//! Returns size of the texture.
|
||||
const core::dimension2d<u32>& COpenGLTexture::getSize() const
|
||||
{
|
||||
return TextureSize;
|
||||
}
|
||||
|
||||
|
||||
//! returns driver type of texture, i.e. the driver, which created the texture
|
||||
E_DRIVER_TYPE COpenGLTexture::getDriverType() const
|
||||
{
|
||||
return EDT_OPENGL;
|
||||
}
|
||||
|
||||
|
||||
//! returns color format of texture
|
||||
ECOLOR_FORMAT COpenGLTexture::getColorFormat() const
|
||||
{
|
||||
return ColorFormat;
|
||||
}
|
||||
|
||||
|
||||
//! returns pitch of texture (in bytes)
|
||||
u32 COpenGLTexture::getPitch() const
|
||||
{
|
||||
if (Image)
|
||||
return Image->getPitch();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//! return open gl texture name
|
||||
GLuint COpenGLTexture::getOpenGLTextureName() const
|
||||
{
|
||||
|
@ -720,13 +713,6 @@ GLuint COpenGLTexture::getOpenGLTextureName() const
|
|||
}
|
||||
|
||||
|
||||
//! Returns whether this texture has mipmaps
|
||||
bool COpenGLTexture::hasMipMaps() const
|
||||
{
|
||||
return HasMipMaps;
|
||||
}
|
||||
|
||||
|
||||
//! Regenerates the mip map levels of the texture. Useful after locking and
|
||||
//! modifying the texture
|
||||
void COpenGLTexture::regenerateMipMapLevels(void* mipmapData)
|
||||
|
@ -814,12 +800,6 @@ void COpenGLTexture::regenerateMipMapLevels(void* mipmapData)
|
|||
}
|
||||
|
||||
|
||||
bool COpenGLTexture::isRenderTarget() const
|
||||
{
|
||||
return IsRenderTarget;
|
||||
}
|
||||
|
||||
|
||||
void COpenGLTexture::setIsRenderTarget(bool isTarget)
|
||||
{
|
||||
IsRenderTarget = isTarget;
|
||||
|
@ -883,15 +863,29 @@ COpenGLFBOTexture::COpenGLFBOTexture(const core::dimension2d<u32>& size,
|
|||
setDebugName("COpenGLFBOTexture");
|
||||
#endif
|
||||
|
||||
DriverType = EDT_OPENGL;
|
||||
|
||||
if (ECF_UNKNOWN == format)
|
||||
format = getBestColorFormat(driver->getColorFormat());
|
||||
|
||||
IsDepthTexture = IImage::isDepthFormat(format);
|
||||
|
||||
ImageSize = size;
|
||||
TextureSize = size;
|
||||
OriginalSize = size;
|
||||
Size = size;
|
||||
ColorFormat = format;
|
||||
|
||||
switch (ColorFormat)
|
||||
{
|
||||
case ECF_A8R8G8B8:
|
||||
case ECF_A1R5G5B5:
|
||||
case ECF_A16B16G16R16F:
|
||||
case ECF_A32B32G32R32F:
|
||||
HasAlpha = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
GLint FilteringType = 0;
|
||||
InternalFormat = getOpenGLFormatAndParametersFromColorFormat(format, FilteringType, PixelFormat, PixelType);
|
||||
|
||||
|
@ -917,7 +911,7 @@ COpenGLFBOTexture::COpenGLFBOTexture(const core::dimension2d<u32>& size,
|
|||
StatesCache.WrapU = ETC_CLAMP_TO_EDGE;
|
||||
StatesCache.WrapV = ETC_CLAMP_TO_EDGE;
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, ImageSize.Width, ImageSize.Height, 0, PixelFormat, PixelType, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, OriginalSize.Width, OriginalSize.Height, 0, PixelFormat, PixelType, 0);
|
||||
|
||||
Driver->setActiveTexture(0, 0);
|
||||
Driver->getBridgeCalls()->setTexture(0, true);
|
||||
|
@ -1071,11 +1065,13 @@ COpenGLRenderBuffer::COpenGLRenderBuffer(
|
|||
setDebugName("COpenGLRenderBuffer");
|
||||
#endif
|
||||
|
||||
DriverType = EDT_OPENGL;
|
||||
|
||||
IsDepthTexture = true;
|
||||
IsRenderBuffer = true;
|
||||
|
||||
ImageSize = size;
|
||||
TextureSize = size;
|
||||
OriginalSize = size;
|
||||
Size = size;
|
||||
InternalFormat = GL_RGBA;
|
||||
PixelFormat = GL_RGBA;
|
||||
PixelType = GL_UNSIGNED_BYTE;
|
||||
|
@ -1085,7 +1081,7 @@ COpenGLRenderBuffer::COpenGLRenderBuffer(
|
|||
// generate depth buffer
|
||||
Driver->extGlGenRenderbuffers(1, &BufferID);
|
||||
Driver->extGlBindRenderbuffer(GL_RENDERBUFFER_EXT, BufferID);
|
||||
Driver->extGlRenderbufferStorage(GL_RENDERBUFFER_EXT, Driver->getZBufferBits(), ImageSize.Width, ImageSize.Height);
|
||||
Driver->extGlRenderbufferStorage(GL_RENDERBUFFER_EXT, Driver->getZBufferBits(), OriginalSize.Width, OriginalSize.Height);
|
||||
Driver->extGlBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -84,34 +84,13 @@ public:
|
|||
//! unlock function
|
||||
virtual void unlock() _IRR_OVERRIDE_;
|
||||
|
||||
//! Returns original size of the texture (image).
|
||||
virtual const core::dimension2d<u32>& getOriginalSize() const _IRR_OVERRIDE_;
|
||||
|
||||
//! Returns size of the texture.
|
||||
virtual const core::dimension2d<u32>& getSize() const _IRR_OVERRIDE_;
|
||||
|
||||
//! returns driver type of texture (=the driver, that created it)
|
||||
virtual E_DRIVER_TYPE getDriverType() const _IRR_OVERRIDE_;
|
||||
|
||||
//! returns color format of texture
|
||||
virtual ECOLOR_FORMAT getColorFormat() const _IRR_OVERRIDE_;
|
||||
|
||||
//! returns pitch of texture (in bytes)
|
||||
virtual u32 getPitch() const _IRR_OVERRIDE_;
|
||||
|
||||
//! return open gl texture name
|
||||
GLuint getOpenGLTextureName() const;
|
||||
|
||||
//! return whether this texture has mipmaps
|
||||
virtual bool hasMipMaps() const _IRR_OVERRIDE_;
|
||||
|
||||
//! Regenerates the mip map levels of the texture.
|
||||
/** Useful after locking and modifying the texture
|
||||
\param mipmapData Pointer to raw mipmap data, including all necessary mip levels, in the same format as the main texture image. If not set the mipmaps are derived from the main image. */
|
||||
virtual void regenerateMipMapLevels(void* mipmapData=0) _IRR_OVERRIDE_;
|
||||
virtual void regenerateMipMapLevels(void* mipmapData = 0) _IRR_OVERRIDE_;
|
||||
|
||||
//! Is it a render target?
|
||||
virtual bool isRenderTarget() const _IRR_OVERRIDE_;
|
||||
//! return open gl texture name
|
||||
GLuint getOpenGLTextureName() const;
|
||||
|
||||
//! Is it a FrameBufferObject?
|
||||
virtual bool isFrameBufferObject() const;
|
||||
|
@ -155,9 +134,6 @@ protected:
|
|||
\param mipLevel If set to non-zero, only that specific miplevel is updated, using the MipImage member. */
|
||||
void uploadTexture(bool newTexture=false, void* mipmapData=0, u32 mipLevel=0);
|
||||
|
||||
core::dimension2d<u32> ImageSize;
|
||||
core::dimension2d<u32> TextureSize;
|
||||
ECOLOR_FORMAT ColorFormat;
|
||||
COpenGLDriver* Driver;
|
||||
IImage* Image;
|
||||
IImage* MipImage;
|
||||
|
@ -168,9 +144,7 @@ protected:
|
|||
GLenum PixelType;
|
||||
|
||||
u8 MipLevelStored;
|
||||
bool HasMipMaps;
|
||||
bool MipmapLegacyMode;
|
||||
bool IsRenderTarget;
|
||||
bool IsCompressed;
|
||||
bool AutomaticMipmapUpdate;
|
||||
bool ReadOnlyLock;
|
||||
|
|
|
@ -16,31 +16,37 @@ namespace video
|
|||
//! constructor
|
||||
CSoftwareTexture::CSoftwareTexture(IImage* image, const io::path& name,
|
||||
bool renderTarget, void* mipmapData)
|
||||
: ITexture(name), Texture(0), IsRenderTarget(renderTarget)
|
||||
: ITexture(name), Texture(0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CSoftwareTexture");
|
||||
#endif
|
||||
|
||||
DriverType = EDT_SOFTWARE;
|
||||
ColorFormat = ECF_A1R5G5B5;
|
||||
HasMipMaps = false;
|
||||
HasAlpha = true;
|
||||
IsRenderTarget = renderTarget;
|
||||
|
||||
if (image)
|
||||
{
|
||||
bool IsCompressed = false;
|
||||
|
||||
if(image->getColorFormat() == ECF_DXT1 || image->getColorFormat() == ECF_DXT2 || image->getColorFormat() == ECF_DXT3 || image->getColorFormat() == ECF_DXT4 || image->getColorFormat() == ECF_DXT5)
|
||||
if(IImage::isCompressedFormat(image->getColorFormat()))
|
||||
{
|
||||
os::Printer::log("DXT texture compression not available.", ELL_ERROR);
|
||||
os::Printer::log("Texture compression not available.", ELL_ERROR);
|
||||
IsCompressed = true;
|
||||
}
|
||||
|
||||
OrigSize = image->getDimension();
|
||||
core::dimension2d<u32> optSize=OrigSize.getOptimalSize();
|
||||
OriginalSize = image->getDimension();
|
||||
core::dimension2d<u32> optSize = OriginalSize.getOptimalSize();
|
||||
|
||||
Image = new CImage(ECF_A1R5G5B5, OrigSize);
|
||||
Image = new CImage(ECF_A1R5G5B5, OriginalSize);
|
||||
|
||||
if (!IsCompressed)
|
||||
image->copyTo(Image);
|
||||
|
||||
if (optSize == OrigSize)
|
||||
if (optSize == OriginalSize)
|
||||
{
|
||||
Texture = Image;
|
||||
Texture->grab();
|
||||
|
@ -50,6 +56,9 @@ CSoftwareTexture::CSoftwareTexture(IImage* image, const io::path& name,
|
|||
Texture = new CImage(ECF_A1R5G5B5, optSize);
|
||||
Image->copyToScaling(Texture);
|
||||
}
|
||||
|
||||
Size = Texture->getDimension();
|
||||
Pitch = Texture->getDimension().Width * 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,20 +97,6 @@ void CSoftwareTexture::unlock()
|
|||
}
|
||||
|
||||
|
||||
//! Returns original size of the texture.
|
||||
const core::dimension2d<u32>& CSoftwareTexture::getOriginalSize() const
|
||||
{
|
||||
return OrigSize;
|
||||
}
|
||||
|
||||
|
||||
//! Returns (=size) of the texture.
|
||||
const core::dimension2d<u32>& CSoftwareTexture::getSize() const
|
||||
{
|
||||
return Image->getDimension();
|
||||
}
|
||||
|
||||
|
||||
//! returns unoptimized surface
|
||||
CImage* CSoftwareTexture::getImage()
|
||||
{
|
||||
|
@ -109,7 +104,6 @@ CImage* CSoftwareTexture::getImage()
|
|||
}
|
||||
|
||||
|
||||
|
||||
//! returns texture surface
|
||||
CImage* CSoftwareTexture::getTexture()
|
||||
{
|
||||
|
@ -117,30 +111,6 @@ CImage* CSoftwareTexture::getTexture()
|
|||
}
|
||||
|
||||
|
||||
|
||||
//! returns driver type of texture (=the driver, who created the texture)
|
||||
E_DRIVER_TYPE CSoftwareTexture::getDriverType() const
|
||||
{
|
||||
return EDT_SOFTWARE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! returns color format of texture
|
||||
ECOLOR_FORMAT CSoftwareTexture::getColorFormat() const
|
||||
{
|
||||
return ECF_A1R5G5B5;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! returns pitch of texture (in bytes)
|
||||
u32 CSoftwareTexture::getPitch() const
|
||||
{
|
||||
return Image->getDimension().Width * 2;
|
||||
}
|
||||
|
||||
|
||||
//! Regenerates the mip map levels of the texture. Useful after locking and
|
||||
//! modifying the texture
|
||||
void CSoftwareTexture::regenerateMipMapLevels(void* mipmapData)
|
||||
|
@ -148,11 +118,6 @@ void CSoftwareTexture::regenerateMipMapLevels(void* mipmapData)
|
|||
// our software textures don't have mip maps
|
||||
}
|
||||
|
||||
bool CSoftwareTexture::isRenderTarget() const
|
||||
{
|
||||
return IsRenderTarget;
|
||||
}
|
||||
|
||||
|
||||
} // end namespace video
|
||||
} // end namespace irr
|
||||
|
|
|
@ -33,39 +33,19 @@ public:
|
|||
//! unlock function
|
||||
virtual void unlock() _IRR_OVERRIDE_;
|
||||
|
||||
//! Returns original size of the texture.
|
||||
virtual const core::dimension2d<u32>& getOriginalSize() const _IRR_OVERRIDE_;
|
||||
|
||||
//! Returns (=size) of the texture.
|
||||
virtual const core::dimension2d<u32>& getSize() const _IRR_OVERRIDE_;
|
||||
|
||||
//! returns unoptimized surface
|
||||
virtual CImage* getImage();
|
||||
|
||||
//! returns texture surface
|
||||
virtual CImage* getTexture();
|
||||
|
||||
//! returns driver type of texture (=the driver, who created the texture)
|
||||
virtual E_DRIVER_TYPE getDriverType() const _IRR_OVERRIDE_;
|
||||
|
||||
//! returns color format of texture
|
||||
virtual ECOLOR_FORMAT getColorFormat() const _IRR_OVERRIDE_;
|
||||
|
||||
//! returns pitch of texture (in bytes)
|
||||
virtual u32 getPitch() const _IRR_OVERRIDE_;
|
||||
|
||||
//! Regenerates the mip map levels of the texture. Useful after locking and
|
||||
//! modifying the texture
|
||||
virtual void regenerateMipMapLevels(void* mipmapData=0) _IRR_OVERRIDE_;
|
||||
|
||||
//! is it a render target?
|
||||
virtual bool isRenderTarget() const _IRR_OVERRIDE_;
|
||||
|
||||
private:
|
||||
CImage* Image;
|
||||
CImage* Texture;
|
||||
core::dimension2d<u32> OrigSize;
|
||||
bool IsRenderTarget;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -24,9 +24,15 @@ CSoftwareTexture2::CSoftwareTexture2(IImage* image, const io::path& name,
|
|||
setDebugName("CSoftwareTexture2");
|
||||
#endif
|
||||
|
||||
#ifndef SOFTWARE_DRIVER_2_MIPMAPPING
|
||||
Flags &= ~GEN_MIPMAP;
|
||||
#endif
|
||||
#ifndef SOFTWARE_DRIVER_2_MIPMAPPING
|
||||
Flags &= ~GEN_MIPMAP;
|
||||
#endif
|
||||
|
||||
DriverType = EDT_BURNINGSVIDEO;
|
||||
ColorFormat = BURNINGSHADER_COLOR_FORMAT;
|
||||
HasMipMaps = (Flags & GEN_MIPMAP) != 0;
|
||||
HasAlpha = (Flags & HAS_ALPHA) != 0;
|
||||
IsRenderTarget = (Flags & IS_RENDERTARGET) != 0;
|
||||
|
||||
memset32 ( MipMap, 0, sizeof ( MipMap ) );
|
||||
|
||||
|
@ -34,13 +40,13 @@ CSoftwareTexture2::CSoftwareTexture2(IImage* image, const io::path& name,
|
|||
{
|
||||
bool IsCompressed = false;
|
||||
|
||||
if(image->getColorFormat() == ECF_DXT1 || image->getColorFormat() == ECF_DXT2 || image->getColorFormat() == ECF_DXT3 || image->getColorFormat() == ECF_DXT4 || image->getColorFormat() == ECF_DXT5)
|
||||
if (IImage::isCompressedFormat(image->getColorFormat()))
|
||||
{
|
||||
os::Printer::log("DXT texture compression not available.", ELL_ERROR);
|
||||
os::Printer::log("Texture compression not available.", ELL_ERROR);
|
||||
IsCompressed = true;
|
||||
}
|
||||
|
||||
OrigSize = image->getDimension();
|
||||
OriginalSize = image->getDimension();
|
||||
OriginalFormat = image->getColorFormat();
|
||||
|
||||
core::setbit_cond(Flags,
|
||||
|
@ -49,12 +55,12 @@ CSoftwareTexture2::CSoftwareTexture2(IImage* image, const io::path& name,
|
|||
HAS_ALPHA);
|
||||
|
||||
core::dimension2d<u32> optSize(
|
||||
OrigSize.getOptimalSize( 0 != ( Flags & NP2_SIZE ),
|
||||
OriginalSize.getOptimalSize(0 != (Flags & NP2_SIZE),
|
||||
false, false,
|
||||
( Flags & NP2_SIZE ) ? SOFTWARE_DRIVER_2_TEXTURE_MAXSIZE : 0)
|
||||
);
|
||||
|
||||
if ( OrigSize == optSize )
|
||||
if (OriginalSize == optSize)
|
||||
{
|
||||
MipMap[0] = new CImage(BURNINGSHADER_COLOR_FORMAT, image->getDimension());
|
||||
|
||||
|
@ -67,11 +73,11 @@ CSoftwareTexture2::CSoftwareTexture2(IImage* image, const io::path& name,
|
|||
core::stringw showName ( name );
|
||||
snprintf ( buf, 256, "Burningvideo: Warning Texture %ls reformat %dx%d -> %dx%d,%d",
|
||||
showName.c_str(),
|
||||
OrigSize.Width, OrigSize.Height, optSize.Width, optSize.Height,
|
||||
OriginalSize.Width, OriginalSize.Height, optSize.Width, optSize.Height,
|
||||
BURNINGSHADER_COLOR_FORMAT
|
||||
);
|
||||
|
||||
OrigSize = optSize;
|
||||
OriginalSize = optSize;
|
||||
os::Printer::log ( buf, ELL_WARNING );
|
||||
MipMap[0] = new CImage(BURNINGSHADER_COLOR_FORMAT, optSize);
|
||||
|
||||
|
@ -79,6 +85,9 @@ CSoftwareTexture2::CSoftwareTexture2(IImage* image, const io::path& name,
|
|||
image->copyToScalingBoxFilter ( MipMap[0],0, false );
|
||||
}
|
||||
|
||||
Size = MipMap[MipMapLOD]->getDimension();
|
||||
Pitch = MipMap[MipMapLOD]->getPitch();
|
||||
|
||||
OrigImageDataSizeInPixels = (f32) 0.3f * MipMap[0]->getImageDataSizeInPixels();
|
||||
}
|
||||
|
||||
|
@ -114,7 +123,7 @@ void CSoftwareTexture2::regenerateMipMapLevels(void* mipmapData)
|
|||
}
|
||||
|
||||
core::dimension2d<u32> newSize;
|
||||
core::dimension2d<u32> origSize=OrigSize;
|
||||
core::dimension2d<u32> origSize = OriginalSize;
|
||||
|
||||
for (i=1; i < SOFTWARE_DRIVER_2_MIPMAPPING_MAX; ++i)
|
||||
{
|
||||
|
|
|
@ -39,7 +39,12 @@ public:
|
|||
virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0) _IRR_OVERRIDE_
|
||||
{
|
||||
if (Flags & GEN_MIPMAP)
|
||||
MipMapLOD=mipmapLevel;
|
||||
{
|
||||
MipMapLOD = mipmapLevel;
|
||||
Size = MipMap[MipMapLOD]->getDimension();
|
||||
Pitch = MipMap[MipMapLOD]->getPitch();
|
||||
}
|
||||
|
||||
return MipMap[MipMapLOD]->lock();
|
||||
}
|
||||
|
||||
|
@ -49,13 +54,6 @@ public:
|
|||
MipMap[MipMapLOD]->unlock();
|
||||
}
|
||||
|
||||
//! Returns original size of the texture.
|
||||
virtual const core::dimension2d<u32>& getOriginalSize() const _IRR_OVERRIDE_
|
||||
{
|
||||
//return MipMap[0]->getDimension();
|
||||
return OrigSize;
|
||||
}
|
||||
|
||||
//! Returns the size of the largest mipmap.
|
||||
f32 getLODFactor( const f32 texArea ) const
|
||||
{
|
||||
|
@ -63,12 +61,6 @@ public:
|
|||
//return MipMap[0]->getImageDataSizeInPixels () * texArea;
|
||||
}
|
||||
|
||||
//! Returns (=size) of the texture.
|
||||
virtual const core::dimension2d<u32>& getSize() const _IRR_OVERRIDE_
|
||||
{
|
||||
return MipMap[MipMapLOD]->getDimension();
|
||||
}
|
||||
|
||||
//! returns unoptimized surface
|
||||
virtual CImage* getImage() const
|
||||
{
|
||||
|
@ -81,50 +73,12 @@ public:
|
|||
return MipMap[MipMapLOD];
|
||||
}
|
||||
|
||||
|
||||
//! returns driver type of texture (=the driver, who created the texture)
|
||||
virtual E_DRIVER_TYPE getDriverType() const _IRR_OVERRIDE_
|
||||
{
|
||||
return EDT_BURNINGSVIDEO;
|
||||
}
|
||||
|
||||
//! returns color format of texture
|
||||
virtual ECOLOR_FORMAT getColorFormat() const _IRR_OVERRIDE_
|
||||
{
|
||||
return BURNINGSHADER_COLOR_FORMAT;
|
||||
}
|
||||
|
||||
//! returns pitch of texture (in bytes)
|
||||
virtual u32 getPitch() const
|
||||
{
|
||||
return MipMap[MipMapLOD]->getPitch();
|
||||
}
|
||||
|
||||
//! Regenerates the mip map levels of the texture. Useful after locking and
|
||||
//! modifying the texture
|
||||
virtual void regenerateMipMapLevels(void* mipmapData=0) _IRR_OVERRIDE_;
|
||||
|
||||
//! support mipmaps
|
||||
virtual bool hasMipMaps() const _IRR_OVERRIDE_
|
||||
{
|
||||
return (Flags & GEN_MIPMAP ) != 0;
|
||||
}
|
||||
|
||||
//! Returns if the texture has an alpha channel
|
||||
virtual bool hasAlpha() const _IRR_OVERRIDE_
|
||||
{
|
||||
return (Flags & HAS_ALPHA ) != 0;
|
||||
}
|
||||
|
||||
//! is a render target
|
||||
virtual bool isRenderTarget() const _IRR_OVERRIDE_
|
||||
{
|
||||
return (Flags & IS_RENDERTARGET) != 0;
|
||||
}
|
||||
|
||||
private:
|
||||
f32 OrigImageDataSizeInPixels;
|
||||
core::dimension2d<u32> OrigSize;
|
||||
|
||||
CImage * MipMap[SOFTWARE_DRIVER_2_MIPMAPPING_MAX];
|
||||
|
||||
|
|
Loading…
Reference in New Issue