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) ...@@ -717,10 +717,10 @@ bool CD3D9Driver::setActiveTexture(u32 stage, const video::ITexture* texture)
} }
else else
{ {
pID3DDevice->SetTexture(stage, ((const CD3D9Texture*)texture)->getDX9Texture()); pID3DDevice->SetTexture(stage, ((const CD3D9Texture*)texture)->getDX9BaseTexture());
if (stage <= 4) if (stage <= 4)
pID3DDevice->SetTexture(D3DVERTEXTEXTURESAMPLER0 + stage, ((const CD3D9Texture*)texture)->getDX9Texture()); pID3DDevice->SetTexture(D3DVERTEXTEXTURESAMPLER0 + stage, ((const CD3D9Texture*)texture)->getDX9BaseTexture());
} }
return true; return true;
} }
...@@ -2827,7 +2827,7 @@ bool CD3D9Driver::reset() ...@@ -2827,7 +2827,7 @@ bool CD3D9Driver::reset()
{ {
if (Textures[i].Surface->isRenderTarget()) if (Textures[i].Surface->isRenderTarget())
{ {
IDirect3DTexture9* tex = ((CD3D9Texture*)(Textures[i].Surface))->getDX9Texture(); IDirect3DBaseTexture9* tex = ((CD3D9Texture*)(Textures[i].Surface))->getDX9BaseTexture();
if (tex) if (tex)
tex->Release(); tex->Release();
} }
......
...@@ -131,6 +131,8 @@ namespace irr ...@@ -131,6 +131,8 @@ namespace irr
IDirect3DTexture9* currentTexture = (depthStencil && depthStencil->getDriverType() == EDT_DIRECT3D9) ? IDirect3DTexture9* currentTexture = (depthStencil && depthStencil->getDriverType() == EDT_DIRECT3D9) ?
static_cast<CD3D9Texture*>(depthStencil)->getDX9Texture() : 0; static_cast<CD3D9Texture*>(depthStencil)->getDX9Texture() : 0;
if (currentTexture)
{
const ECOLOR_FORMAT textureFormat = (depthStencil) ? depthStencil->getColorFormat() : ECF_UNKNOWN; const ECOLOR_FORMAT textureFormat = (depthStencil) ? depthStencil->getColorFormat() : ECF_UNKNOWN;
if (IImage::isDepthFormat(textureFormat)) if (IImage::isDepthFormat(textureFormat))
...@@ -144,6 +146,7 @@ namespace irr ...@@ -144,6 +146,7 @@ namespace irr
DepthStencilSurface = currentSurface; DepthStencilSurface = currentSurface;
} }
} }
}
// Set size required for a viewport. // Set size required for a viewport.
......
...@@ -65,7 +65,20 @@ CD3D9Texture::CD3D9Texture(const io::path& name, const core::array<IImage*>& ima ...@@ -65,7 +65,20 @@ CD3D9Texture::CD3D9Texture(const io::path& name, const core::array<IImage*>& ima
AutoGenerateMipMaps = false; 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)) if (SUCCEEDED(hr))
{ {
...@@ -128,6 +141,9 @@ CD3D9Texture::~CD3D9Texture() ...@@ -128,6 +141,9 @@ CD3D9Texture::~CD3D9Texture()
if (Texture) if (Texture)
Texture->Release(); Texture->Release();
if (CubeTexture)
CubeTexture->Release();
if (RTTSurface) if (RTTSurface)
RTTSurface->Release(); RTTSurface->Release();
...@@ -150,8 +166,17 @@ void* CD3D9Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel) ...@@ -150,8 +166,17 @@ void* CD3D9Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
D3DLOCKED_RECT rect; D3DLOCKED_RECT rect;
if (!IsRenderTarget) if (!IsRenderTarget)
{
if (Texture)
{ {
hr = Texture->LockRect(mipmapLevel, &rect, 0, lockReadOnly ? D3DLOCK_READONLY : 0); 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)) if (FAILED(hr))
{ {
os::Printer::log("Could not lock DIRECT3D9 Texture.", ELL_ERROR); os::Printer::log("Could not lock DIRECT3D9 Texture.", ELL_ERROR);
...@@ -206,9 +231,21 @@ void CD3D9Texture::unlock() ...@@ -206,9 +231,21 @@ void CD3D9Texture::unlock()
return; return;
if (!IsRenderTarget) 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) else if (RTTSurface)
{
RTTSurface->UnlockRect(); RTTSurface->UnlockRect();
}
if (LockLevel == 0) if (LockLevel == 0)
regenerateMipMapLevels(0); regenerateMipMapLevels(0);
...@@ -248,15 +285,28 @@ void CD3D9Texture::regenerateMipMapLevels(void* data, u32 layer) ...@@ -248,15 +285,28 @@ void CD3D9Texture::regenerateMipMapLevels(void* data, u32 layer)
} }
else else
{ {
if (Texture)
Texture->GenerateMipSubLevels(); 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 IDirect3DTexture9* CD3D9Texture::getDX9Texture() const
{ {
return Texture; return Texture;
} }
IDirect3DCubeTexture9* CD3D9Texture::getDX9CubeTexture() const
{
return CubeTexture;
}
void CD3D9Texture::generateRenderTarget() void CD3D9Texture::generateRenderTarget()
{ {
DWORD flag = (IImage::isDepthFormat(ColorFormat)) ? D3DUSAGE_DEPTHSTENCIL : D3DUSAGE_RENDERTARGET; DWORD flag = (IImage::isDepthFormat(ColorFormat)) ? D3DUSAGE_DEPTHSTENCIL : D3DUSAGE_RENDERTARGET;
...@@ -367,12 +417,28 @@ void CD3D9Texture::uploadTexture(u32 layer, u32 level, void* data) ...@@ -367,12 +417,28 @@ void CD3D9Texture::uploadTexture(u32 layer, u32 level, void* data)
u32 width = Size.Width >> level; u32 width = Size.Width >> level;
u32 height = Size.Height >> 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); u32 dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height);
HRESULT hr = 0; HRESULT hr = 0;
D3DLOCKED_RECT lockRectangle; D3DLOCKED_RECT lockRectangle;
if (Texture)
{
hr = Texture->LockRect(level, &lockRectangle, 0, 0); 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)) if (FAILED(hr))
{ {
...@@ -382,7 +448,15 @@ void CD3D9Texture::uploadTexture(u32 layer, u32 level, void* data) ...@@ -382,7 +448,15 @@ void CD3D9Texture::uploadTexture(u32 layer, u32 level, void* data)
memcpy(lockRectangle.pBits, data, dataSize); memcpy(lockRectangle.pBits, data, dataSize);
if (Texture)
{
hr = Texture->UnlockRect(level); hr = Texture->UnlockRect(level);
}
else if (CubeTexture)
{
const D3DCUBEMAP_FACES tmpCubeTextureType = cubeTextureType[(layer < 6) ? layer : 0];
hr = CubeTexture->UnlockRect(tmpCubeTextureType, level);
}
if (FAILED(hr)) if (FAILED(hr))
{ {
......
...@@ -38,7 +38,9 @@ public: ...@@ -38,7 +38,9 @@ public:
virtual void regenerateMipMapLevels(void* data = 0, u32 layer = 0) _IRR_OVERRIDE_; virtual void regenerateMipMapLevels(void* data = 0, u32 layer = 0) _IRR_OVERRIDE_;
IDirect3DBaseTexture9* getDX9BaseTexture() const;
IDirect3DTexture9* getDX9Texture() const; IDirect3DTexture9* getDX9Texture() const;
IDirect3DCubeTexture9* getDX9CubeTexture() const;
private: private:
friend class CD3D9Driver; 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