Skip to content

Commit

Permalink
[Windows] Texture から ID3D11Texture2D を取得できるように #1219
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Mar 17, 2024
1 parent c1beee0 commit dff7d38
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Siv3D/include/Siv3D/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
# include "PredefinedNamedParameter.hpp"
# include "PredefinedYesNo.hpp"

# if SIV3D_PLATFORM(WINDOWS)

struct ID3D11Texture2D;

# endif

namespace s3d
{
struct TextureRegion;
Expand Down Expand Up @@ -289,6 +295,13 @@ namespace s3d

void swap(Texture& other) noexcept;

# if SIV3D_PLATFORM(WINDOWS)

[[nodiscard]]
ID3D11Texture2D* getD3D11Texture2D();

# endif

protected:

struct Dynamic {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ namespace s3d
m_textures[handleID]->resolveMSRT(m_context);
}

ID3D11Texture2D* CTexture_D3D11::getTexture(const Texture::IDType handleID)
{
return m_textures[handleID]->getTexture();
}

ID3D11ShaderResourceView** CTexture_D3D11::getSRVPtr(const Texture::IDType handleID)
{
return m_textures[handleID]->getSRVPtr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ namespace s3d
//
// D3D11
//
ID3D11Texture2D* getTexture(Texture::IDType handleID);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,11 @@ namespace s3d
return m_hasDepth;
}

ID3D11Texture2D* D3D11Texture::getTexture()
{
return m_texture.Get();
}

ID3D11ShaderResourceView** D3D11Texture::getSRVPtr()
{
return m_shaderResourceView.GetAddressOf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ namespace s3d
[[nodiscard]]
bool hasDepth() const noexcept;

[[nodiscard]]
ID3D11Texture2D* getTexture();

[[nodiscard]]
ID3D11ShaderResourceView** getSRVPtr();

Expand Down
20 changes: 20 additions & 0 deletions Siv3D/src/Siv3D/Texture/SivTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
# include <Siv3D/AssetMonitor/IAssetMonitor.hpp>
# include <Siv3D/Common/Siv3DEngine.hpp>

# if SIV3D_PLATFORM(WINDOWS)
# include <Siv3D/Texture/D3D11/CTexture_D3D11.hpp>
# endif

namespace s3d
{
namespace detail
Expand Down Expand Up @@ -631,6 +635,22 @@ namespace s3d
m_handle.swap(other.m_handle);
}

# if SIV3D_PLATFORM(WINDOWS)

ID3D11Texture2D* Texture::getD3D11Texture2D()
{
if (auto p = dynamic_cast<CTexture_D3D11*>(SIV3D_ENGINE(Texture)))
{
return p->getTexture(m_handle->id());
}
else
{
return nullptr;
}
}

# endif

Texture::Texture(Dynamic, const Size& size, const void* pData, const uint32 stride, const TextureFormat& format, const TextureDesc desc)
: AssetHandle{ (detail::CheckEngine(U"DynamicTexture"), std::make_shared<AssetIDWrapperType>(SIV3D_ENGINE(Texture)->createDynamic(size, pData, stride, format, desc)))}
{
Expand Down

0 comments on commit dff7d38

Please sign in to comment.