Added fix for d3d9 textures by rogerborg- D3D9 textures no longer hold on to the IImage pointer, a copy is already in system ram due to using the d3d_managed pool. The same change should also be added to D3D8 textures.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1122 dfc29bdd-3216-0410-991c-e03cc46cb475
master
bitplane 2007-12-21 21:20:34 +00:00
parent 78a681194d
commit 0b391b0380
2 changed files with 15 additions and 19 deletions

View File

@ -31,7 +31,7 @@ namespace video
//! rendertarget constructor
CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, core::dimension2d<s32> size, const char* name)
: ITexture(name), Image(0), Texture(0), RTTSurface(0), Driver(driver),
: ITexture(name), Texture(0), RTTSurface(0), Driver(driver),
TextureSize(size), ImageSize(size), Pitch(0),
HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(true)
{
@ -50,7 +50,7 @@ CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, core::dimension2d<s32> size, con
//! constructor
CD3D9Texture::CD3D9Texture(IImage* image, CD3D9Driver* driver,
u32 flags, const char* name)
: ITexture(name), Image(image), Texture(0), RTTSurface(0), Driver(driver),
: ITexture(name), Texture(0), RTTSurface(0), Driver(driver),
TextureSize(0,0), ImageSize(0,0), Pitch(0),
HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false)
{
@ -64,13 +64,11 @@ HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false)
if (Device)
Device->AddRef();
if (Image)
if (image)
{
Image->grab();
if (createTexture(flags))
if (createTexture(flags, image))
{
if (copyTexture() && generateMipLevels)
if (copyTexture(image) && generateMipLevels)
{
// create mip maps.
#ifdef _IRR_USE_D3DXFilterTexture_
@ -100,9 +98,6 @@ CD3D9Texture::~CD3D9Texture()
if (Device)
Device->Release();
if (Image)
Image->drop();
if (Texture)
Texture->Release();
@ -259,10 +254,10 @@ bool CD3D9Texture::createMipMaps(u32 level)
//! creates the hardware texture
bool CD3D9Texture::createTexture(u32 flags)
bool CD3D9Texture::createTexture(u32 flags, IImage * image)
{
core::dimension2d<s32> optSize;
ImageSize = Image->getDimension();
ImageSize = image->getDimension();
if (Driver->queryFeature(EVDF_TEXTURE_NPOT))
optSize=ImageSize;
@ -283,7 +278,7 @@ bool CD3D9Texture::createTexture(u32 flags)
format = D3DFMT_A8R8G8B8; break;
case ETCF_OPTIMIZED_FOR_QUALITY:
{
switch(Image->getColorFormat())
switch(image->getColorFormat())
{
case ECF_R8G8B8:
case ECF_A8R8G8B8:
@ -395,9 +390,9 @@ ECOLOR_FORMAT CD3D9Texture::getColorFormatFromD3DFormat(D3DFORMAT format)
//! copies the image to the texture
bool CD3D9Texture::copyTexture()
bool CD3D9Texture::copyTexture(IImage * image)
{
if (Texture && Image)
if (Texture && image)
{
D3DSURFACE_DESC desc;
Texture->GetLevelDesc(0, &desc);
@ -414,7 +409,7 @@ bool CD3D9Texture::copyTexture()
}
Pitch = rect.Pitch;
Image->copyToScaling(rect.pBits, TextureSize.Width, TextureSize.Height, ColorFormat, Pitch);
image->copyToScaling(rect.pBits, TextureSize.Width, TextureSize.Height, ColorFormat, Pitch);
hr = Texture->UnlockRect(0);
if (FAILED(hr))
@ -687,3 +682,4 @@ IDirect3DSurface9* CD3D9Texture::getRenderTargetSurface()
#endif // _IRR_COMPILE_WITH_DIRECT3D_9_

View File

@ -80,10 +80,10 @@ private:
inline s32 getTextureSizeFromImageSize(s32 size) const;
//! creates the hardware texture
bool createTexture(u32 flags);
bool createTexture(u32 flags, IImage * image);
//! copies the image to the texture
bool copyTexture();
bool copyTexture(IImage * image);
//! Get D3D color format from Irrlicht color format.
D3DFORMAT getD3DFormatFromColorFormat(ECOLOR_FORMAT format) const;
@ -102,7 +102,6 @@ private:
void copy32BitMipMap(char* src, char* tgt,
s32 width, s32 height, s32 pitchsrc, s32 pitchtgt) const;
IImage* Image;
IDirect3DDevice9* Device;
IDirect3DTexture9* Texture;
IDirect3DSurface9* RTTSurface;
@ -125,3 +124,4 @@ private:
#endif // __C_DIRECTX9_TEXTURE_H_INCLUDED__