2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2019-11-03 14:39:25 +00:00
|
|
|
#pragma once
|
2022-10-03 06:44:34 +00:00
|
|
|
#include "../gpu_texture.h"
|
2020-01-10 03:31:12 +00:00
|
|
|
#include "../windows_headers.h"
|
2019-11-03 14:39:25 +00:00
|
|
|
#include <d3d11.h>
|
|
|
|
#include <wrl/client.h>
|
|
|
|
|
|
|
|
namespace D3D11 {
|
2022-10-03 06:44:34 +00:00
|
|
|
|
|
|
|
class Texture final : public GPUTexture
|
2019-11-03 14:39:25 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
using ComPtr = Microsoft::WRL::ComPtr<T>;
|
|
|
|
|
|
|
|
Texture();
|
|
|
|
Texture(ComPtr<ID3D11Texture2D> texture, ComPtr<ID3D11ShaderResourceView> srv, ComPtr<ID3D11RenderTargetView> rtv);
|
|
|
|
~Texture();
|
|
|
|
|
2022-10-03 06:44:34 +00:00
|
|
|
static DXGI_FORMAT GetDXGIFormat(Format format);
|
|
|
|
static Format LookupBaseFormat(DXGI_FORMAT dformat);
|
|
|
|
|
2019-11-03 14:39:25 +00:00
|
|
|
ALWAYS_INLINE ID3D11Texture2D* GetD3DTexture() const { return m_texture.Get(); }
|
|
|
|
ALWAYS_INLINE ID3D11ShaderResourceView* GetD3DSRV() const { return m_srv.Get(); }
|
|
|
|
ALWAYS_INLINE ID3D11RenderTargetView* GetD3DRTV() const { return m_rtv.Get(); }
|
|
|
|
ALWAYS_INLINE ID3D11ShaderResourceView* const* GetD3DSRVArray() const { return m_srv.GetAddressOf(); }
|
|
|
|
ALWAYS_INLINE ID3D11RenderTargetView* const* GetD3DRTVArray() const { return m_rtv.GetAddressOf(); }
|
2022-10-03 06:44:34 +00:00
|
|
|
ALWAYS_INLINE DXGI_FORMAT GetDXGIFormat() const { return GetDXGIFormat(m_format); }
|
|
|
|
ALWAYS_INLINE bool IsDynamic() const { return m_dynamic; }
|
2019-11-03 14:39:25 +00:00
|
|
|
|
|
|
|
ALWAYS_INLINE operator ID3D11Texture2D*() const { return m_texture.Get(); }
|
|
|
|
ALWAYS_INLINE operator ID3D11ShaderResourceView*() const { return m_srv.Get(); }
|
|
|
|
ALWAYS_INLINE operator ID3D11RenderTargetView*() const { return m_rtv.Get(); }
|
|
|
|
ALWAYS_INLINE operator bool() const { return static_cast<bool>(m_texture); }
|
|
|
|
|
2022-10-03 06:44:34 +00:00
|
|
|
D3D11_TEXTURE2D_DESC GetDesc() const;
|
|
|
|
|
|
|
|
bool IsValid() const override;
|
|
|
|
|
|
|
|
bool Create(ID3D11Device* device, u32 width, u32 height, u32 layers, u32 levels, u32 samples, Format format,
|
2021-05-30 04:04:30 +00:00
|
|
|
u32 bind_flags, const void* initial_data = nullptr, u32 initial_data_stride = 0, bool dynamic = false);
|
2019-11-03 14:39:25 +00:00
|
|
|
bool Adopt(ID3D11Device* device, ComPtr<ID3D11Texture2D> texture);
|
|
|
|
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ComPtr<ID3D11Texture2D> m_texture;
|
|
|
|
ComPtr<ID3D11ShaderResourceView> m_srv;
|
|
|
|
ComPtr<ID3D11RenderTargetView> m_rtv;
|
2022-10-03 06:44:34 +00:00
|
|
|
bool m_dynamic = false;
|
2019-11-03 14:39:25 +00:00
|
|
|
};
|
2022-10-03 06:44:34 +00:00
|
|
|
|
2019-11-03 14:39:25 +00:00
|
|
|
} // namespace D3D11
|