Skip to content

Commit dff7d38

Browse files
committed
[Windows] Texture から ID3D11Texture2D を取得できるように #1219
1 parent c1beee0 commit dff7d38

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

Siv3D/include/Siv3D/Texture.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
# include "PredefinedNamedParameter.hpp"
2020
# include "PredefinedYesNo.hpp"
2121

22+
# if SIV3D_PLATFORM(WINDOWS)
23+
24+
struct ID3D11Texture2D;
25+
26+
# endif
27+
2228
namespace s3d
2329
{
2430
struct TextureRegion;
@@ -289,6 +295,13 @@ namespace s3d
289295

290296
void swap(Texture& other) noexcept;
291297

298+
# if SIV3D_PLATFORM(WINDOWS)
299+
300+
[[nodiscard]]
301+
ID3D11Texture2D* getD3D11Texture2D();
302+
303+
# endif
304+
292305
protected:
293306

294307
struct Dynamic {};

Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Texture/D3D11/CTexture_D3D11.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ namespace s3d
405405
m_textures[handleID]->resolveMSRT(m_context);
406406
}
407407

408+
ID3D11Texture2D* CTexture_D3D11::getTexture(const Texture::IDType handleID)
409+
{
410+
return m_textures[handleID]->getTexture();
411+
}
412+
408413
ID3D11ShaderResourceView** CTexture_D3D11::getSRVPtr(const Texture::IDType handleID)
409414
{
410415
return m_textures[handleID]->getSRVPtr();

Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Texture/D3D11/CTexture_D3D11.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ namespace s3d
104104
//
105105
// D3D11
106106
//
107+
ID3D11Texture2D* getTexture(Texture::IDType handleID);
107108

108109
ID3D11ShaderResourceView** getSRVPtr(Texture::IDType handleID);
109110

Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Texture/D3D11/D3D11Texture.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ namespace s3d
559559
return m_hasDepth;
560560
}
561561

562+
ID3D11Texture2D* D3D11Texture::getTexture()
563+
{
564+
return m_texture.Get();
565+
}
566+
562567
ID3D11ShaderResourceView** D3D11Texture::getSRVPtr()
563568
{
564569
return m_shaderResourceView.GetAddressOf();

Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Texture/D3D11/D3D11Texture.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ namespace s3d
6363
[[nodiscard]]
6464
bool hasDepth() const noexcept;
6565

66+
[[nodiscard]]
67+
ID3D11Texture2D* getTexture();
68+
6669
[[nodiscard]]
6770
ID3D11ShaderResourceView** getSRVPtr();
6871

Siv3D/src/Siv3D/Texture/SivTexture.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
# include <Siv3D/AssetMonitor/IAssetMonitor.hpp>
2525
# include <Siv3D/Common/Siv3DEngine.hpp>
2626

27+
# if SIV3D_PLATFORM(WINDOWS)
28+
# include <Siv3D/Texture/D3D11/CTexture_D3D11.hpp>
29+
# endif
30+
2731
namespace s3d
2832
{
2933
namespace detail
@@ -631,6 +635,22 @@ namespace s3d
631635
m_handle.swap(other.m_handle);
632636
}
633637

638+
# if SIV3D_PLATFORM(WINDOWS)
639+
640+
ID3D11Texture2D* Texture::getD3D11Texture2D()
641+
{
642+
if (auto p = dynamic_cast<CTexture_D3D11*>(SIV3D_ENGINE(Texture)))
643+
{
644+
return p->getTexture(m_handle->id());
645+
}
646+
else
647+
{
648+
return nullptr;
649+
}
650+
}
651+
652+
# endif
653+
634654
Texture::Texture(Dynamic, const Size& size, const void* pData, const uint32 stride, const TextureFormat& format, const TextureDesc desc)
635655
: AssetHandle{ (detail::CheckEngine(U"DynamicTexture"), std::make_shared<AssetIDWrapperType>(SIV3D_ENGINE(Texture)->createDynamic(size, pData, stride, format, desc)))}
636656
{

0 commit comments

Comments
 (0)