56 lines
2.0 KiB
C++
56 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <d3d12.h>
|
|
#include <wrl/client.h>
|
|
#include <string>
|
|
|
|
#include "D3D12Enum.h"
|
|
|
|
using Microsoft::WRL::ComPtr;
|
|
|
|
namespace XCEngine {
|
|
namespace RHI {
|
|
|
|
class D3D12Texture {
|
|
public:
|
|
D3D12Texture();
|
|
~D3D12Texture();
|
|
|
|
bool Initialize(ID3D12Device* device, const D3D12_RESOURCE_DESC& desc, D3D12_RESOURCE_STATES initialState = D3D12_RESOURCE_STATE_COMMON);
|
|
bool InitializeFromExisting(ID3D12Resource* resource);
|
|
bool InitializeFromData(ID3D12Device* device, ID3D12GraphicsCommandList* commandList,
|
|
const void* pixelData, uint32_t width, uint32_t height, DXGI_FORMAT format);
|
|
bool InitializeDepthStencil(ID3D12Device* device, uint32_t width, uint32_t height, DXGI_FORMAT format = DXGI_FORMAT_D24_UNORM_S8_UINT);
|
|
void Shutdown();
|
|
|
|
ID3D12Resource* GetResource() const { return m_resource.Get(); }
|
|
D3D12_RESOURCE_DESC GetDesc() const { return m_resource->GetDesc(); }
|
|
|
|
uint32_t GetWidth() const { return static_cast<uint32_t>(GetDesc().Width); }
|
|
uint32_t GetHeight() const { return GetDesc().Height; }
|
|
uint32_t GetDepth() const { return GetDesc().DepthOrArraySize; }
|
|
uint32_t GetMipLevels() const { return GetDesc().MipLevels; }
|
|
|
|
void* GetNativeHandle() const { return m_resource.Get(); }
|
|
ResourceStates GetState() const { return m_state; }
|
|
void SetState(ResourceStates state) { m_state = state; }
|
|
|
|
uint64_t GetGPUAddress() const { return m_resource->GetGPUVirtualAddress(); }
|
|
size_t GetSize() const { return GetDesc().Width * GetDesc().Height * GetDesc().DepthOrArraySize; }
|
|
|
|
const std::string& GetName() const { return m_name; }
|
|
void SetName(const std::string& name) { m_name = name; }
|
|
|
|
uint32_t GetArraySize() const { return GetDesc().DepthOrArraySize; }
|
|
Format GetFormat() const { return static_cast<Format>(GetDesc().Format); }
|
|
TextureType GetTextureType() const { return TextureType::Texture2D; }
|
|
|
|
private:
|
|
ComPtr<ID3D12Resource> m_resource;
|
|
ResourceStates m_state = ResourceStates::Common;
|
|
std::string m_name;
|
|
};
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|