From 3469582bac1b51a24d06711acfb24ed33bbacd15 Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 15 Aug 2019 20:18:45 +0000 Subject: [PATCH] Make CD3D9RenderTarget::setTexture code more similar to COpenGLCoreRenderTarget::setTexture. Add log warnings when users try to set depth/stencil textures which have no depth color format. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5845 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CD3D9RenderTarget.cpp | 204 +++++++++++----------- source/Irrlicht/COpenGLCoreRenderTarget.h | 4 + 2 files changed, 107 insertions(+), 101 deletions(-) diff --git a/source/Irrlicht/CD3D9RenderTarget.cpp b/source/Irrlicht/CD3D9RenderTarget.cpp index 28458e88..30ab72c0 100644 --- a/source/Irrlicht/CD3D9RenderTarget.cpp +++ b/source/Irrlicht/CD3D9RenderTarget.cpp @@ -51,136 +51,138 @@ namespace irr void CD3D9RenderTarget::setTexture(const core::array& texture, ITexture* depthStencil, const core::array& cubeSurfaces) { - bool textureUpdate = (Texture != texture) || (CubeSurfaces != cubeSurfaces) ? true : false; - bool depthStencilUpdate = (DepthStencil != depthStencil) ? true : false; + bool needSizeUpdate = false; - if (textureUpdate || depthStencilUpdate) + // Set color attachments. + if ((Texture != texture) || (CubeSurfaces != cubeSurfaces)) { - // Set color attachments. + needSizeUpdate = true; + CubeSurfaces = cubeSurfaces; - if (textureUpdate) + if (texture.size() > Driver->ActiveRenderTarget.size()) { - CubeSurfaces = cubeSurfaces; + core::stringc message = "This GPU supports up to "; + message += Driver->ActiveRenderTarget.size(); + message += " textures per render target."; - if (texture.size() > Driver->ActiveRenderTarget.size()) - { - core::stringc message = "This GPU supports up to "; - message += Driver->ActiveRenderTarget.size(); - message += " textures per render target."; - - os::Printer::log(message.c_str(), ELL_WARNING); - } - - const u32 size = core::min_(texture.size(), static_cast(Driver->ActiveRenderTarget.size())); - - for (u32 i = 0; i < Surface.size(); ++i) - { - if (Surface[i]) - Surface[i]->Release(); - } - - Surface.set_used(size); - - for (u32 i = 0; i < Texture.size(); ++i) - { - if (Texture[i]) - Texture[i]->drop(); - } - - Texture.set_used(size); - - for (u32 i = 0; i < size; ++i) - { - CD3D9Texture* currentTexture = (texture[i] && texture[i]->getDriverType() == DriverType) ? static_cast(texture[i]) : 0; - - IDirect3DTexture9* textureID = 0; - IDirect3DCubeTexture9* cubeTextureId = 0; - UINT level = 0; // no support for rendering to to other mip-levels so far - - if (currentTexture) - { - if (currentTexture->getType() == ETT_2D) - textureID = currentTexture->getDX9Texture(); - else if ( currentTexture->getType() == ETT_CUBEMAP ) - cubeTextureId = currentTexture->getDX9CubeTexture(); - } - - if (textureID) - { - Texture[i] = texture[i]; - Texture[i]->grab(); - - IDirect3DSurface9* currentSurface = 0; - textureID->GetSurfaceLevel(level, ¤tSurface); - - Surface[i] = currentSurface; - } - else if ( cubeTextureId ) - { - Texture[i] = texture[i]; - Texture[i]->grab(); - - IDirect3DSurface9* currentSurface = 0; - D3DCUBEMAP_FACES face = (D3DCUBEMAP_FACES)CubeSurfaces[i]; // we use same numbering - cubeTextureId->GetCubeMapSurface(face, level, ¤tSurface); - - Surface[i] = currentSurface; - } - else - { - Surface[i] = 0; - Texture[i] = 0; - } - } + os::Printer::log(message.c_str(), ELL_WARNING); } - // Set depth and stencil attachments. + const u32 size = core::min_(texture.size(), static_cast(Driver->ActiveRenderTarget.size())); - if (depthStencilUpdate) + for (u32 i = 0; i < Surface.size(); ++i) { - if (DepthStencilSurface) - { - DepthStencilSurface->Release(); - DepthStencilSurface = 0; - } + if (Surface[i]) + Surface[i]->Release(); + } - if (DepthStencil) - { - DepthStencil->drop(); - DepthStencil = 0; + Surface.set_used(size); - DepthStencilSurface = 0; - } + for (u32 i = 0; i < Texture.size(); ++i) + { + if (Texture[i]) + Texture[i]->drop(); + } - CD3D9Texture* currentTexture = (depthStencil && depthStencil->getDriverType() == DriverType) ? static_cast(depthStencil) : 0; + Texture.set_used(size); + + for (u32 i = 0; i < size; ++i) + { + CD3D9Texture* currentTexture = (texture[i] && texture[i]->getDriverType() == DriverType) ? static_cast(texture[i]) : 0; IDirect3DTexture9* textureID = 0; + IDirect3DCubeTexture9* cubeTextureId = 0; + UINT level = 0; // no support for rendering to to other mip-levels so far if (currentTexture) { if (currentTexture->getType() == ETT_2D) textureID = currentTexture->getDX9Texture(); - else - os::Printer::log("This driver doesn't support depth/stencil to cubemaps.", ELL_WARNING); + else if ( currentTexture->getType() == ETT_CUBEMAP ) + cubeTextureId = currentTexture->getDX9CubeTexture(); } if (textureID) { - const ECOLOR_FORMAT textureFormat = (depthStencil) ? depthStencil->getColorFormat() : ECF_UNKNOWN; + Texture[i] = texture[i]; + Texture[i]->grab(); - if (IImage::isDepthFormat(textureFormat)) - { - DepthStencil = depthStencil; - DepthStencil->grab(); + IDirect3DSurface9* currentSurface = 0; + textureID->GetSurfaceLevel(level, ¤tSurface); - IDirect3DSurface9* currentSurface = 0; - textureID->GetSurfaceLevel(0, ¤tSurface); + Surface[i] = currentSurface; + } + else if ( cubeTextureId ) + { + Texture[i] = texture[i]; + Texture[i]->grab(); - DepthStencilSurface = currentSurface; - } + IDirect3DSurface9* currentSurface = 0; + D3DCUBEMAP_FACES face = (D3DCUBEMAP_FACES)CubeSurfaces[i]; // we use same numbering + cubeTextureId->GetCubeMapSurface(face, level, ¤tSurface); + + Surface[i] = currentSurface; + } + else + { + Surface[i] = 0; + Texture[i] = 0; } } + } + // Set depth and stencil attachments. + + if (DepthStencil != depthStencil) + { + if (DepthStencilSurface) + { + DepthStencilSurface->Release(); + DepthStencilSurface = 0; + } + + if (DepthStencil) + { + DepthStencil->drop(); + DepthStencil = 0; + + DepthStencilSurface = 0; + } + + needSizeUpdate = true; + CD3D9Texture* currentTexture = (depthStencil && depthStencil->getDriverType() == DriverType) ? static_cast(depthStencil) : 0; + + if (currentTexture) + { + if (currentTexture->getType() == ETT_2D) + { + IDirect3DTexture9* textureID = currentTexture->getDX9Texture(); + if (textureID) + { + const ECOLOR_FORMAT textureFormat = depthStencil->getColorFormat(); + if (IImage::isDepthFormat(textureFormat)) + { + DepthStencil = depthStencil; + DepthStencil->grab(); + + IDirect3DSurface9* currentSurface = 0; + textureID->GetSurfaceLevel(0, ¤tSurface); + + DepthStencilSurface = currentSurface; + } + else + { + os::Printer::log("Ignoring depth/stencil texture without depth color format.", ELL_WARNING); + } + } + } + else + os::Printer::log("This driver doesn't support depth/stencil to cubemaps.", ELL_WARNING); + } + } + + if (needSizeUpdate) + { // Set size required for a viewport. bool sizeDetected = false; diff --git a/source/Irrlicht/COpenGLCoreRenderTarget.h b/source/Irrlicht/COpenGLCoreRenderTarget.h index 1839be9b..21eb2494 100644 --- a/source/Irrlicht/COpenGLCoreRenderTarget.h +++ b/source/Irrlicht/COpenGLCoreRenderTarget.h @@ -134,6 +134,10 @@ public: DepthStencil = depthStencil; DepthStencil->grab(); } + else + { + os::Printer::log("Ignoring depth/stencil texture without depth color format.", ELL_WARNING); + } } else {