Commit 883ed034 authored by nadro's avatar nadro

- Removed unnecessary virtual methods in ITexture and reduced double lines of...

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