Commit 33a18192 authored by hybrid's avatar hybrid

Ensure proper texture dimensions in the D3D drivers.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2606 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 0a8836ac
...@@ -26,6 +26,8 @@ namespace video ...@@ -26,6 +26,8 @@ namespace video
{ {
class CD3D8Driver : public CNullDriver, IMaterialRendererServices class CD3D8Driver : public CNullDriver, IMaterialRendererServices
{ {
friend class CD3D8Texture;
public: public:
//! constructor //! constructor
......
...@@ -112,20 +112,11 @@ CD3D8Texture::~CD3D8Texture() ...@@ -112,20 +112,11 @@ CD3D8Texture::~CD3D8Texture()
//! creates the hardware texture //! creates the hardware texture
bool CD3D8Texture::createTexture(video::IImage* image, u32 flags) bool CD3D8Texture::createTexture(video::IImage* image, u32 flags)
{ {
core::dimension2d<u32> optSize;
ImageSize = image->getDimension(); ImageSize = image->getDimension();
if (Driver->queryFeature(EVDF_TEXTURE_NPOT)) core::dimension2d<u32> optSize = ImageSize.getOptimalSize(Driver->queryFeature(EVDF_TEXTURE_NPOT), Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);
optSize=ImageSize;
else
{
optSize.Width = getTextureSizeFromSurfaceSize(ImageSize.Width);
optSize.Height = getTextureSizeFromSurfaceSize(ImageSize.Height);
}
HRESULT hr;
D3DFORMAT format = D3DFMT_A1R5G5B5; D3DFORMAT format = D3DFMT_A1R5G5B5;
switch(getTextureFormatFromFlags(flags)) switch(getTextureFormatFromFlags(flags))
{ {
case ETCF_ALWAYS_16_BIT: case ETCF_ALWAYS_16_BIT:
...@@ -165,7 +156,7 @@ bool CD3D8Texture::createTexture(video::IImage* image, u32 flags) ...@@ -165,7 +156,7 @@ bool CD3D8Texture::createTexture(video::IImage* image, u32 flags)
const bool mipmaps = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); const bool mipmaps = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
hr = Device->CreateTexture(optSize.Width, optSize.Height, HRESULT hr = Device->CreateTexture(optSize.Width, optSize.Height,
mipmaps ? 0 : 1, // number of mipmaplevels (0 = automatic all) mipmaps ? 0 : 1, // number of mipmaplevels (0 = automatic all)
0, format, D3DPOOL_MANAGED, &Texture); 0, format, D3DPOOL_MANAGED, &Texture);
...@@ -313,18 +304,6 @@ const core::dimension2d<u32>& CD3D8Texture::getSize() const ...@@ -313,18 +304,6 @@ const core::dimension2d<u32>& CD3D8Texture::getSize() const
} }
//! returns the size of a texture which would be the optimize size for rendering it
inline s32 CD3D8Texture::getTextureSizeFromSurfaceSize(s32 size) const
{
s32 ts = 0x01;
while(ts < size)
ts <<= 1;
return ts;
}
//! returns driver type of texture (=the driver, who created the texture) //! returns driver type of texture (=the driver, who created the texture)
E_DRIVER_TYPE CD3D8Texture::getDriverType() const E_DRIVER_TYPE CD3D8Texture::getDriverType() const
{ {
...@@ -332,7 +311,6 @@ E_DRIVER_TYPE CD3D8Texture::getDriverType() const ...@@ -332,7 +311,6 @@ E_DRIVER_TYPE CD3D8Texture::getDriverType() const
} }
//! returns color format of texture //! returns color format of texture
ECOLOR_FORMAT CD3D8Texture::getColorFormat() const ECOLOR_FORMAT CD3D8Texture::getColorFormat() const
{ {
...@@ -340,7 +318,6 @@ ECOLOR_FORMAT CD3D8Texture::getColorFormat() const ...@@ -340,7 +318,6 @@ ECOLOR_FORMAT CD3D8Texture::getColorFormat() const
} }
//! returns pitch of texture (in bytes) //! returns pitch of texture (in bytes)
u32 CD3D8Texture::getPitch() const u32 CD3D8Texture::getPitch() const
{ {
...@@ -348,7 +325,6 @@ u32 CD3D8Texture::getPitch() const ...@@ -348,7 +325,6 @@ u32 CD3D8Texture::getPitch() const
} }
//! returns the DIRECT3D8 Texture //! returns the DIRECT3D8 Texture
IDirect3DTexture8* CD3D8Texture::getDX8Texture() const IDirect3DTexture8* CD3D8Texture::getDX8Texture() const
{ {
...@@ -561,11 +537,9 @@ void CD3D8Texture::copy32BitMipMap(char* src, char* tgt, ...@@ -561,11 +537,9 @@ void CD3D8Texture::copy32BitMipMap(char* src, char* tgt,
} }
void CD3D8Texture::createRenderTarget() void CD3D8Texture::createRenderTarget()
{ {
TextureSize.Width = getTextureSizeFromSurfaceSize(TextureSize.Width); TextureSize = TextureSize.getOptimalSize(Driver->queryFeature(EVDF_TEXTURE_NPOT), Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);
TextureSize.Height = getTextureSizeFromSurfaceSize(TextureSize.Height);
// get backbuffer format to create the render target in the // get backbuffer format to create the render target in the
// same format // same format
...@@ -611,7 +585,6 @@ void CD3D8Texture::createRenderTarget() ...@@ -611,7 +585,6 @@ void CD3D8Texture::createRenderTarget()
} }
//! 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 CD3D8Texture::regenerateMipMapLevels() void CD3D8Texture::regenerateMipMapLevels()
...@@ -627,6 +600,7 @@ bool CD3D8Texture::isRenderTarget() const ...@@ -627,6 +600,7 @@ bool CD3D8Texture::isRenderTarget() const
return IsRenderTarget; return IsRenderTarget;
} }
//! Returns pointer to the render target surface //! Returns pointer to the render target surface
IDirect3DSurface8* CD3D8Texture::getRenderTargetSurface() IDirect3DSurface8* CD3D8Texture::getRenderTargetSurface()
{ {
......
...@@ -79,9 +79,6 @@ private: ...@@ -79,9 +79,6 @@ private:
void createRenderTarget(); void createRenderTarget();
//! returns the size of a texture which would be the optimize size for rendering it
inline s32 getTextureSizeFromSurfaceSize(s32 size) const;
//! creates the hardware texture //! creates the hardware texture
bool createTexture(IImage* Image, u32 flags); bool createTexture(IImage* Image, u32 flags);
......
...@@ -44,6 +44,8 @@ namespace video ...@@ -44,6 +44,8 @@ namespace video
{ {
public: public:
friend class CD3D9Texture;
//! constructor //! constructor
CD3D9Driver(const core::dimension2d<u32>& screenSize, HWND window, bool fullscreen, CD3D9Driver(const core::dimension2d<u32>& screenSize, HWND window, bool fullscreen,
bool stencibuffer, io::IFileSystem* io, bool pureSoftware=false); bool stencibuffer, io::IFileSystem* io, bool pureSoftware=false);
......
...@@ -121,11 +121,10 @@ void CD3D9Texture::createRenderTarget(const ECOLOR_FORMAT format) ...@@ -121,11 +121,10 @@ 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))
{ {
TextureSize.Width = getTextureSizeFromSurfaceSize(TextureSize.Width);
TextureSize.Height = getTextureSizeFromSurfaceSize(TextureSize.Height);
if (TextureSize != ImageSize) if (TextureSize != ImageSize)
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);
D3DFORMAT d3dformat = Driver->getD3DColorFormat(); D3DFORMAT d3dformat = Driver->getD3DColorFormat();
...@@ -278,18 +277,10 @@ bool CD3D9Texture::createMipMaps(u32 level) ...@@ -278,18 +277,10 @@ 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)
{ {
core::dimension2d<u32> optSize;
ImageSize = image->getDimension(); ImageSize = image->getDimension();
if (Driver->queryFeature(EVDF_TEXTURE_NPOT)) core::dimension2d<u32> optSize = ImageSize.getOptimalSize(Driver->queryFeature(EVDF_TEXTURE_NPOT), Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);
optSize=ImageSize;
else
{
optSize.Width = getTextureSizeFromSurfaceSize(ImageSize.Width);
optSize.Height = getTextureSizeFromSurfaceSize(ImageSize.Height);
}
HRESULT hr;
D3DFORMAT format = D3DFMT_A1R5G5B5; D3DFORMAT format = D3DFMT_A1R5G5B5;
switch(getTextureFormatFromFlags(flags)) switch(getTextureFormatFromFlags(flags))
...@@ -343,7 +334,7 @@ bool CD3D9Texture::createTexture(u32 flags, IImage * image) ...@@ -343,7 +334,7 @@ bool CD3D9Texture::createTexture(u32 flags, IImage * image)
} }
} }
hr = Device->CreateTexture(optSize.Width, optSize.Height, HRESULT hr = Device->CreateTexture(optSize.Width, optSize.Height,
mipmaps ? 0 : 1, // number of mipmaplevels (0 = automatic all) mipmaps ? 0 : 1, // number of mipmaplevels (0 = automatic all)
usage, // usage usage, // usage
format, D3DPOOL_MANAGED , &Texture, NULL); format, D3DPOOL_MANAGED , &Texture, NULL);
...@@ -489,19 +480,6 @@ const core::dimension2d<u32>& CD3D9Texture::getSize() const ...@@ -489,19 +480,6 @@ const core::dimension2d<u32>& CD3D9Texture::getSize() const
} }
//! returns the size of a texture which would be the optimize size for rendering it
inline s32 CD3D9Texture::getTextureSizeFromSurfaceSize(s32 size) const
{
s32 ts = 0x01;
while(ts < size)
ts <<= 1;
return ts;
}
//! returns driver type of texture (=the driver, who created the texture) //! returns driver type of texture (=the driver, who created the texture)
E_DRIVER_TYPE CD3D9Texture::getDriverType() const E_DRIVER_TYPE CD3D9Texture::getDriverType() const
{ {
...@@ -509,7 +487,6 @@ E_DRIVER_TYPE CD3D9Texture::getDriverType() const ...@@ -509,7 +487,6 @@ E_DRIVER_TYPE CD3D9Texture::getDriverType() const
} }
//! returns color format of texture //! returns color format of texture
ECOLOR_FORMAT CD3D9Texture::getColorFormat() const ECOLOR_FORMAT CD3D9Texture::getColorFormat() const
{ {
...@@ -517,7 +494,6 @@ ECOLOR_FORMAT CD3D9Texture::getColorFormat() const ...@@ -517,7 +494,6 @@ ECOLOR_FORMAT CD3D9Texture::getColorFormat() const
} }
//! returns pitch of texture (in bytes) //! returns pitch of texture (in bytes)
u32 CD3D9Texture::getPitch() const u32 CD3D9Texture::getPitch() const
{ {
...@@ -525,7 +501,6 @@ u32 CD3D9Texture::getPitch() const ...@@ -525,7 +501,6 @@ u32 CD3D9Texture::getPitch() const
} }
//! returns the DIRECT3D9 Texture //! returns the DIRECT3D9 Texture
IDirect3DBaseTexture9* CD3D9Texture::getDX9Texture() const IDirect3DBaseTexture9* CD3D9Texture::getDX9Texture() const
{ {
......
...@@ -80,9 +80,6 @@ private: ...@@ -80,9 +80,6 @@ private:
void createRenderTarget(const ECOLOR_FORMAT format = ECF_UNKNOWN); void createRenderTarget(const ECOLOR_FORMAT format = ECF_UNKNOWN);
//! returns the size of a texture which would be the optimize size for rendering it
inline s32 getTextureSizeFromSurfaceSize(s32 size) const;
//! creates the hardware texture //! creates the hardware texture
bool createTexture(u32 flags, IImage * image); bool createTexture(u32 flags, IImage * image);
......
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