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
{
class CD3D8Driver : public CNullDriver, IMaterialRendererServices
{
friend class CD3D8Texture;
public:
//! constructor
......
......@@ -112,20 +112,11 @@ CD3D8Texture::~CD3D8Texture()
//! creates the hardware texture
bool CD3D8Texture::createTexture(video::IImage* image, u32 flags)
{
core::dimension2d<u32> optSize;
ImageSize = image->getDimension();
if (Driver->queryFeature(EVDF_TEXTURE_NPOT))
optSize=ImageSize;
else
{
optSize.Width = getTextureSizeFromSurfaceSize(ImageSize.Width);
optSize.Height = getTextureSizeFromSurfaceSize(ImageSize.Height);
}
core::dimension2d<u32> optSize = ImageSize.getOptimalSize(Driver->queryFeature(EVDF_TEXTURE_NPOT), Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);
HRESULT hr;
D3DFORMAT format = D3DFMT_A1R5G5B5;
switch(getTextureFormatFromFlags(flags))
{
case ETCF_ALWAYS_16_BIT:
......@@ -165,7 +156,7 @@ bool CD3D8Texture::createTexture(video::IImage* image, u32 flags)
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)
0, format, D3DPOOL_MANAGED, &Texture);
......@@ -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)
E_DRIVER_TYPE CD3D8Texture::getDriverType() const
{
......@@ -332,7 +311,6 @@ E_DRIVER_TYPE CD3D8Texture::getDriverType() const
}
//! returns color format of texture
ECOLOR_FORMAT CD3D8Texture::getColorFormat() const
{
......@@ -340,7 +318,6 @@ ECOLOR_FORMAT CD3D8Texture::getColorFormat() const
}
//! returns pitch of texture (in bytes)
u32 CD3D8Texture::getPitch() const
{
......@@ -348,7 +325,6 @@ u32 CD3D8Texture::getPitch() const
}
//! returns the DIRECT3D8 Texture
IDirect3DTexture8* CD3D8Texture::getDX8Texture() const
{
......@@ -561,11 +537,9 @@ void CD3D8Texture::copy32BitMipMap(char* src, char* tgt,
}
void CD3D8Texture::createRenderTarget()
{
TextureSize.Width = getTextureSizeFromSurfaceSize(TextureSize.Width);
TextureSize.Height = getTextureSizeFromSurfaceSize(TextureSize.Height);
TextureSize = TextureSize.getOptimalSize(Driver->queryFeature(EVDF_TEXTURE_NPOT), Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);
// get backbuffer format to create the render target in the
// same format
......@@ -611,7 +585,6 @@ void CD3D8Texture::createRenderTarget()
}
//! Regenerates the mip map levels of the texture. Useful after locking and
//! modifying the texture
void CD3D8Texture::regenerateMipMapLevels()
......@@ -627,6 +600,7 @@ bool CD3D8Texture::isRenderTarget() const
return IsRenderTarget;
}
//! Returns pointer to the render target surface
IDirect3DSurface8* CD3D8Texture::getRenderTargetSurface()
{
......
......@@ -79,9 +79,6 @@ private:
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
bool createTexture(IImage* Image, u32 flags);
......
......@@ -44,6 +44,8 @@ namespace video
{
public:
friend class CD3D9Texture;
//! constructor
CD3D9Driver(const core::dimension2d<u32>& screenSize, HWND window, bool fullscreen,
bool stencibuffer, io::IFileSystem* io, bool pureSoftware=false);
......
......@@ -121,11 +121,10 @@ void CD3D9Texture::createRenderTarget(const ECOLOR_FORMAT format)
// are texture size restrictions there ?
if(!Driver->queryFeature(EVDF_TEXTURE_NPOT))
{
TextureSize.Width = getTextureSizeFromSurfaceSize(TextureSize.Width);
TextureSize.Height = getTextureSizeFromSurfaceSize(TextureSize.Height);
if (TextureSize != ImageSize)
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();
......@@ -278,18 +277,10 @@ bool CD3D9Texture::createMipMaps(u32 level)
//! creates the hardware texture
bool CD3D9Texture::createTexture(u32 flags, IImage * image)
{
core::dimension2d<u32> optSize;
ImageSize = image->getDimension();
if (Driver->queryFeature(EVDF_TEXTURE_NPOT))
optSize=ImageSize;
else
{
optSize.Width = getTextureSizeFromSurfaceSize(ImageSize.Width);
optSize.Height = getTextureSizeFromSurfaceSize(ImageSize.Height);
}
core::dimension2d<u32> optSize = ImageSize.getOptimalSize(Driver->queryFeature(EVDF_TEXTURE_NPOT), Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);
HRESULT hr;
D3DFORMAT format = D3DFMT_A1R5G5B5;
switch(getTextureFormatFromFlags(flags))
......@@ -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)
usage, // usage
format, D3DPOOL_MANAGED , &Texture, NULL);
......@@ -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)
E_DRIVER_TYPE CD3D9Texture::getDriverType() const
{
......@@ -509,7 +487,6 @@ E_DRIVER_TYPE CD3D9Texture::getDriverType() const
}
//! returns color format of texture
ECOLOR_FORMAT CD3D9Texture::getColorFormat() const
{
......@@ -517,7 +494,6 @@ ECOLOR_FORMAT CD3D9Texture::getColorFormat() const
}
//! returns pitch of texture (in bytes)
u32 CD3D9Texture::getPitch() const
{
......@@ -525,7 +501,6 @@ u32 CD3D9Texture::getPitch() const
}
//! returns the DIRECT3D9 Texture
IDirect3DBaseTexture9* CD3D9Texture::getDX9Texture() const
{
......
......@@ -80,9 +80,6 @@ private:
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
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