Commit 81a4c3d9 authored by nadro's avatar nadro

- Added cubemaps support for D3D9.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5239 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 5325a921
......@@ -717,10 +717,10 @@ bool CD3D9Driver::setActiveTexture(u32 stage, const video::ITexture* texture)
}
else
{
pID3DDevice->SetTexture(stage, ((const CD3D9Texture*)texture)->getDX9Texture());
pID3DDevice->SetTexture(stage, ((const CD3D9Texture*)texture)->getDX9BaseTexture());
if (stage <= 4)
pID3DDevice->SetTexture(D3DVERTEXTEXTURESAMPLER0 + stage, ((const CD3D9Texture*)texture)->getDX9Texture());
pID3DDevice->SetTexture(D3DVERTEXTEXTURESAMPLER0 + stage, ((const CD3D9Texture*)texture)->getDX9BaseTexture());
}
return true;
}
......@@ -2827,7 +2827,7 @@ bool CD3D9Driver::reset()
{
if (Textures[i].Surface->isRenderTarget())
{
IDirect3DTexture9* tex = ((CD3D9Texture*)(Textures[i].Surface))->getDX9Texture();
IDirect3DBaseTexture9* tex = ((CD3D9Texture*)(Textures[i].Surface))->getDX9BaseTexture();
if (tex)
tex->Release();
}
......
......@@ -131,17 +131,20 @@ namespace irr
IDirect3DTexture9* currentTexture = (depthStencil && depthStencil->getDriverType() == EDT_DIRECT3D9) ?
static_cast<CD3D9Texture*>(depthStencil)->getDX9Texture() : 0;
const ECOLOR_FORMAT textureFormat = (depthStencil) ? depthStencil->getColorFormat() : ECF_UNKNOWN;
if (IImage::isDepthFormat(textureFormat))
if (currentTexture)
{
DepthStencil = depthStencil;
DepthStencil->grab();
const ECOLOR_FORMAT textureFormat = (depthStencil) ? depthStencil->getColorFormat() : ECF_UNKNOWN;
if (IImage::isDepthFormat(textureFormat))
{
DepthStencil = depthStencil;
DepthStencil->grab();
IDirect3DSurface9* currentSurface = 0;
currentTexture->GetSurfaceLevel(0, &currentSurface);
IDirect3DSurface9* currentSurface = 0;
currentTexture->GetSurfaceLevel(0, &currentSurface);
DepthStencilSurface = currentSurface;
DepthStencilSurface = currentSurface;
}
}
}
......
......@@ -65,7 +65,20 @@ CD3D9Texture::CD3D9Texture(const io::path& name, const core::array<IImage*>& ima
AutoGenerateMipMaps = false;
}
HRESULT hr = Device->CreateTexture(Size.Width, Size.Height, HasMipMaps ? 0 : 1, flags, InternalFormat, D3DPOOL_MANAGED, &Texture, NULL);
HRESULT hr = 0;
switch (Type)
{
case ETT_2D:
Device->CreateTexture(Size.Width, Size.Height, HasMipMaps ? 0 : 1, flags, InternalFormat, D3DPOOL_MANAGED, &Texture, NULL);
break;
case ETT_CUBEMAP:
Device->CreateCubeTexture(Size.Width, HasMipMaps ? 0 : 1, flags, InternalFormat, D3DPOOL_MANAGED, &CubeTexture, NULL);
break;
default:
_IRR_DEBUG_BREAK_IF(true)
break;
}
if (SUCCEEDED(hr))
{
......@@ -128,6 +141,9 @@ CD3D9Texture::~CD3D9Texture()
if (Texture)
Texture->Release();
if (CubeTexture)
CubeTexture->Release();
if (RTTSurface)
RTTSurface->Release();
......@@ -151,7 +167,16 @@ void* CD3D9Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
if (!IsRenderTarget)
{
hr = Texture->LockRect(mipmapLevel, &rect, 0, lockReadOnly ? D3DLOCK_READONLY : 0);
if (Texture)
{
hr = Texture->LockRect(mipmapLevel, &rect, 0, lockReadOnly ? D3DLOCK_READONLY : 0);
}
else if (CubeTexture)
{
// TO-DO -> hardcoded D3DCUBEMAP_FACE_POSITIVE_X.
hr = CubeTexture->LockRect(D3DCUBEMAP_FACE_POSITIVE_X, mipmapLevel, &rect, 0, lockReadOnly ? D3DLOCK_READONLY : 0);
}
if (FAILED(hr))
{
os::Printer::log("Could not lock DIRECT3D9 Texture.", ELL_ERROR);
......@@ -206,9 +231,21 @@ void CD3D9Texture::unlock()
return;
if (!IsRenderTarget)
Texture->UnlockRect(0);
{
if (Texture)
{
Texture->UnlockRect(LockLevel);
}
else if (CubeTexture)
{
// TO-DO -> hardcoded D3DCUBEMAP_FACE_POSITIVE_X.
CubeTexture->UnlockRect(D3DCUBEMAP_FACE_POSITIVE_X, LockLevel);
}
}
else if (RTTSurface)
{
RTTSurface->UnlockRect();
}
if (LockLevel == 0)
regenerateMipMapLevels(0);
......@@ -248,15 +285,28 @@ void CD3D9Texture::regenerateMipMapLevels(void* data, u32 layer)
}
else
{
Texture->GenerateMipSubLevels();
if (Texture)
Texture->GenerateMipSubLevels();
else if (CubeTexture)
CubeTexture->GenerateMipSubLevels();
}
}
IDirect3DBaseTexture9* CD3D9Texture::getDX9BaseTexture() const
{
return (Texture) ? static_cast<IDirect3DBaseTexture9*>(Texture) : static_cast<IDirect3DBaseTexture9*>(CubeTexture);
}
IDirect3DTexture9* CD3D9Texture::getDX9Texture() const
{
return Texture;
}
IDirect3DCubeTexture9* CD3D9Texture::getDX9CubeTexture() const
{
return CubeTexture;
}
void CD3D9Texture::generateRenderTarget()
{
DWORD flag = (IImage::isDepthFormat(ColorFormat)) ? D3DUSAGE_DEPTHSTENCIL : D3DUSAGE_RENDERTARGET;
......@@ -367,12 +417,28 @@ void CD3D9Texture::uploadTexture(u32 layer, u32 level, void* data)
u32 width = Size.Width >> level;
u32 height = Size.Height >> level;
const D3DCUBEMAP_FACES cubeTextureType[6] =
{
D3DCUBEMAP_FACE_POSITIVE_X, D3DCUBEMAP_FACE_NEGATIVE_X,
D3DCUBEMAP_FACE_POSITIVE_Y, D3DCUBEMAP_FACE_NEGATIVE_Y,
D3DCUBEMAP_FACE_POSITIVE_Z, D3DCUBEMAP_FACE_NEGATIVE_Z
};
u32 dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height);
HRESULT hr = 0;
D3DLOCKED_RECT lockRectangle;
hr = Texture->LockRect(level, &lockRectangle, 0, 0);
if (Texture)
{
hr = Texture->LockRect(level, &lockRectangle, 0, 0);
}
else if (CubeTexture)
{
const D3DCUBEMAP_FACES tmpCubeTextureType = cubeTextureType[(layer < 6) ? layer : 0];
hr = CubeTexture->LockRect(tmpCubeTextureType, level, &lockRectangle, 0, 0);
}
if (FAILED(hr))
{
......@@ -382,7 +448,15 @@ void CD3D9Texture::uploadTexture(u32 layer, u32 level, void* data)
memcpy(lockRectangle.pBits, data, dataSize);
hr = Texture->UnlockRect(level);
if (Texture)
{
hr = Texture->UnlockRect(level);
}
else if (CubeTexture)
{
const D3DCUBEMAP_FACES tmpCubeTextureType = cubeTextureType[(layer < 6) ? layer : 0];
hr = CubeTexture->UnlockRect(tmpCubeTextureType, level);
}
if (FAILED(hr))
{
......
......@@ -38,7 +38,9 @@ public:
virtual void regenerateMipMapLevels(void* data = 0, u32 layer = 0) _IRR_OVERRIDE_;
IDirect3DBaseTexture9* getDX9BaseTexture() const;
IDirect3DTexture9* getDX9Texture() const;
IDirect3DCubeTexture9* getDX9CubeTexture() const;
private:
friend class CD3D9Driver;
......
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