From 224d7c5e2ca443adcf8303991393c9e105bfef15 Mon Sep 17 00:00:00 2001 From: cutealien Date: Fri, 4 Jun 2021 12:17:01 +0000 Subject: [PATCH] Vertex texture sampling support in Direct3D 9 now controlled via texture-flag ETCF_SUPPORT_VERTEXT_TEXTURE It's no longer enabled by default as it causes some costs to all texture switches. Thanks @ edo9300 for reporting (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=52721) git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6219 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 2 ++ include/ITexture.h | 8 ++++++++ source/Irrlicht/CD3D9Driver.cpp | 17 +++++++++-------- source/Irrlicht/CD3D9Texture.cpp | 10 ++++++---- source/Irrlicht/CD3D9Texture.h | 6 ++++++ 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/changes.txt b/changes.txt index f6bcfa7d..8c00b5ba 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,7 @@ -------------------------- Changes in 1.9 (not yet released) +- Add ETCF_SUPPORT_VERTEXT_TEXTURE flag which can be used to enable vertex texture sampling support in Direct3D 9. + Note that this was enabled for a long time in 1.9 svn, but is now disabled by default. - CGUIListBox now serializes the state of "Selected". Feature wish by chronologicaldot (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=2&t=52719) - Bugfix: Changing focus with tab-keys now also work when elements are inside a modal screen. - COBJMeshFileLoader using a bit more exact color conversion for 0-1 to 0-255 range (same now as SColorf::toSColor uses). diff --git a/include/ITexture.h b/include/ITexture.h index f975abd8..3976ba37 100644 --- a/include/ITexture.h +++ b/include/ITexture.h @@ -97,6 +97,14 @@ enum E_TEXTURE_CREATION_FLAG */ ETCF_AUTO_GENERATE_MIP_MAPS = 0x00000100, + //! Enable support for vertex shader texture sampling on some drivers + /** Default is false. + This adds a small costs to all texture switches. + Currently only affects D3D9. + On OpenGL vertex shaders use the same texture unit as pixel shaders, so support there only depends on GL version and not on this flag + */ + ETCF_SUPPORT_VERTEXT_TEXTURE = 0x00000200, + /** This flag is never used, it only forces the compiler to compile these enumeration values to 32 bit. */ ETCF_FORCE_32_BIT_DO_NOT_USE = 0x7fffffff diff --git a/source/Irrlicht/CD3D9Driver.cpp b/source/Irrlicht/CD3D9Driver.cpp index 48de93b2..3c46c877 100644 --- a/source/Irrlicht/CD3D9Driver.cpp +++ b/source/Irrlicht/CD3D9Driver.cpp @@ -698,12 +698,6 @@ bool CD3D9Driver::setActiveTexture(u32 stage, const video::ITexture* texture) if (CurrentTexture[stage] == texture) return true; - if (texture && texture->getDriverType() != EDT_DIRECT3D9) - { - os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR); - return false; - } - CurrentTexture[stage] = texture; if (!texture) @@ -711,13 +705,20 @@ bool CD3D9Driver::setActiveTexture(u32 stage, const video::ITexture* texture) pID3DDevice->SetTexture(stage, 0); pID3DDevice->SetTextureStageState( stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE ); } - else + else if (texture->getDriverType() == EDT_DIRECT3D9) { pID3DDevice->SetTexture(stage, ((const CD3D9Texture*)texture)->getDX9BaseTexture()); - if (stage <= 4) + if (((const CD3D9Texture*)texture)->HasVertexTextureSupport() && stage < 4 ) pID3DDevice->SetTexture(D3DVERTEXTEXTURESAMPLER0 + stage, ((const CD3D9Texture*)texture)->getDX9BaseTexture()); } + else + { + os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR); + setActiveTexture(stage, 0); + return false; + } + return true; } diff --git a/source/Irrlicht/CD3D9Texture.cpp b/source/Irrlicht/CD3D9Texture.cpp index 42a8df55..a04b5f9e 100644 --- a/source/Irrlicht/CD3D9Texture.cpp +++ b/source/Irrlicht/CD3D9Texture.cpp @@ -38,17 +38,19 @@ CD3D9Texture::CD3D9Texture(const io::path& name, const core::array& ima DWORD flags = 0; + LPDIRECT3D9 intf = Driver->getExposedVideoData().D3D9.D3D9; + D3DDISPLAYMODE d3ddm; + intf->GetAdapterDisplayMode(Driver->Params.DisplayAdapter, &d3ddm); if (HasMipMaps && HardwareMipMaps) { - LPDIRECT3D9 intf = Driver->getExposedVideoData().D3D9.D3D9; - D3DDISPLAYMODE d3ddm; - intf->GetAdapterDisplayMode(Driver->Params.DisplayAdapter, &d3ddm); - if (D3D_OK == intf->CheckDeviceFormat(Driver->Params.DisplayAdapter, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_AUTOGENMIPMAP, D3DRTYPE_TEXTURE, InternalFormat)) flags = D3DUSAGE_AUTOGENMIPMAP; else HardwareMipMaps = false; } + + VertexTextureSupport = Driver->getTextureCreationFlag(ETCF_SUPPORT_VERTEXT_TEXTURE) + && (D3D_OK == intf->CheckDeviceFormat(Driver->Params.DisplayAdapter, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, InternalFormat)); HRESULT hr = 0; diff --git a/source/Irrlicht/CD3D9Texture.h b/source/Irrlicht/CD3D9Texture.h index 879f1437..40ddb235 100644 --- a/source/Irrlicht/CD3D9Texture.h +++ b/source/Irrlicht/CD3D9Texture.h @@ -42,6 +42,11 @@ public: IDirect3DTexture9* getDX9Texture() const; IDirect3DCubeTexture9* getDX9CubeTexture() const; + inline bool HasVertexTextureSupport() const + { + return VertexTextureSupport; + } + private: friend class CD3D9Driver; @@ -77,6 +82,7 @@ private: u32 MipLevelLocked; bool HardwareMipMaps; + bool VertexTextureSupport; IDirect3DDevice9* Device; IDirect3DTexture9* Texture;