You need to sign in or sign up before continuing.
Commit 0b391b03 authored by bitplane's avatar bitplane

Added fix for d3d9 textures by rogerborg- D3D9 textures no longer hold on to...

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
parent 78a68119
...@@ -31,7 +31,7 @@ namespace video ...@@ -31,7 +31,7 @@ namespace video
//! rendertarget constructor //! rendertarget constructor
CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, core::dimension2d<s32> size, const char* name) 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), TextureSize(size), ImageSize(size), Pitch(0),
HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(true) HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(true)
{ {
...@@ -50,7 +50,7 @@ CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, core::dimension2d<s32> size, con ...@@ -50,7 +50,7 @@ CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, core::dimension2d<s32> size, con
//! constructor //! constructor
CD3D9Texture::CD3D9Texture(IImage* image, CD3D9Driver* driver, CD3D9Texture::CD3D9Texture(IImage* image, CD3D9Driver* driver,
u32 flags, const char* name) 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), TextureSize(0,0), ImageSize(0,0), Pitch(0),
HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false) HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false)
{ {
...@@ -64,13 +64,11 @@ HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false) ...@@ -64,13 +64,11 @@ HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false)
if (Device) if (Device)
Device->AddRef(); Device->AddRef();
if (Image) if (image)
{ {
Image->grab(); if (createTexture(flags, image))
if (createTexture(flags))
{ {
if (copyTexture() && generateMipLevels) if (copyTexture(image) && generateMipLevels)
{ {
// create mip maps. // create mip maps.
#ifdef _IRR_USE_D3DXFilterTexture_ #ifdef _IRR_USE_D3DXFilterTexture_
...@@ -100,9 +98,6 @@ CD3D9Texture::~CD3D9Texture() ...@@ -100,9 +98,6 @@ CD3D9Texture::~CD3D9Texture()
if (Device) if (Device)
Device->Release(); Device->Release();
if (Image)
Image->drop();
if (Texture) if (Texture)
Texture->Release(); Texture->Release();
...@@ -259,10 +254,10 @@ bool CD3D9Texture::createMipMaps(u32 level) ...@@ -259,10 +254,10 @@ bool CD3D9Texture::createMipMaps(u32 level)
//! creates the hardware texture //! creates the hardware texture
bool CD3D9Texture::createTexture(u32 flags) bool CD3D9Texture::createTexture(u32 flags, IImage * image)
{ {
core::dimension2d<s32> optSize; core::dimension2d<s32> optSize;
ImageSize = Image->getDimension(); ImageSize = image->getDimension();
if (Driver->queryFeature(EVDF_TEXTURE_NPOT)) if (Driver->queryFeature(EVDF_TEXTURE_NPOT))
optSize=ImageSize; optSize=ImageSize;
...@@ -283,7 +278,7 @@ bool CD3D9Texture::createTexture(u32 flags) ...@@ -283,7 +278,7 @@ bool CD3D9Texture::createTexture(u32 flags)
format = D3DFMT_A8R8G8B8; break; format = D3DFMT_A8R8G8B8; break;
case ETCF_OPTIMIZED_FOR_QUALITY: case ETCF_OPTIMIZED_FOR_QUALITY:
{ {
switch(Image->getColorFormat()) switch(image->getColorFormat())
{ {
case ECF_R8G8B8: case ECF_R8G8B8:
case ECF_A8R8G8B8: case ECF_A8R8G8B8:
...@@ -395,9 +390,9 @@ ECOLOR_FORMAT CD3D9Texture::getColorFormatFromD3DFormat(D3DFORMAT format) ...@@ -395,9 +390,9 @@ ECOLOR_FORMAT CD3D9Texture::getColorFormatFromD3DFormat(D3DFORMAT format)
//! copies the image to the texture //! copies the image to the texture
bool CD3D9Texture::copyTexture() bool CD3D9Texture::copyTexture(IImage * image)
{ {
if (Texture && Image) if (Texture && image)
{ {
D3DSURFACE_DESC desc; D3DSURFACE_DESC desc;
Texture->GetLevelDesc(0, &desc); Texture->GetLevelDesc(0, &desc);
...@@ -414,7 +409,7 @@ bool CD3D9Texture::copyTexture() ...@@ -414,7 +409,7 @@ bool CD3D9Texture::copyTexture()
} }
Pitch = rect.Pitch; 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); hr = Texture->UnlockRect(0);
if (FAILED(hr)) if (FAILED(hr))
...@@ -687,3 +682,4 @@ IDirect3DSurface9* CD3D9Texture::getRenderTargetSurface() ...@@ -687,3 +682,4 @@ IDirect3DSurface9* CD3D9Texture::getRenderTargetSurface()
#endif // _IRR_COMPILE_WITH_DIRECT3D_9_ #endif // _IRR_COMPILE_WITH_DIRECT3D_9_
...@@ -80,10 +80,10 @@ private: ...@@ -80,10 +80,10 @@ private:
inline s32 getTextureSizeFromImageSize(s32 size) const; inline s32 getTextureSizeFromImageSize(s32 size) const;
//! creates the hardware texture //! creates the hardware texture
bool createTexture(u32 flags); bool createTexture(u32 flags, IImage * image);
//! copies the image to the texture //! copies the image to the texture
bool copyTexture(); bool copyTexture(IImage * image);
//! Get D3D color format from Irrlicht color format. //! Get D3D color format from Irrlicht color format.
D3DFORMAT getD3DFormatFromColorFormat(ECOLOR_FORMAT format) const; D3DFORMAT getD3DFormatFromColorFormat(ECOLOR_FORMAT format) const;
...@@ -102,7 +102,6 @@ private: ...@@ -102,7 +102,6 @@ private:
void copy32BitMipMap(char* src, char* tgt, void copy32BitMipMap(char* src, char* tgt,
s32 width, s32 height, s32 pitchsrc, s32 pitchtgt) const; s32 width, s32 height, s32 pitchsrc, s32 pitchtgt) const;
IImage* Image;
IDirect3DDevice9* Device; IDirect3DDevice9* Device;
IDirect3DTexture9* Texture; IDirect3DTexture9* Texture;
IDirect3DSurface9* RTTSurface; IDirect3DSurface9* RTTSurface;
...@@ -125,3 +124,4 @@ private: ...@@ -125,3 +124,4 @@ private:
#endif // __C_DIRECTX9_TEXTURE_H_INCLUDED__ #endif // __C_DIRECTX9_TEXTURE_H_INCLUDED__
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