diff --git a/MAGE/FPS/src/core/FPS.cpp b/MAGE/FPS/src/core/FPS.cpp index c36fe4c23..94f360ece 100644 --- a/MAGE/FPS/src/core/FPS.cpp +++ b/MAGE/FPS/src/core/FPS.cpp @@ -72,7 +72,7 @@ class TestScene : public Scene { AddScript(test_script); //TODO - SpriteFont font(*(g_engine->GetRenderer().GetDevice().Get()), L"assets/fonts/calibri.spritefont", SpriteFontDescriptor()); + SpriteFont font(g_engine->GetRenderer().GetDevice(), L"assets/fonts/calibri.spritefont", SpriteFontDescriptor()); } private: @@ -116,7 +116,7 @@ int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE, LPSTR, int nCmdShow) { // Create the engine, then run it. g_engine = new Engine(setup); g_engine->Run(nCmdShow); - delete g_engine; + SAFE_DELETE(g_engine); return 0; } diff --git a/MAGE/MAGE/src/core/version.hpp b/MAGE/MAGE/src/core/version.hpp index f11966462..0db5bf80a 100644 --- a/MAGE/MAGE/src/core/version.hpp +++ b/MAGE/MAGE/src/core/version.hpp @@ -6,7 +6,7 @@ #pragma region #define MAGE_VERSION_MAJOR 0 -#define MAGE_VERSION_MINOR 11 +#define MAGE_VERSION_MINOR 12 #define MAGE_VERSION_PATCH 0 #define MAGE_QUOTE(S) #S diff --git a/MAGE/MAGE/src/mesh/mesh.hpp b/MAGE/MAGE/src/mesh/mesh.hpp index 83ac6ced6..59e076c7f 100644 --- a/MAGE/MAGE/src/mesh/mesh.hpp +++ b/MAGE/MAGE/src/mesh/mesh.hpp @@ -118,7 +118,7 @@ namespace mage { @param[in] primitive_topology The primitive topology. */ - Mesh(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, size_t vertex_size, + Mesh(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, size_t vertex_size, DXGI_FORMAT index_format = DXGI_FORMAT_R32_UINT, D3D11_PRIMITIVE_TOPOLOGY primitive_topology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST) : m_device(device), m_device_context(device_context), @@ -148,7 +148,7 @@ namespace mage { /** A pointer to the device of this mesh. */ - ComPtr< ID3D11Device2 > m_device; + ID3D11Device2 * const m_device; /** A pointer to the vertex buffer of this mesh. @@ -201,7 +201,7 @@ namespace mage { /** A pointer to the device context of this mesh. */ - ComPtr< ID3D11DeviceContext2 > m_device_context; + ID3D11DeviceContext2 * const m_device_context; /** The vertex size of this static mesh. diff --git a/MAGE/MAGE/src/mesh/sprite_batch_mesh.cpp b/MAGE/MAGE/src/mesh/sprite_batch_mesh.cpp index 4ad16d6be..388e0f1fd 100644 --- a/MAGE/MAGE/src/mesh/sprite_batch_mesh.cpp +++ b/MAGE/MAGE/src/mesh/sprite_batch_mesh.cpp @@ -16,7 +16,7 @@ //----------------------------------------------------------------------------- namespace mage { - SpriteBatchMesh::SpriteBatchMesh(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context) + SpriteBatchMesh::SpriteBatchMesh(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context) : Mesh(device, device_context, sizeof(VertexPositionColorTexture), DXGI_FORMAT_R16_UINT) { const HRESULT result_vertex_buffer = SetupVertexBuffer(); @@ -33,7 +33,7 @@ namespace mage { } HRESULT SpriteBatchMesh::SetupVertexBuffer() { - const HRESULT result_vertex_buffer = CreateDynamicVertexBuffer< VertexPositionColorTexture >(*m_device.Get(), m_vertex_buffer.ReleaseAndGetAddressOf(), nullptr, MaxVerticesPerSprite()); + const HRESULT result_vertex_buffer = CreateDynamicVertexBuffer< VertexPositionColorTexture >(m_device, m_vertex_buffer.ReleaseAndGetAddressOf(), nullptr, MaxVerticesPerSprite()); if (FAILED(result_vertex_buffer)) { Error("Vertex buffer creation failed: %08X.", result_vertex_buffer); return result_vertex_buffer; @@ -59,7 +59,7 @@ namespace mage { indices.push_back(i + 2); } - const HRESULT result_index_buffer = CreateIndexBuffer< uint16_t >(*m_device.Get(), m_index_buffer.ReleaseAndGetAddressOf(), indices.data(), indices.size()); + const HRESULT result_index_buffer = CreateIndexBuffer< uint16_t >(m_device, m_index_buffer.ReleaseAndGetAddressOf(), indices.data(), indices.size()); if (FAILED(result_index_buffer)) { Error("Index buffer creation failed: %08X.", result_index_buffer); return result_index_buffer; diff --git a/MAGE/MAGE/src/mesh/sprite_batch_mesh.hpp b/MAGE/MAGE/src/mesh/sprite_batch_mesh.hpp index 829a38b7a..5dc2a2559 100644 --- a/MAGE/MAGE/src/mesh/sprite_batch_mesh.hpp +++ b/MAGE/MAGE/src/mesh/sprite_batch_mesh.hpp @@ -42,7 +42,7 @@ namespace mage { /** Constructs a sprite batch mesh. */ - SpriteBatchMesh(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context); + SpriteBatchMesh(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context); /** Destructs this sprite batch mesh. diff --git a/MAGE/MAGE/src/mesh/static_mesh.cpp b/MAGE/MAGE/src/mesh/static_mesh.cpp index 59e83020b..9619af341 100644 --- a/MAGE/MAGE/src/mesh/static_mesh.cpp +++ b/MAGE/MAGE/src/mesh/static_mesh.cpp @@ -15,7 +15,7 @@ namespace mage { HRESULT StaticMesh::SetupIndexBuffer(const uint32_t *indices, size_t nb_indices) { - const HRESULT result_index_buffer = CreateIndexBuffer< uint32_t >(*m_device.Get(), m_index_buffer.ReleaseAndGetAddressOf(), indices, nb_indices); + const HRESULT result_index_buffer = CreateIndexBuffer< uint32_t >(m_device, m_index_buffer.ReleaseAndGetAddressOf(), indices, nb_indices); if (FAILED(result_index_buffer)) { Error("Index buffer creation failed: %08X.", result_index_buffer); return result_index_buffer; diff --git a/MAGE/MAGE/src/mesh/static_mesh.hpp b/MAGE/MAGE/src/mesh/static_mesh.hpp index d7ab58e0c..64e28fa95 100644 --- a/MAGE/MAGE/src/mesh/static_mesh.hpp +++ b/MAGE/MAGE/src/mesh/static_mesh.hpp @@ -43,7 +43,7 @@ namespace mage { The number of indices. */ template < typename VertexT > - StaticMesh(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + StaticMesh(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const VertexT *vertices, size_t nb_vertices, const uint32_t *indices, size_t nb_indices); @@ -64,7 +64,7 @@ namespace mage { A reference to a vector of indices. */ template < typename VertexT > - StaticMesh(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + StaticMesh(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const vector< VertexT > &vertices, const vector< uint32_t > &indices) : StaticMesh(device, device_context, vertices.data(), vertices.size(), diff --git a/MAGE/MAGE/src/mesh/static_mesh.tpp b/MAGE/MAGE/src/mesh/static_mesh.tpp index 2395a3a11..5003f8138 100644 --- a/MAGE/MAGE/src/mesh/static_mesh.tpp +++ b/MAGE/MAGE/src/mesh/static_mesh.tpp @@ -16,7 +16,7 @@ namespace mage { template < typename VertexT > - StaticMesh::StaticMesh(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + StaticMesh::StaticMesh(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const VertexT *vertices, size_t nb_vertices, const uint32_t *indices, size_t nb_indices) : Mesh(device, device_context, sizeof(VertexT)) { @@ -35,7 +35,7 @@ namespace mage { template < typename VertexT > HRESULT StaticMesh::SetupVertexBuffer(const VertexT *vertices, size_t nb_vertices) { - const HRESULT result_vertex_buffer = CreateStaticVertexBuffer< VertexT >(*m_device.Get(), m_vertex_buffer.ReleaseAndGetAddressOf(), vertices, nb_vertices); + const HRESULT result_vertex_buffer = CreateStaticVertexBuffer< VertexT >(m_device, m_vertex_buffer.ReleaseAndGetAddressOf(), vertices, nb_vertices); if (FAILED(result_vertex_buffer)) { Error("Vertex buffer creation failed: %08X.", result_vertex_buffer); return result_vertex_buffer; diff --git a/MAGE/MAGE/src/model/model.hpp b/MAGE/MAGE/src/model/model.hpp index f20a2fa83..bec027a77 100644 --- a/MAGE/MAGE/src/model/model.hpp +++ b/MAGE/MAGE/src/model/model.hpp @@ -89,9 +89,7 @@ namespace mage { m_material(std::move(submodel.m_material)) { submodel.m_material = nullptr; } - virtual ~SubModel() { - delete m_material; - } + virtual ~SubModel() = default; virtual SubModel *Clone() const { return new SubModel(*this); @@ -126,7 +124,7 @@ namespace mage { const size_t m_start_index; const size_t m_nb_indices; - ShadedMaterial *m_material; + UniquePtr< ShadedMaterial > m_material; }; } diff --git a/MAGE/MAGE/src/model/model_descriptor.cpp b/MAGE/MAGE/src/model/model_descriptor.cpp index 8711b4525..3c4efc5ff 100644 --- a/MAGE/MAGE/src/model/model_descriptor.cpp +++ b/MAGE/MAGE/src/model/model_descriptor.cpp @@ -12,10 +12,10 @@ //----------------------------------------------------------------------------- namespace mage { - ComPtr< ID3D11Device2 > GetModelRenderingDevice() { + ID3D11Device2 *GetModelRenderingDevice() { return GetRenderingDevice(); } - ComPtr< ID3D11DeviceContext2 > GetModelRenderingDeviceContext() { + ID3D11DeviceContext2 *GetModelRenderingDeviceContext() { return GetRenderingDeviceContext(); } ResourceFactory &GetModelResourceFactory() { diff --git a/MAGE/MAGE/src/model/model_descriptor.hpp b/MAGE/MAGE/src/model/model_descriptor.hpp index b222c40db..35e41c6ec 100644 --- a/MAGE/MAGE/src/model/model_descriptor.hpp +++ b/MAGE/MAGE/src/model/model_descriptor.hpp @@ -20,7 +20,7 @@ namespace mage { public: template < typename VertexT > - ModelDescriptor(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + ModelDescriptor(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &fname, const MeshDescriptor< VertexT > &desc = MeshDescriptor< VertexT >()); virtual ~ModelDescriptor() { m_materials.clear(); diff --git a/MAGE/MAGE/src/model/model_descriptor.tpp b/MAGE/MAGE/src/model/model_descriptor.tpp index 6f0e071a5..e90e2cd77 100644 --- a/MAGE/MAGE/src/model/model_descriptor.tpp +++ b/MAGE/MAGE/src/model/model_descriptor.tpp @@ -6,7 +6,7 @@ namespace mage { template < typename VertexT > - ModelDescriptor::ModelDescriptor(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + ModelDescriptor::ModelDescriptor(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &fname, const MeshDescriptor< VertexT > &desc) : FileResource(fname) { @@ -24,14 +24,14 @@ namespace mage { // Forward declarations class ResourceFactory; - ComPtr< ID3D11Device2 > GetModelRenderingDevice(); - ComPtr< ID3D11DeviceContext2 > GetModelRenderingDeviceContext(); + ID3D11Device2 *GetModelRenderingDevice(); + ID3D11DeviceContext2 *GetModelRenderingDeviceContext(); ResourceFactory &GetModelResourceFactory(); template < typename VertexT > SharedPtr< ModelDescriptor > CreateModelDescriptor(const wstring &fname, const MeshDescriptor< VertexT > &desc) { - ComPtr< ID3D11Device2 > device = GetModelRenderingDevice(); - ComPtr< ID3D11DeviceContext2 > device_context = GetModelRenderingDeviceContext(); + ID3D11Device2 *device = GetModelRenderingDevice(); + ID3D11DeviceContext2 *device_context = GetModelRenderingDeviceContext(); ResourceFactory &factory = GetModelResourceFactory(); return factory.CreateModelDescriptor(device, device_context, fname, desc); } diff --git a/MAGE/MAGE/src/rendering/renderer.cpp b/MAGE/MAGE/src/rendering/renderer.cpp index 0a68938de..48c52ba49 100644 --- a/MAGE/MAGE/src/rendering/renderer.cpp +++ b/MAGE/MAGE/src/rendering/renderer.cpp @@ -243,8 +243,8 @@ namespace mage { } void Renderer::SetupRenderingState() { - m_rendering_state_cache = SharedPtr< RenderingStateCache >(new RenderingStateCache(m_device2)); - m_rendering_state = make_unique< RenderingState >(m_device2, m_device_context2, m_rendering_state_cache); + m_rendering_state_cache = make_unique< RenderingStateCache >(m_device2.Get()); + m_rendering_state = make_unique< RenderingState >(m_device2.Get(), m_device_context2.Get(), m_rendering_state_cache.get()); m_rendering_state->SetDefaultRenderingState3D(); } diff --git a/MAGE/MAGE/src/rendering/renderer.hpp b/MAGE/MAGE/src/rendering/renderer.hpp index a94b72830..39ee84f22 100644 --- a/MAGE/MAGE/src/rendering/renderer.hpp +++ b/MAGE/MAGE/src/rendering/renderer.hpp @@ -76,8 +76,8 @@ namespace mage { @return A pointer to the device of this renderer. */ - ComPtr< ID3D11Device2 > GetDevice() const { - return m_device2; + ID3D11Device2 *GetDevice() const { + return m_device2.Get(); } /** @@ -85,8 +85,8 @@ namespace mage { @return A pointer to the device context of this renderer. */ - ComPtr< ID3D11DeviceContext2 > GetDeviceContext() const { - return m_device_context2; + ID3D11DeviceContext2 *GetDeviceContext() const { + return m_device_context2.Get(); } /** @@ -266,6 +266,6 @@ namespace mage { ComPtr< ID3D11Texture2D > m_depth_stencil; ComPtr< ID3D11DepthStencilView > m_depth_stencil_view; UniquePtr< RenderingState > m_rendering_state; - SharedPtr< RenderingStateCache > m_rendering_state_cache; + UniquePtr< RenderingStateCache > m_rendering_state_cache; }; } \ No newline at end of file diff --git a/MAGE/MAGE/src/rendering/rendering_factory.cpp b/MAGE/MAGE/src/rendering/rendering_factory.cpp index b7c16692f..227721a2b 100644 --- a/MAGE/MAGE/src/rendering/rendering_factory.cpp +++ b/MAGE/MAGE/src/rendering/rendering_factory.cpp @@ -16,7 +16,7 @@ namespace mage { // Blend states //------------------------------------------------------------------------- - HRESULT CreateBlendState(ID3D11Device2 &device, ID3D11BlendState **blend_state, D3D11_BLEND src_blend, D3D11_BLEND dest_blend) { + HRESULT CreateBlendState(ID3D11Device2 *device, ID3D11BlendState **blend_state, D3D11_BLEND src_blend, D3D11_BLEND dest_blend) { D3D11_BLEND_DESC desc; ZeroMemory(&desc, sizeof(desc)); @@ -29,18 +29,18 @@ namespace mage { desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; - return device.CreateBlendState(&desc, blend_state); + return device->CreateBlendState(&desc, blend_state); } - HRESULT CreateOpaqueBlendState(ID3D11Device2 &device, ID3D11BlendState **blend_state) { + HRESULT CreateOpaqueBlendState(ID3D11Device2 *device, ID3D11BlendState **blend_state) { return CreateBlendState(device, blend_state, D3D11_BLEND_ONE, D3D11_BLEND_ZERO); } - HRESULT CreateAlphaBlendState(ID3D11Device2 &device, ID3D11BlendState **blend_state) { + HRESULT CreateAlphaBlendState(ID3D11Device2 *device, ID3D11BlendState **blend_state) { return CreateBlendState(device, blend_state, D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA); } - HRESULT CreateAdditiveBlendState(ID3D11Device2 &device, ID3D11BlendState **blend_state) { + HRESULT CreateAdditiveBlendState(ID3D11Device2 *device, ID3D11BlendState **blend_state) { return CreateBlendState(device, blend_state, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_ONE); } - HRESULT CreateNonPremultipliedBlendState(ID3D11Device2 &device, ID3D11BlendState **blend_state) { + HRESULT CreateNonPremultipliedBlendState(ID3D11Device2 *device, ID3D11BlendState **blend_state) { return CreateBlendState(device, blend_state, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA); } @@ -48,7 +48,7 @@ namespace mage { // Depth stencil states //------------------------------------------------------------------------- - HRESULT CreateDepthStencilState(ID3D11Device2 &device, ID3D11DepthStencilState **depth_stencil_state, bool enable, bool write_enable) { + HRESULT CreateDepthStencilState(ID3D11Device2 *device, ID3D11DepthStencilState **depth_stencil_state, bool enable, bool write_enable) { D3D11_DEPTH_STENCIL_DESC desc; ZeroMemory(&desc, sizeof(desc)); @@ -67,15 +67,15 @@ namespace mage { desc.BackFace = desc.FrontFace; - return device.CreateDepthStencilState(&desc, depth_stencil_state); + return device->CreateDepthStencilState(&desc, depth_stencil_state); } - HRESULT CreateDepthNoneDepthStencilState(ID3D11Device2 &device, ID3D11DepthStencilState **depth_stencil_state) { + HRESULT CreateDepthNoneDepthStencilState(ID3D11Device2 *device, ID3D11DepthStencilState **depth_stencil_state) { return CreateDepthStencilState(device, depth_stencil_state, false, false); } - HRESULT CreateDepthDefaultDepthStencilState(ID3D11Device2 &device, ID3D11DepthStencilState **depth_stencil_state) { + HRESULT CreateDepthDefaultDepthStencilState(ID3D11Device2 *device, ID3D11DepthStencilState **depth_stencil_state) { return CreateDepthStencilState(device, depth_stencil_state, true, true); } - HRESULT CreateDepthReadDepthStencilState(ID3D11Device2 &device, ID3D11DepthStencilState **depth_stencil_state) { + HRESULT CreateDepthReadDepthStencilState(ID3D11Device2 *device, ID3D11DepthStencilState **depth_stencil_state) { return CreateDepthStencilState(device, depth_stencil_state, true, false); } @@ -83,7 +83,7 @@ namespace mage { // Rasterizer states //------------------------------------------------------------------------- - HRESULT CreateRasterizerState(ID3D11Device2 &device, ID3D11RasterizerState **rasterizer_state, D3D11_CULL_MODE cull_mode, D3D11_FILL_MODE fill_mode) { + HRESULT CreateRasterizerState(ID3D11Device2 *device, ID3D11RasterizerState **rasterizer_state, D3D11_CULL_MODE cull_mode, D3D11_FILL_MODE fill_mode) { D3D11_RASTERIZER_DESC desc; ZeroMemory(&desc, sizeof(desc)); @@ -92,18 +92,18 @@ namespace mage { desc.DepthClipEnable = true; desc.MultisampleEnable = true; - return device.CreateRasterizerState(&desc, rasterizer_state); + return device->CreateRasterizerState(&desc, rasterizer_state); } - HRESULT CreateCullNoneRasterizerState(ID3D11Device2 &device, ID3D11RasterizerState **rasterizer_state) { + HRESULT CreateCullNoneRasterizerState(ID3D11Device2 *device, ID3D11RasterizerState **rasterizer_state) { return CreateRasterizerState(device, rasterizer_state, D3D11_CULL_NONE, D3D11_FILL_SOLID); } - HRESULT CreateCullClockwiseRasterizerState(ID3D11Device2 &device, ID3D11RasterizerState **rasterizer_state) { + HRESULT CreateCullClockwiseRasterizerState(ID3D11Device2 *device, ID3D11RasterizerState **rasterizer_state) { return CreateRasterizerState(device, rasterizer_state, D3D11_CULL_FRONT, D3D11_FILL_SOLID); } - HRESULT CreateCullCounterClockwiseRasterizerState(ID3D11Device2 &device, ID3D11RasterizerState **rasterizer_state) { + HRESULT CreateCullCounterClockwiseRasterizerState(ID3D11Device2 *device, ID3D11RasterizerState **rasterizer_state) { return CreateRasterizerState(device, rasterizer_state, D3D11_CULL_BACK, D3D11_FILL_SOLID); } - HRESULT CreateWireframeRasterizerState(ID3D11Device2 &device, ID3D11RasterizerState **rasterizer_state) { + HRESULT CreateWireframeRasterizerState(ID3D11Device2 *device, ID3D11RasterizerState **rasterizer_state) { return CreateRasterizerState(device, rasterizer_state, D3D11_CULL_NONE, D3D11_FILL_WIREFRAME); } @@ -111,7 +111,7 @@ namespace mage { // Sampler states //------------------------------------------------------------------------- - HRESULT CreateSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state, D3D11_FILTER filter, D3D11_TEXTURE_ADDRESS_MODE address_mode) { + HRESULT CreateSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state, D3D11_FILTER filter, D3D11_TEXTURE_ADDRESS_MODE address_mode) { D3D11_SAMPLER_DESC desc; ZeroMemory(&desc, sizeof(desc)); @@ -121,29 +121,29 @@ namespace mage { desc.AddressV = address_mode; desc.AddressW = address_mode; - desc.MaxAnisotropy = (device.GetFeatureLevel() > D3D_FEATURE_LEVEL_9_1) ? D3D11_MAX_MAXANISOTROPY : 2; + desc.MaxAnisotropy = (device->GetFeatureLevel() > D3D_FEATURE_LEVEL_9_1) ? D3D11_MAX_MAXANISOTROPY : 2; desc.MaxLOD = D3D11_FLOAT32_MAX; desc.ComparisonFunc = D3D11_COMPARISON_NEVER; - return device.CreateSamplerState(&desc, sampler_state); + return device->CreateSamplerState(&desc, sampler_state); } - HRESULT CreatePointWrapSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state) { + HRESULT CreatePointWrapSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state) { return CreateSamplerState(device, sampler_state, D3D11_FILTER_MIN_MAG_MIP_POINT, D3D11_TEXTURE_ADDRESS_WRAP); } - HRESULT CreatePointClampSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state) { + HRESULT CreatePointClampSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state) { return CreateSamplerState(device, sampler_state, D3D11_FILTER_MIN_MAG_MIP_POINT, D3D11_TEXTURE_ADDRESS_CLAMP); } - HRESULT CreateLinearWrapSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state) { + HRESULT CreateLinearWrapSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state) { return CreateSamplerState(device, sampler_state, D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D11_TEXTURE_ADDRESS_WRAP); } - HRESULT CreateLinearClampSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state) { + HRESULT CreateLinearClampSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state) { return CreateSamplerState(device, sampler_state, D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D11_TEXTURE_ADDRESS_CLAMP); } - HRESULT CreateAnisotropicWrapSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state) { + HRESULT CreateAnisotropicWrapSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state) { return CreateSamplerState(device, sampler_state, D3D11_FILTER_ANISOTROPIC, D3D11_TEXTURE_ADDRESS_WRAP); } - HRESULT CreateAnisotropicClampSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state) { + HRESULT CreateAnisotropicClampSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state) { return CreateSamplerState(device, sampler_state, D3D11_FILTER_ANISOTROPIC, D3D11_TEXTURE_ADDRESS_CLAMP); } } \ No newline at end of file diff --git a/MAGE/MAGE/src/rendering/rendering_factory.hpp b/MAGE/MAGE/src/rendering/rendering_factory.hpp index 0988bb587..638549383 100644 --- a/MAGE/MAGE/src/rendering/rendering_factory.hpp +++ b/MAGE/MAGE/src/rendering/rendering_factory.hpp @@ -19,54 +19,54 @@ namespace mage { //------------------------------------------------------------------------- template < typename VertexT > - HRESULT CreateStaticVertexBuffer(ID3D11Device2 &device, ID3D11Buffer **buffer, const VertexT *vertices, size_t nb_vertices); + HRESULT CreateStaticVertexBuffer(ID3D11Device2 *device, ID3D11Buffer **buffer, const VertexT *vertices, size_t nb_vertices); template < typename VertexT > - HRESULT CreateDynamicVertexBuffer(ID3D11Device2 &device, ID3D11Buffer **buffer, const VertexT *vertices, size_t nb_vertices); + HRESULT CreateDynamicVertexBuffer(ID3D11Device2 *device, ID3D11Buffer **buffer, const VertexT *vertices, size_t nb_vertices); template < typename IndexT > - HRESULT CreateIndexBuffer(ID3D11Device2 &device, ID3D11Buffer **buffer, const IndexT *indices, size_t nb_indices); + HRESULT CreateIndexBuffer(ID3D11Device2 *device, ID3D11Buffer **buffer, const IndexT *indices, size_t nb_indices); template < typename BufferT > - HRESULT CreateConstantBuffer(ID3D11Device2 &device, ID3D11Buffer **buffer); + HRESULT CreateConstantBuffer(ID3D11Device2 *device, ID3D11Buffer **buffer); //------------------------------------------------------------------------- // Blend states //------------------------------------------------------------------------- - HRESULT CreateBlendState(ID3D11Device2 &device, ID3D11BlendState **blend_state, D3D11_BLEND src_blend, D3D11_BLEND dest_blend); - HRESULT CreateOpaqueBlendState(ID3D11Device2 &device, ID3D11BlendState **blend_state); - HRESULT CreateAlphaBlendState(ID3D11Device2 &device, ID3D11BlendState **blend_state); - HRESULT CreateAdditiveBlendState(ID3D11Device2 &device, ID3D11BlendState **blend_state); - HRESULT CreateNonPremultipliedBlendState(ID3D11Device2 &device, ID3D11BlendState **blend_state); + HRESULT CreateBlendState(ID3D11Device2 *device, ID3D11BlendState **blend_state, D3D11_BLEND src_blend, D3D11_BLEND dest_blend); + HRESULT CreateOpaqueBlendState(ID3D11Device2 *device, ID3D11BlendState **blend_state); + HRESULT CreateAlphaBlendState(ID3D11Device2 *device, ID3D11BlendState **blend_state); + HRESULT CreateAdditiveBlendState(ID3D11Device2 *device, ID3D11BlendState **blend_state); + HRESULT CreateNonPremultipliedBlendState(ID3D11Device2 *device, ID3D11BlendState **blend_state); //------------------------------------------------------------------------- // Depth stencil states //------------------------------------------------------------------------- - HRESULT CreateDepthStencilState(ID3D11Device2 &device, ID3D11DepthStencilState **depth_stencil_state, bool enable, bool write_enable); - HRESULT CreateDepthNoneDepthStencilState(ID3D11Device2 &device, ID3D11DepthStencilState **depth_stencil_state); - HRESULT CreateDepthDefaultDepthStencilState(ID3D11Device2 &device, ID3D11DepthStencilState **depth_stencil_state); - HRESULT CreateDepthReadDepthStencilState(ID3D11Device2 &device, ID3D11DepthStencilState **depth_stencil_state); + HRESULT CreateDepthStencilState(ID3D11Device2 *device, ID3D11DepthStencilState **depth_stencil_state, bool enable, bool write_enable); + HRESULT CreateDepthNoneDepthStencilState(ID3D11Device2 *device, ID3D11DepthStencilState **depth_stencil_state); + HRESULT CreateDepthDefaultDepthStencilState(ID3D11Device2 *device, ID3D11DepthStencilState **depth_stencil_state); + HRESULT CreateDepthReadDepthStencilState(ID3D11Device2 *device, ID3D11DepthStencilState **depth_stencil_state); //------------------------------------------------------------------------- // Rasterizer states //------------------------------------------------------------------------- - HRESULT CreateRasterizerState(ID3D11Device2 &device, ID3D11RasterizerState **rasterizer_state, D3D11_CULL_MODE cull_mode, D3D11_FILL_MODE fill_mode); - HRESULT CreateCullNoneRasterizerState(ID3D11Device2 &device, ID3D11RasterizerState **rasterizer_state); - HRESULT CreateCullClockwiseRasterizerState(ID3D11Device2 &device, ID3D11RasterizerState **rasterizer_state); - HRESULT CreateCullCounterClockwiseRasterizerState(ID3D11Device2 &device, ID3D11RasterizerState **rasterizer_state); - HRESULT CreateWireframeRasterizerState(ID3D11Device2 &device, ID3D11RasterizerState **rasterizer_state); + HRESULT CreateRasterizerState(ID3D11Device2 *device, ID3D11RasterizerState **rasterizer_state, D3D11_CULL_MODE cull_mode, D3D11_FILL_MODE fill_mode); + HRESULT CreateCullNoneRasterizerState(ID3D11Device2 *device, ID3D11RasterizerState **rasterizer_state); + HRESULT CreateCullClockwiseRasterizerState(ID3D11Device2 *device, ID3D11RasterizerState **rasterizer_state); + HRESULT CreateCullCounterClockwiseRasterizerState(ID3D11Device2 *device, ID3D11RasterizerState **rasterizer_state); + HRESULT CreateWireframeRasterizerState(ID3D11Device2 *device, ID3D11RasterizerState **rasterizer_state); //------------------------------------------------------------------------- // Sampler states //------------------------------------------------------------------------- - HRESULT CreateSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state, D3D11_FILTER filter, D3D11_TEXTURE_ADDRESS_MODE address_mode); - HRESULT CreatePointWrapSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state); - HRESULT CreatePointClampSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state); - HRESULT CreateLinearWrapSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state); - HRESULT CreateLinearClampSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state); - HRESULT CreateAnisotropicWrapSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state); - HRESULT CreateAnisotropicClampSamplerState(ID3D11Device2 &device, ID3D11SamplerState **sampler_state); + HRESULT CreateSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state, D3D11_FILTER filter, D3D11_TEXTURE_ADDRESS_MODE address_mode); + HRESULT CreatePointWrapSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state); + HRESULT CreatePointClampSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state); + HRESULT CreateLinearWrapSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state); + HRESULT CreateLinearClampSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state); + HRESULT CreateAnisotropicWrapSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state); + HRESULT CreateAnisotropicClampSamplerState(ID3D11Device2 *device, ID3D11SamplerState **sampler_state); } //----------------------------------------------------------------------------- diff --git a/MAGE/MAGE/src/rendering/rendering_factory.tpp b/MAGE/MAGE/src/rendering/rendering_factory.tpp index 28b6100df..5884a5f4a 100644 --- a/MAGE/MAGE/src/rendering/rendering_factory.tpp +++ b/MAGE/MAGE/src/rendering/rendering_factory.tpp @@ -10,7 +10,7 @@ namespace mage { //------------------------------------------------------------------------- template < typename VertexT > - inline HRESULT CreateStaticVertexBuffer(ID3D11Device2 &device, ID3D11Buffer **buffer, const VertexT *vertices, size_t nb_vertices) { + inline HRESULT CreateStaticVertexBuffer(ID3D11Device2 *device, ID3D11Buffer **buffer, const VertexT *vertices, size_t nb_vertices) { // Describe the buffer resource. D3D11_BUFFER_DESC buffer_desc; ZeroMemory(&buffer_desc, sizeof(buffer_desc)); @@ -28,11 +28,11 @@ namespace mage { // 1. A pointer to a D3D11_BUFFER_DESC structure that describes the buffer. // 2. A pointer to a D3D11_SUBRESOURCE_DATA structure that describes the initialization data. // 3. Address of a pointer to the ID3D11Buffer interface for the buffer object created. - return device.CreateBuffer(&buffer_desc, &init_data, buffer); + return device->CreateBuffer(&buffer_desc, &init_data, buffer); } template < typename VertexT > - inline HRESULT CreateDynamicVertexBuffer(ID3D11Device2 &device, ID3D11Buffer **buffer, const VertexT *vertices, size_t nb_vertices) { + inline HRESULT CreateDynamicVertexBuffer(ID3D11Device2 *device, ID3D11Buffer **buffer, const VertexT *vertices, size_t nb_vertices) { // Describe the buffer resource. D3D11_BUFFER_DESC buffer_desc; ZeroMemory(&buffer_desc, sizeof(buffer_desc)); @@ -50,11 +50,11 @@ namespace mage { // 1. A pointer to a D3D11_BUFFER_DESC structure that describes the buffer. // 2. A pointer to a D3D11_SUBRESOURCE_DATA structure that describes the initialization data. // 3. Address of a pointer to the ID3D11Buffer interface for the buffer object created. - return device.CreateBuffer(&buffer_desc, &init_data, buffer); + return device->CreateBuffer(&buffer_desc, &init_data, buffer); } template < typename IndexT > - inline HRESULT CreateIndexBuffer(ID3D11Device2 &device, ID3D11Buffer **buffer, const IndexT *indices, size_t nb_indices) { + inline HRESULT CreateIndexBuffer(ID3D11Device2 *device, ID3D11Buffer **buffer, const IndexT *indices, size_t nb_indices) { // Describe the buffer resource. D3D11_BUFFER_DESC buffer_desc; ZeroMemory(&buffer_desc, sizeof(buffer_desc)); @@ -72,11 +72,11 @@ namespace mage { // 1. A pointer to a D3D11_BUFFER_DESC structure that describes the buffer. // 2. A pointer to a D3D11_SUBRESOURCE_DATA structure that describes the initialization data. // 3. Address of a pointer to the ID3D11Buffer interface for the buffer object created. - return device.CreateBuffer(&buffer_desc, &init_data, buffer); + return device->CreateBuffer(&buffer_desc, &init_data, buffer); } template < typename BufferT > - inline HRESULT CreateConstantBuffer(ID3D11Device2 &device, ID3D11Buffer **buffer) { + inline HRESULT CreateConstantBuffer(ID3D11Device2 *device, ID3D11Buffer **buffer) { // Describe the buffer resource. D3D11_BUFFER_DESC buffer_desc; ZeroMemory(&buffer_desc, sizeof(buffer_desc)); @@ -89,6 +89,6 @@ namespace mage { // 1. A pointer to a D3D11_BUFFER_DESC structure that describes the buffer. // 2. A pointer to a D3D11_SUBRESOURCE_DATA structure that describes the initialization data. // 3. Address of a pointer to the ID3D11Buffer interface for the buffer object created. - return device.CreateBuffer(&buffer_desc, nullptr, buffer); + return device->CreateBuffer(&buffer_desc, nullptr, buffer); } } \ No newline at end of file diff --git a/MAGE/MAGE/src/rendering/rendering_state.cpp b/MAGE/MAGE/src/rendering/rendering_state.cpp index 44e57e834..80cdba018 100644 --- a/MAGE/MAGE/src/rendering/rendering_state.cpp +++ b/MAGE/MAGE/src/rendering/rendering_state.cpp @@ -11,15 +11,15 @@ #pragma endregion //----------------------------------------------------------------------------- -// Engine Declarations and Definitions +// Engine Definitions //----------------------------------------------------------------------------- namespace mage { void RenderingState::Render() { - m_device_context->OMSetBlendState(m_blend_state.Get(), nullptr, 0xFFFFFFFF); - m_device_context->OMSetDepthStencilState(m_depth_stencil_state.Get(), 0); - m_device_context->RSSetState(m_rasterizer_state.Get()); - m_device_context->PSSetSamplers(0, 1, m_sampler_state.GetAddressOf()); + m_device_context->OMSetBlendState(m_blend_state, nullptr, 0xFFFFFFFF); + m_device_context->OMSetDepthStencilState(m_depth_stencil_state, 0); + m_device_context->RSSetState(m_rasterizer_state); + m_device_context->PSSetSamplers(0, 1, &m_sampler_state); } void RenderingState::SetDefaultRenderingState2D() { @@ -39,7 +39,7 @@ namespace mage { // Blend state //------------------------------------------------------------------------- - void RenderingState::SetBlendState(ComPtr< ID3D11BlendState > blend_state) { + void RenderingState::SetBlendState(ID3D11BlendState *blend_state) { Assert(blend_state); m_blend_state = blend_state; } @@ -60,7 +60,7 @@ namespace mage { // Depth stencil state //------------------------------------------------------------------------- - void RenderingState::SetDepthStencilState(ComPtr< ID3D11DepthStencilState > depth_stencil_state) { + void RenderingState::SetDepthStencilState(ID3D11DepthStencilState *depth_stencil_state) { Assert(depth_stencil_state); m_depth_stencil_state = depth_stencil_state; } @@ -78,7 +78,7 @@ namespace mage { // Rasterizer state //------------------------------------------------------------------------- - void RenderingState::SetRasterizerState(ComPtr< ID3D11RasterizerState > rasterizer_state) { + void RenderingState::SetRasterizerState(ID3D11RasterizerState *rasterizer_state) { Assert(rasterizer_state); m_rasterizer_state = rasterizer_state; } @@ -99,7 +99,7 @@ namespace mage { // Sampler state //------------------------------------------------------------------------- - void RenderingState::SetSamplerState(ComPtr< ID3D11SamplerState > sampler_state) { + void RenderingState::SetSamplerState(ID3D11SamplerState *sampler_state) { Assert(sampler_state); m_sampler_state = sampler_state; } diff --git a/MAGE/MAGE/src/rendering/rendering_state.hpp b/MAGE/MAGE/src/rendering/rendering_state.hpp index b1e8a1054..7a3d7d1a3 100644 --- a/MAGE/MAGE/src/rendering/rendering_state.hpp +++ b/MAGE/MAGE/src/rendering/rendering_state.hpp @@ -18,15 +18,12 @@ namespace mage { public: - RenderingState(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, SharedPtr< RenderingStateCache > rendering_state_cache) + RenderingState(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, RenderingStateCache *rendering_state_cache) : m_device(device), m_device_context(device_context), m_rendering_state_cache(rendering_state_cache) {} RenderingState(const RenderingState &rendering_state) = default; RenderingState(RenderingState &&rendering_state) = default; ~RenderingState() = default; - RenderingState &operator=(const RenderingState &rendering_state) = default; - RenderingState &operator=(RenderingState &&rendering_state) = default; - void Render(); void SetDefaultRenderingState2D(); @@ -36,90 +33,93 @@ namespace mage { // Blend state //--------------------------------------------------------------------- - void SetBlendState(ComPtr< ID3D11BlendState > blend_state); + void SetBlendState(ID3D11BlendState *blend_state); void SetOpaqueBlendState(); void SetAlphaBlendState(); void SetAdditiveBlendState(); void SetNonPremultipliedBlendState(); - ID3D11BlendState &GetBlendState() const { - return *m_blend_state.Get(); + ID3D11BlendState *GetBlendState() const { + return m_blend_state; } //--------------------------------------------------------------------- // Depth stencil state //--------------------------------------------------------------------- - void SetDepthStencilState(ComPtr< ID3D11DepthStencilState > depth_stencil_state); + void SetDepthStencilState(ID3D11DepthStencilState *depth_stencil_state); void SetDepthNoneDepthStencilState(); void SetDepthDefaultDepthStencilState(); void SetDepthReadDepthStencilState(); - ID3D11DepthStencilState &GetDepthStencilState() const { - return *m_depth_stencil_state.Get(); + ID3D11DepthStencilState *GetDepthStencilState() const { + return m_depth_stencil_state; } //--------------------------------------------------------------------- // Rasterizer state //--------------------------------------------------------------------- - void SetRasterizerState(ComPtr< ID3D11RasterizerState > rasterizer_state); + void SetRasterizerState(ID3D11RasterizerState *rasterizer_state); void SetCullNoneRasterizerState(); void SetCullClockwiseRasterizerState(); void SetCullCounterClockwiseRasterizerState(); void SetWireframeRasterizerState(); - ID3D11RasterizerState &GetRasterizerState() const { - return *m_rasterizer_state.Get(); + ID3D11RasterizerState *GetRasterizerState() const { + return m_rasterizer_state; } //------------------------------------------------------------------------- // Sampler state //------------------------------------------------------------------------- - void SetSamplerState(ComPtr< ID3D11SamplerState > sampler_state); + void SetSamplerState(ID3D11SamplerState *sampler_state); void SetPointWrapSamplerState(); void SetPointClampSamplerState(); void SetLinearWrapSamplerState(); void SetLinearClampSamplerState(); void SetAnisotropicWrapSamplerState(); void SetAnisotropicClampSamplerState(); - ID3D11SamplerState &GetSamplerState() const { - return *m_sampler_state.Get(); + ID3D11SamplerState *GetSamplerState() const { + return m_sampler_state; } private: + RenderingState &operator=(const RenderingState &rendering_state) = delete; + RenderingState &operator=(RenderingState &&rendering_state) = delete; + /** - The device of this rendering state. + A pointer to the device of this rendering state. */ - ComPtr< ID3D11Device2 > m_device; + ID3D11Device2 * const m_device; /** - The device context of this rendering state. + A pointer to the device context of this rendering state. */ - ComPtr< ID3D11DeviceContext2 > m_device_context; + ID3D11DeviceContext2 * const m_device_context; /** - The rendering state cache of this rendering state. + A pointer to the rendering state cache of this rendering state. */ - SharedPtr< RenderingStateCache > m_rendering_state_cache; + RenderingStateCache * const m_rendering_state_cache; /** - The blend state of this rendering state. + A pointer to the blend state of this rendering state. */ - ComPtr< ID3D11BlendState > m_blend_state; + ID3D11BlendState *m_blend_state; /** - The depth stencil state of this rendering state. + A pointer to the depth stencil state of this rendering state. */ - ComPtr< ID3D11DepthStencilState > m_depth_stencil_state; + ID3D11DepthStencilState *m_depth_stencil_state; /** - The rasterizer state of this rendering state. + A pointer to the rasterizer state of this rendering state. */ - ComPtr< ID3D11RasterizerState > m_rasterizer_state; + ID3D11RasterizerState *m_rasterizer_state; /** - The sampler state of this rendering state. + A pointer to the sampler state of this rendering state. */ - ComPtr< ID3D11SamplerState > m_sampler_state; + ID3D11SamplerState *m_sampler_state; }; } diff --git a/MAGE/MAGE/src/rendering/rendering_state_cache.cpp b/MAGE/MAGE/src/rendering/rendering_state_cache.cpp index 1720e96d0..56a1498ed 100644 --- a/MAGE/MAGE/src/rendering/rendering_state_cache.cpp +++ b/MAGE/MAGE/src/rendering/rendering_state_cache.cpp @@ -20,190 +20,190 @@ namespace mage { // Blend states //------------------------------------------------------------------------- - ComPtr< ID3D11BlendState > RenderingStateCache::GetOpaqueBlendState() { + ID3D11BlendState *RenderingStateCache::GetOpaqueBlendState() { MutexLock lock(m_mutex); if (!m_opaque_blend_state) { - const HRESULT result_create = CreateOpaqueBlendState(*m_device.Get(), m_opaque_blend_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateOpaqueBlendState(m_device, m_opaque_blend_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Opaque blend state creation failed: %08X.", result_create); } } - return m_opaque_blend_state; + return m_opaque_blend_state.Get(); } - ComPtr< ID3D11BlendState > RenderingStateCache::GetAlphaBlendState() { + ID3D11BlendState *RenderingStateCache::GetAlphaBlendState() { MutexLock lock(m_mutex); if (!m_alpha_blend_state) { - const HRESULT result_create = CreateAlphaBlendState(*m_device.Get(), m_alpha_blend_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateAlphaBlendState(m_device, m_alpha_blend_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Alpha blend state creation failed: %08X.", result_create); } } - return m_alpha_blend_state; + return m_alpha_blend_state.Get(); } - ComPtr< ID3D11BlendState > RenderingStateCache::GetAdditiveBlendState() { + ID3D11BlendState *RenderingStateCache::GetAdditiveBlendState() { MutexLock lock(m_mutex); if (!m_additive_blend_state) { - const HRESULT result_create = CreateAdditiveBlendState(*m_device.Get(), m_additive_blend_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateAdditiveBlendState(m_device, m_additive_blend_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Additive blend state creation failed: %08X.", result_create); } } - return m_additive_blend_state; + return m_additive_blend_state.Get(); } - ComPtr< ID3D11BlendState > RenderingStateCache::GetNonPremultipliedBlendState() { + ID3D11BlendState *RenderingStateCache::GetNonPremultipliedBlendState() { MutexLock lock(m_mutex); if (!m_non_premultiplied_blend_state) { - const HRESULT result_create = CreateNonPremultipliedBlendState(*m_device.Get(), m_non_premultiplied_blend_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateNonPremultipliedBlendState(m_device, m_non_premultiplied_blend_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Non-premultiplied blend state creation failed: %08X.", result_create); } } - return m_non_premultiplied_blend_state; + return m_non_premultiplied_blend_state.Get(); } //------------------------------------------------------------------------- // Depth stencil states //------------------------------------------------------------------------- - ComPtr< ID3D11DepthStencilState > RenderingStateCache::GetDepthNoneDepthStencilState() { + ID3D11DepthStencilState *RenderingStateCache::GetDepthNoneDepthStencilState() { MutexLock lock(m_mutex); if (!m_depth_none_depth_stencil_state) { - const HRESULT result_create = CreateDepthNoneDepthStencilState(*m_device.Get(), m_depth_none_depth_stencil_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateDepthNoneDepthStencilState(m_device, m_depth_none_depth_stencil_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Depth non depth stencil state creation failed: %08X.", result_create); } } - return m_depth_none_depth_stencil_state; + return m_depth_none_depth_stencil_state.Get(); } - ComPtr< ID3D11DepthStencilState > RenderingStateCache::GetDepthDefaultDepthStencilState() { + ID3D11DepthStencilState *RenderingStateCache::GetDepthDefaultDepthStencilState() { MutexLock lock(m_mutex); if (!m_depth_default_depth_stencil_state) { - const HRESULT result_create = CreateDepthDefaultDepthStencilState(*m_device.Get(), m_depth_default_depth_stencil_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateDepthDefaultDepthStencilState(m_device, m_depth_default_depth_stencil_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Depth default depth stencil state creation failed: %08X.", result_create); } } - return m_depth_default_depth_stencil_state; + return m_depth_default_depth_stencil_state.Get(); } - ComPtr< ID3D11DepthStencilState > RenderingStateCache::GetDepthReadDepthStencilState() { + ID3D11DepthStencilState *RenderingStateCache::GetDepthReadDepthStencilState() { MutexLock lock(m_mutex); if (!m_depth_read_depth_stencil_state) { - const HRESULT result_create = CreateDepthReadDepthStencilState(*m_device.Get(), m_depth_read_depth_stencil_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateDepthReadDepthStencilState(m_device, m_depth_read_depth_stencil_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Depth read depth stencil state creation failed: %08X.", result_create); } } - return m_depth_read_depth_stencil_state; + return m_depth_read_depth_stencil_state.Get(); } //------------------------------------------------------------------------- // Rasterizer states //------------------------------------------------------------------------- - ComPtr< ID3D11RasterizerState > RenderingStateCache::GetCullNoneRasterizerState() { + ID3D11RasterizerState *RenderingStateCache::GetCullNoneRasterizerState() { MutexLock lock(m_mutex); if (!m_cull_none_rasterizer_state) { - const HRESULT result_create = CreateCullNoneRasterizerState(*m_device.Get(), m_cull_none_rasterizer_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateCullNoneRasterizerState(m_device, m_cull_none_rasterizer_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Cull none rasterizer state creation failed: %08X.", result_create); } } - return m_cull_none_rasterizer_state; + return m_cull_none_rasterizer_state.Get(); } - ComPtr< ID3D11RasterizerState > RenderingStateCache::GetCullClockwiseRasterizerState() { + ID3D11RasterizerState *RenderingStateCache::GetCullClockwiseRasterizerState() { MutexLock lock(m_mutex); if (!m_cull_clockwise_rasterizer_state) { - const HRESULT result_create = CreateCullClockwiseRasterizerState(*m_device.Get(), m_cull_clockwise_rasterizer_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateCullClockwiseRasterizerState(m_device, m_cull_clockwise_rasterizer_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Cull clockwise rasterizer state creation failed: %08X.", result_create); } } - return m_cull_clockwise_rasterizer_state; + return m_cull_clockwise_rasterizer_state.Get(); } - ComPtr< ID3D11RasterizerState > RenderingStateCache::GetCullCounterClockwiseRasterizerState() { + ID3D11RasterizerState *RenderingStateCache::GetCullCounterClockwiseRasterizerState() { MutexLock lock(m_mutex); if (!m_cull_counter_clockwise_rasterizer_state) { - const HRESULT result_create = CreateCullCounterClockwiseRasterizerState(*m_device.Get(), m_cull_counter_clockwise_rasterizer_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateCullCounterClockwiseRasterizerState(m_device, m_cull_counter_clockwise_rasterizer_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Cull counter clockwise state creation failed: %08X.", result_create); } } - return m_cull_counter_clockwise_rasterizer_state; + return m_cull_counter_clockwise_rasterizer_state.Get(); } - ComPtr< ID3D11RasterizerState > RenderingStateCache::GetWireframeRasterizerState() { + ID3D11RasterizerState *RenderingStateCache::GetWireframeRasterizerState() { MutexLock lock(m_mutex); if (!m_wireframe_rasterizer_state) { - const HRESULT result_create = CreateWireframeRasterizerState(*m_device.Get(), m_wireframe_rasterizer_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateWireframeRasterizerState(m_device, m_wireframe_rasterizer_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Wireframe rasterizer state creation failed: %08X.", result_create); } } - return m_wireframe_rasterizer_state; + return m_wireframe_rasterizer_state.Get(); } //------------------------------------------------------------------------- // Sampler states //------------------------------------------------------------------------- - ComPtr< ID3D11SamplerState > RenderingStateCache::GetPointWrapSamplerState() { + ID3D11SamplerState *RenderingStateCache::GetPointWrapSamplerState() { MutexLock lock(m_mutex); if (!m_point_wrap_sampler_state) { - const HRESULT result_create = CreatePointWrapSamplerState(*m_device.Get(), m_point_wrap_sampler_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreatePointWrapSamplerState(m_device, m_point_wrap_sampler_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Point wrap sampler state creation failed: %08X.", result_create); } } - return m_point_wrap_sampler_state; + return m_point_wrap_sampler_state.Get(); } - ComPtr< ID3D11SamplerState > RenderingStateCache::GetPointClampSamplerState() { + ID3D11SamplerState *RenderingStateCache::GetPointClampSamplerState() { MutexLock lock(m_mutex); if (!m_point_clamp_sampler_state) { - const HRESULT result_create = CreatePointClampSamplerState(*m_device.Get(), m_point_clamp_sampler_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreatePointClampSamplerState(m_device, m_point_clamp_sampler_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Point clamp sampler state creation failed: %08X.", result_create); } } - return m_point_clamp_sampler_state; + return m_point_clamp_sampler_state.Get(); } - ComPtr< ID3D11SamplerState > RenderingStateCache::GetLinearWrapSamplerState() { + ID3D11SamplerState *RenderingStateCache::GetLinearWrapSamplerState() { MutexLock lock(m_mutex); if (!m_linear_wrap_sampler_state) { - const HRESULT result_create = CreateLinearWrapSamplerState(*m_device.Get(), m_linear_wrap_sampler_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateLinearWrapSamplerState(m_device, m_linear_wrap_sampler_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Linear wrap sampler state creation failed: %08X.", result_create); } } - return m_linear_wrap_sampler_state; + return m_linear_wrap_sampler_state.Get(); } - ComPtr< ID3D11SamplerState > RenderingStateCache::GetLinearClampSamplerState() { + ID3D11SamplerState *RenderingStateCache::GetLinearClampSamplerState() { MutexLock lock(m_mutex); if (!m_linear_clamp_sampler_state) { - const HRESULT result_create = CreateLinearClampSamplerState(*m_device.Get(), m_linear_clamp_sampler_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateLinearClampSamplerState(m_device, m_linear_clamp_sampler_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Linear clamp sampler state creation failed: %08X.", result_create); } } - return m_linear_clamp_sampler_state; + return m_linear_clamp_sampler_state.Get(); } - ComPtr< ID3D11SamplerState > RenderingStateCache::GetAnisotropicWrapSamplerState() { + ID3D11SamplerState *RenderingStateCache::GetAnisotropicWrapSamplerState() { MutexLock lock(m_mutex); if (!m_anisotropic_wrap_sampler_state) { - const HRESULT result_create = CreateAnisotropicWrapSamplerState(*m_device.Get(), m_anisotropic_wrap_sampler_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateAnisotropicWrapSamplerState(m_device, m_anisotropic_wrap_sampler_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Anistropic wrap sampler state creation failed: %08X.", result_create); } } - return m_anisotropic_wrap_sampler_state; + return m_anisotropic_wrap_sampler_state.Get(); } - ComPtr< ID3D11SamplerState > RenderingStateCache::GetAnisotropicClampSamplerState() { + ID3D11SamplerState *RenderingStateCache::GetAnisotropicClampSamplerState() { MutexLock lock(m_mutex); if (!m_anisotropic_clamp_sampler_state) { - const HRESULT result_create = CreateAnisotropicClampSamplerState(*m_device.Get(), m_anisotropic_clamp_sampler_state.ReleaseAndGetAddressOf()); + const HRESULT result_create = CreateAnisotropicClampSamplerState(m_device, m_anisotropic_clamp_sampler_state.ReleaseAndGetAddressOf()); if (FAILED(result_create)) { Error("Anistropic clamp sampler state creation failed: %08X.", result_create); } } - return m_anisotropic_clamp_sampler_state; + return m_anisotropic_clamp_sampler_state.Get(); } } \ No newline at end of file diff --git a/MAGE/MAGE/src/rendering/rendering_state_cache.hpp b/MAGE/MAGE/src/rendering/rendering_state_cache.hpp index 030b3ba3b..647dc6a06 100644 --- a/MAGE/MAGE/src/rendering/rendering_state_cache.hpp +++ b/MAGE/MAGE/src/rendering/rendering_state_cache.hpp @@ -20,7 +20,7 @@ namespace mage { public: - RenderingStateCache(ComPtr< ID3D11Device2 > device) + RenderingStateCache(ID3D11Device2 *device) : m_device(device) {} ~RenderingStateCache() = default; @@ -28,38 +28,38 @@ namespace mage { // Blend states //--------------------------------------------------------------------- - ComPtr< ID3D11BlendState > GetOpaqueBlendState(); - ComPtr< ID3D11BlendState > GetAlphaBlendState(); - ComPtr< ID3D11BlendState > GetAdditiveBlendState(); - ComPtr< ID3D11BlendState > GetNonPremultipliedBlendState(); + ID3D11BlendState *GetOpaqueBlendState(); + ID3D11BlendState *GetAlphaBlendState(); + ID3D11BlendState *GetAdditiveBlendState(); + ID3D11BlendState *GetNonPremultipliedBlendState(); //--------------------------------------------------------------------- // Depth stencil states //--------------------------------------------------------------------- - ComPtr< ID3D11DepthStencilState > GetDepthNoneDepthStencilState(); - ComPtr< ID3D11DepthStencilState > GetDepthDefaultDepthStencilState(); - ComPtr< ID3D11DepthStencilState > GetDepthReadDepthStencilState(); + ID3D11DepthStencilState *GetDepthNoneDepthStencilState(); + ID3D11DepthStencilState *GetDepthDefaultDepthStencilState(); + ID3D11DepthStencilState *GetDepthReadDepthStencilState(); //------------------------------------------------------------------------- // Rasterizer states //------------------------------------------------------------------------- - ComPtr< ID3D11RasterizerState > GetCullNoneRasterizerState(); - ComPtr< ID3D11RasterizerState > GetCullClockwiseRasterizerState(); - ComPtr< ID3D11RasterizerState > GetCullCounterClockwiseRasterizerState(); - ComPtr< ID3D11RasterizerState > GetWireframeRasterizerState(); + ID3D11RasterizerState *GetCullNoneRasterizerState(); + ID3D11RasterizerState *GetCullClockwiseRasterizerState(); + ID3D11RasterizerState *GetCullCounterClockwiseRasterizerState(); + ID3D11RasterizerState *GetWireframeRasterizerState(); //------------------------------------------------------------------------- // Sampler states //------------------------------------------------------------------------- - ComPtr< ID3D11SamplerState > GetPointWrapSamplerState(); - ComPtr< ID3D11SamplerState > GetPointClampSamplerState(); - ComPtr< ID3D11SamplerState > GetLinearWrapSamplerState(); - ComPtr< ID3D11SamplerState > GetLinearClampSamplerState(); - ComPtr< ID3D11SamplerState > GetAnisotropicWrapSamplerState(); - ComPtr< ID3D11SamplerState > GetAnisotropicClampSamplerState(); + ID3D11SamplerState *GetPointWrapSamplerState(); + ID3D11SamplerState *GetPointClampSamplerState(); + ID3D11SamplerState *GetLinearWrapSamplerState(); + ID3D11SamplerState *GetLinearClampSamplerState(); + ID3D11SamplerState *GetAnisotropicWrapSamplerState(); + ID3D11SamplerState *GetAnisotropicClampSamplerState(); private: @@ -72,7 +72,7 @@ namespace mage { /** The device of this rendering state. */ - ComPtr< ID3D11Device2 > m_device; + ID3D11Device2 * const m_device; ComPtr< ID3D11BlendState > m_opaque_blend_state; ComPtr< ID3D11BlendState > m_alpha_blend_state; diff --git a/MAGE/MAGE/src/resource/resource_factory.cpp b/MAGE/MAGE/src/resource/resource_factory.cpp index 2cfba75e8..09b295ffc 100644 --- a/MAGE/MAGE/src/resource/resource_factory.cpp +++ b/MAGE/MAGE/src/resource/resource_factory.cpp @@ -33,19 +33,19 @@ namespace mage { } SharedPtr< VertexShader > ResourceFactory::CreateLambertianVertexShader( - ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context) { + ID3D11Device2 *device, ID3D11DeviceContext2 *device_context) { return m_vertex_shader_resource_pool->template - GetDerivedResource< LambertianVertexShader, ComPtr< ID3D11Device2 > &, ComPtr< ID3D11DeviceContext2 > & >(MAGE_GUID_LAMBERTIAN_VS, device, device_context); + GetDerivedResource< LambertianVertexShader, ID3D11Device2 *&, ID3D11DeviceContext2 *& >(MAGE_GUID_LAMBERTIAN_VS, device, device_context); } SharedPtr< PixelShader > ResourceFactory::CreateLambertianPixelShader( - ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context) { + ID3D11Device2 *device, ID3D11DeviceContext2 *device_context) { return m_pixel_shader_resource_pool->template - GetDerivedResource< LambertianPixelShader, ComPtr< ID3D11Device2 > &, ComPtr< ID3D11DeviceContext2 > & >(MAGE_GUID_LAMBERTIAN_PS, device, device_context); + GetDerivedResource< LambertianPixelShader, ID3D11Device2 *&, ID3D11DeviceContext2 *& >(MAGE_GUID_LAMBERTIAN_PS, device, device_context); } SharedPtr< Texture > ResourceFactory::CreateTexture( - ComPtr< ID3D11Device2 > device, const wstring &fname) { + ID3D11Device2 *device, const wstring &fname) { return m_texture_resource_pool->template - GetResource< ComPtr< ID3D11Device2 > &, const wstring & >(fname, device, fname); + GetResource< ID3D11Device2 *&, const wstring & >(fname, device, fname); } SharedPtr< VariableScript > ResourceFactory::CreateVariableScript(const wstring &fname, bool import) { return m_variable_script_resource_pool->template @@ -56,11 +56,11 @@ namespace mage { // Resource Creation //------------------------------------------------------------------------- - ComPtr< ID3D11Device2 > GetRenderingDevice() { + ID3D11Device2 *GetRenderingDevice() { Assert(g_engine); return g_engine->GetRenderer().GetDevice(); } - ComPtr< ID3D11DeviceContext2 > GetRenderingDeviceContext() { + ID3D11DeviceContext2 *GetRenderingDeviceContext() { Assert(g_engine); return g_engine->GetRenderer().GetDeviceContext(); } diff --git a/MAGE/MAGE/src/resource/resource_factory.hpp b/MAGE/MAGE/src/resource/resource_factory.hpp index 12fd27342..b2416bde4 100644 --- a/MAGE/MAGE/src/resource/resource_factory.hpp +++ b/MAGE/MAGE/src/resource/resource_factory.hpp @@ -30,13 +30,13 @@ namespace mage { template < typename VertexT > SharedPtr< ModelDescriptor > CreateModelDescriptor( - ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &fname, const MeshDescriptor< VertexT > &desc); SharedPtr< VertexShader > CreateLambertianVertexShader( - ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context); + ID3D11Device2 *device, ID3D11DeviceContext2 *device_context); SharedPtr< PixelShader > CreateLambertianPixelShader( - ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context); - SharedPtr< Texture > CreateTexture(ComPtr< ID3D11Device2 > device, const wstring &fname); + ID3D11Device2 *device, ID3D11DeviceContext2 *device_context); + SharedPtr< Texture > CreateTexture(ID3D11Device2 *device, const wstring &fname); SharedPtr< VariableScript > CreateVariableScript(const wstring &fname, bool import); private: @@ -57,8 +57,8 @@ namespace mage { // Resource Creation //------------------------------------------------------------------------- - ComPtr< ID3D11Device2 > GetRenderingDevice(); - ComPtr< ID3D11DeviceContext2 > GetRenderingDeviceContext(); + ID3D11Device2 *GetRenderingDevice(); + ID3D11DeviceContext2 *GetRenderingDeviceContext(); ResourceFactory &GetResourceFactory(); } diff --git a/MAGE/MAGE/src/resource/resource_factory.tpp b/MAGE/MAGE/src/resource/resource_factory.tpp index f293e4378..f336931b5 100644 --- a/MAGE/MAGE/src/resource/resource_factory.tpp +++ b/MAGE/MAGE/src/resource/resource_factory.tpp @@ -11,9 +11,9 @@ namespace mage { template < typename VertexT > SharedPtr< ModelDescriptor > ResourceFactory::CreateModelDescriptor( - ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &fname, const MeshDescriptor< VertexT > &desc) { return m_model_descriptor_resource_pool->template - GetResource< ComPtr< ID3D11Device2 > &, ComPtr< ID3D11DeviceContext2 > &, const wstring &, const MeshDescriptor< VertexT > & >(fname, device, device_context, fname, desc); + GetResource< ID3D11Device2 *&, ID3D11DeviceContext2 *&, const wstring &, const MeshDescriptor< VertexT > & >(fname, device, device_context, fname, desc); } } \ No newline at end of file diff --git a/MAGE/MAGE/src/scripting/variable.hpp b/MAGE/MAGE/src/scripting/variable.hpp index 6ea9d861a..83bfc0e5d 100644 --- a/MAGE/MAGE/src/scripting/variable.hpp +++ b/MAGE/MAGE/src/scripting/variable.hpp @@ -5,6 +5,7 @@ //----------------------------------------------------------------------------- #pragma region +#include "memory\memory.hpp" #include "string\string.hpp" #include "math\math.hpp" @@ -75,9 +76,7 @@ namespace mage { /** Destructs this variable. */ - ~Variable() { - delete m_value; - } + ~Variable() = default; /** Checks whether the given variable is equal to this variable. @@ -142,8 +141,7 @@ namespace mage { */ template< typename T > void SetValue(const T *value) { - delete m_value; - m_value = new Value< T >(value); + m_value.reset(new Value< T >(value)); } private: @@ -289,9 +287,7 @@ namespace mage { /** Destructs this value. */ - virtual ~Value() { - delete m_value; - } + virtual ~Value() = default; /** Returns the value of this value. @@ -299,7 +295,7 @@ namespace mage { @return A pointer to the value of this value. */ virtual const void *GetValue() const override { - return (void *)m_value; + return (void *)m_value.get(); } private: @@ -347,12 +343,12 @@ namespace mage { /** A pointer to the value of this value. */ - const T *m_value; + UniquePtr< const T > m_value; }; /** - A pointer to the value of this variable. - */ - const AbstractValue *m_value; + A pointer to the value of this variable. + */ + UniquePtr< const AbstractValue > m_value; }; } \ No newline at end of file diff --git a/MAGE/MAGE/src/scripting/vs/vs_reader.cpp b/MAGE/MAGE/src/scripting/vs/vs_reader.cpp index 274e6ff82..1d6c3b634 100644 --- a/MAGE/MAGE/src/scripting/vs/vs_reader.cpp +++ b/MAGE/MAGE/src/scripting/vs/vs_reader.cpp @@ -152,6 +152,6 @@ namespace mage { const char *str = ReadChars(); char *value = new char[MAX_PATH + 1]; strcpy_s(value, MAX_PATH + 1, str); - m_variable_buffer.push_back(new Variable(UnknownType, name, (void *)value)); + m_variable_buffer.push_back(new Variable(UnknownType, name, value)); } } \ No newline at end of file diff --git a/MAGE/MAGE/src/shader/empty_shader.hpp b/MAGE/MAGE/src/shader/empty_shader.hpp index 3d460f999..3d721fe01 100644 --- a/MAGE/MAGE/src/shader/empty_shader.hpp +++ b/MAGE/MAGE/src/shader/empty_shader.hpp @@ -22,7 +22,7 @@ namespace mage { public: - EmptyVertexShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + EmptyVertexShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &fname, const D3D11_INPUT_ELEMENT_DESC *input_element_desc, uint32_t nb_input_elements) : VertexShader(device, device_context, fname, input_element_desc, nb_input_elements) {} virtual ~EmptyVertexShader() = default; @@ -45,7 +45,7 @@ namespace mage { public: - EmptyPixelShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + EmptyPixelShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &fname) : PixelShader(device, device_context, fname) {} virtual ~EmptyPixelShader() = default; diff --git a/MAGE/MAGE/src/shader/lambertian_shader.cpp b/MAGE/MAGE/src/shader/lambertian_shader.cpp index abc1e7432..06a106df6 100644 --- a/MAGE/MAGE/src/shader/lambertian_shader.cpp +++ b/MAGE/MAGE/src/shader/lambertian_shader.cpp @@ -26,11 +26,11 @@ namespace mage { // LambertianVertexShader //------------------------------------------------------------------------- - LambertianVertexShader::LambertianVertexShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context) + LambertianVertexShader::LambertianVertexShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context) : VertexShader(device, device_context, MAGE_GUID_LAMBERTIAN_VS, g_lambertian_vs, sizeof(g_lambertian_vs), VertexPositionNormalTexture::input_element_desc, VertexPositionNormalTexture::nb_input_elements) { - const HRESULT result_cb_transform = CreateConstantBuffer< TransformBuffer >(*m_device.Get(), m_cb_transform.ReleaseAndGetAddressOf()); + const HRESULT result_cb_transform = CreateConstantBuffer< TransformBuffer >(m_device, m_cb_transform.ReleaseAndGetAddressOf()); if (FAILED(result_cb_transform)) { Error("Transformation constant buffer creation failed: %08X.", result_cb_transform); return; @@ -50,10 +50,10 @@ namespace mage { // LambertianPixelShader //------------------------------------------------------------------------- - LambertianPixelShader::LambertianPixelShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context) + LambertianPixelShader::LambertianPixelShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context) : PixelShader(device, device_context, MAGE_GUID_LAMBERTIAN_PS, g_lambertian_ps, sizeof(g_lambertian_ps)) { - const HRESULT result_cb_material = CreateConstantBuffer< MaterialBuffer >(*m_device.Get(), m_cb_material.ReleaseAndGetAddressOf()); + const HRESULT result_cb_material = CreateConstantBuffer< MaterialBuffer >(m_device, m_cb_material.ReleaseAndGetAddressOf()); if (FAILED(result_cb_material)) { Error("Material constant buffer creation failed: %08X.", result_cb_material); return; @@ -64,7 +64,7 @@ namespace mage { UNUSED(material); UNUSED(world); m_device_context->PSSetShader(m_pixel_shader.Get(), nullptr, 0); - m_device_context->PSSetShaderResources(0, 1, material.m_diffuse_reflectivity_texture->GetTextureResourceView().GetAddressOf()); + m_device_context->PSSetShaderResources(0, 1, material.m_diffuse_reflectivity_texture->GetTextureResourceViewAddress()); } //------------------------------------------------------------------------- @@ -72,8 +72,8 @@ namespace mage { //------------------------------------------------------------------------- CombinedShader CreateLambertianShader() { - ComPtr< ID3D11Device2 > device = GetRenderingDevice(); - ComPtr< ID3D11DeviceContext2 > device_context = GetRenderingDeviceContext(); + ID3D11Device2 *device = GetRenderingDevice(); + ID3D11DeviceContext2 *device_context = GetRenderingDeviceContext(); ResourceFactory &factory = GetResourceFactory(); SharedPtr< VertexShader > vs = factory.CreateLambertianVertexShader(device, device_context); SharedPtr< PixelShader > ps = factory.CreateLambertianPixelShader(device, device_context); diff --git a/MAGE/MAGE/src/shader/lambertian_shader.hpp b/MAGE/MAGE/src/shader/lambertian_shader.hpp index 641c4759f..3dffb64a2 100644 --- a/MAGE/MAGE/src/shader/lambertian_shader.hpp +++ b/MAGE/MAGE/src/shader/lambertian_shader.hpp @@ -32,7 +32,7 @@ namespace mage { public: - LambertianVertexShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context); + LambertianVertexShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context); virtual ~LambertianVertexShader() = default; virtual void Draw(const Material &material, const World &world, const TransformBuffer &transform_buffer) const override; @@ -55,7 +55,7 @@ namespace mage { public: - LambertianPixelShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context); + LambertianPixelShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context); virtual ~LambertianPixelShader() = default; virtual void Draw(const Material &material, const World &world) const override; diff --git a/MAGE/MAGE/src/shader/shader.cpp b/MAGE/MAGE/src/shader/shader.cpp index 1049534a0..e401a6c9a 100644 --- a/MAGE/MAGE/src/shader/shader.cpp +++ b/MAGE/MAGE/src/shader/shader.cpp @@ -18,7 +18,7 @@ namespace mage { // VertexShader //------------------------------------------------------------------------- - VertexShader::VertexShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + VertexShader::VertexShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &guid, const D3D11_INPUT_ELEMENT_DESC *input_element_desc, uint32_t nb_input_elements) : Resource(guid), m_device(device), m_device_context(device_context) { @@ -30,7 +30,7 @@ namespace mage { } } - VertexShader::VertexShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + VertexShader::VertexShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &guid, const void *bytecode, SIZE_T bytecode_size, const D3D11_INPUT_ELEMENT_DESC *input_element_desc, uint32_t nb_input_elements) : Resource(guid), m_device(device), m_device_context(device_context) { @@ -107,7 +107,7 @@ namespace mage { // PixelShader //------------------------------------------------------------------------- - PixelShader::PixelShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + PixelShader::PixelShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &guid) : Resource(guid), m_device(device), m_device_context(device_context) { @@ -118,7 +118,7 @@ namespace mage { } } - PixelShader::PixelShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + PixelShader::PixelShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &guid, const void *bytecode, SIZE_T bytecode_size) : Resource(guid), m_device(device), m_device_context(device_context) { diff --git a/MAGE/MAGE/src/shader/shader.hpp b/MAGE/MAGE/src/shader/shader.hpp index f9efc6d46..370481c41 100644 --- a/MAGE/MAGE/src/shader/shader.hpp +++ b/MAGE/MAGE/src/shader/shader.hpp @@ -24,9 +24,9 @@ namespace mage { public: - VertexShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + VertexShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &guid, const D3D11_INPUT_ELEMENT_DESC *input_element_desc, uint32_t nb_input_elements); - VertexShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + VertexShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &guid, const void *bytecode, SIZE_T bytecode_size, const D3D11_INPUT_ELEMENT_DESC *input_element_desc, uint32_t nb_input_elements); virtual ~VertexShader() = default; @@ -35,10 +35,10 @@ namespace mage { protected: - ComPtr< ID3D11Device2 > m_device; - ComPtr< ID3D11DeviceContext2 > m_device_context; - ComPtr< ID3D11VertexShader > m_vertex_shader; - ComPtr< ID3D11InputLayout > m_vertex_layout; + ID3D11Device2 * const m_device; + ID3D11DeviceContext2 * const m_device_context; + ComPtr< ID3D11VertexShader > m_vertex_shader; + ComPtr< ID3D11InputLayout > m_vertex_layout; private: @@ -60,9 +60,9 @@ namespace mage { public: - PixelShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + PixelShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &guid); - PixelShader(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, + PixelShader(ID3D11Device2 *device, ID3D11DeviceContext2 *device_context, const wstring &guid, const void *bytecode, SIZE_T bytecode_size); virtual ~PixelShader() = default; @@ -70,9 +70,9 @@ namespace mage { protected: - ComPtr< ID3D11Device2 > m_device; - ComPtr< ID3D11DeviceContext2 > m_device_context; - ComPtr< ID3D11PixelShader > m_pixel_shader; + ID3D11Device2 * const m_device; + ID3D11DeviceContext2 * const m_device_context; + ComPtr< ID3D11PixelShader > m_pixel_shader; private: @@ -102,20 +102,6 @@ namespace mage { CombinedShader &operator=(const CombinedShader &shader) = default; CombinedShader &operator=(CombinedShader &&shader) = default; - SharedPtr< VertexShader > GetVertexShader() const { - return m_vertex_shader; - } - void SetVertexShader(SharedPtr< VertexShader > vertex_shader) { - m_vertex_shader = vertex_shader; - } - - SharedPtr< PixelShader > GetPixelShader() const { - return m_pixel_shader; - } - void SetPixelShader(SharedPtr< PixelShader > pixel_shader) { - m_pixel_shader = pixel_shader; - } - void Draw(const Material &material, const World &world, const TransformBuffer &transform_buffer) const { m_vertex_shader->Draw(material, world, transform_buffer); m_pixel_shader->Draw(material, world); diff --git a/MAGE/MAGE/src/sprite/sprite_font.cpp b/MAGE/MAGE/src/sprite/sprite_font.cpp index aa31da375..b8943810f 100644 --- a/MAGE/MAGE/src/sprite/sprite_font.cpp +++ b/MAGE/MAGE/src/sprite/sprite_font.cpp @@ -45,7 +45,7 @@ namespace mage { } }; - SpriteFont::SpriteFont(ID3D11Device2 &device, const wstring &fname, const SpriteFontDescriptor &desc) + SpriteFont::SpriteFont(ID3D11Device2 *device, const wstring &fname, const SpriteFontDescriptor &desc) : Resource(fname) { SpriteFontOutput output; diff --git a/MAGE/MAGE/src/sprite/sprite_font.hpp b/MAGE/MAGE/src/sprite/sprite_font.hpp index f656aa059..05c02c7c0 100644 --- a/MAGE/MAGE/src/sprite/sprite_font.hpp +++ b/MAGE/MAGE/src/sprite/sprite_font.hpp @@ -21,7 +21,7 @@ namespace mage { public: - SpriteFont(ID3D11Device2 &device, const wstring &fname, const SpriteFontDescriptor &desc); + SpriteFont(ID3D11Device2 *device, const wstring &fname, const SpriteFontDescriptor &desc); virtual ~SpriteFont() = default; void DrawString(SpriteBatch &sprite_batch, const wchar_t *text, const SpriteTransform &transform, diff --git a/MAGE/MAGE/src/sprite/sprite_font_loader.cpp b/MAGE/MAGE/src/sprite/sprite_font_loader.cpp index ab2eacb40..23341c3de 100644 --- a/MAGE/MAGE/src/sprite/sprite_font_loader.cpp +++ b/MAGE/MAGE/src/sprite/sprite_font_loader.cpp @@ -15,7 +15,7 @@ //----------------------------------------------------------------------------- namespace mage { - HRESULT ImportSpriteFontFromFile(const wstring &fname, ID3D11Device2 &device, SpriteFontOutput &output, const SpriteFontDescriptor &desc) { + HRESULT ImportSpriteFontFromFile(const wstring &fname, ID3D11Device2 *device, SpriteFontOutput &output, const SpriteFontDescriptor &desc) { const wstring extension = GetFileExtension(fname); if (extension == L"spritefont" || extension == L"SPRITEFONT") { diff --git a/MAGE/MAGE/src/sprite/sprite_font_loader.hpp b/MAGE/MAGE/src/sprite/sprite_font_loader.hpp index 8f55e2a2b..f79082ef5 100644 --- a/MAGE/MAGE/src/sprite/sprite_font_loader.hpp +++ b/MAGE/MAGE/src/sprite/sprite_font_loader.hpp @@ -16,5 +16,5 @@ //----------------------------------------------------------------------------- namespace mage { - HRESULT ImportSpriteFontFromFile(const wstring &fname, ID3D11Device2 &device, SpriteFontOutput &output, const SpriteFontDescriptor &desc = SpriteFontDescriptor()); + HRESULT ImportSpriteFontFromFile(const wstring &fname, ID3D11Device2 *device, SpriteFontOutput &output, const SpriteFontDescriptor &desc = SpriteFontDescriptor()); } \ No newline at end of file diff --git a/MAGE/MAGE/src/sprite/spritefont/spritefont_loader.cpp b/MAGE/MAGE/src/sprite/spritefont/spritefont_loader.cpp index 8e6133522..4e6a3d299 100644 --- a/MAGE/MAGE/src/sprite/spritefont/spritefont_loader.cpp +++ b/MAGE/MAGE/src/sprite/spritefont/spritefont_loader.cpp @@ -13,7 +13,7 @@ //----------------------------------------------------------------------------- namespace mage { - HRESULT ImportFontFromFile(const wstring &fname, ID3D11Device2 &device, SpriteFontOutput &output, const SpriteFontDescriptor &desc) { + HRESULT ImportFontFromFile(const wstring &fname, ID3D11Device2 *device, SpriteFontOutput &output, const SpriteFontDescriptor &desc) { SpriteFontReader reader(device, output, desc); return reader.ReadFromFile(fname); } diff --git a/MAGE/MAGE/src/sprite/spritefont/spritefont_loader.hpp b/MAGE/MAGE/src/sprite/spritefont/spritefont_loader.hpp index ca551e6b0..5efb36426 100644 --- a/MAGE/MAGE/src/sprite/spritefont/spritefont_loader.hpp +++ b/MAGE/MAGE/src/sprite/spritefont/spritefont_loader.hpp @@ -16,5 +16,5 @@ //----------------------------------------------------------------------------- namespace mage { - HRESULT ImportFontFromFile(const wstring &fname, ID3D11Device2 &device, SpriteFontOutput &output, const SpriteFontDescriptor &desc = SpriteFontDescriptor()); + HRESULT ImportFontFromFile(const wstring &fname, ID3D11Device2 *device, SpriteFontOutput &output, const SpriteFontDescriptor &desc = SpriteFontDescriptor()); } \ No newline at end of file diff --git a/MAGE/MAGE/src/sprite/spritefont/spritefont_reader.cpp b/MAGE/MAGE/src/sprite/spritefont/spritefont_reader.cpp index 3d0ccd126..a6b609cb7 100644 --- a/MAGE/MAGE/src/sprite/spritefont/spritefont_reader.cpp +++ b/MAGE/MAGE/src/sprite/spritefont/spritefont_reader.cpp @@ -14,7 +14,7 @@ //----------------------------------------------------------------------------- namespace mage { - SpriteFontReader::SpriteFontReader(ID3D11Device2 &device, SpriteFontOutput &output, const SpriteFontDescriptor &desc) + SpriteFontReader::SpriteFontReader(ID3D11Device2 *device, SpriteFontOutput &output, const SpriteFontDescriptor &desc) : BigEndianBinaryReader(), m_device(device), m_output(output), m_desc(desc) {} HRESULT SpriteFontReader::Read() { @@ -74,7 +74,7 @@ namespace mage { init_data.SysMemPitch = texture_stride; // Create the texture resource. ComPtr< ID3D11Texture2D > texture; - const HRESULT result_texture = m_device.CreateTexture2D(&texture_desc, &init_data, texture.ReleaseAndGetAddressOf()); + const HRESULT result_texture = m_device->CreateTexture2D(&texture_desc, &init_data, texture.ReleaseAndGetAddressOf()); if (FAILED(result_texture)) { Error("%ls: failed to create ID3D11Texture2D: %08X.", GetFilename().c_str(), result_texture); return result_texture; @@ -83,7 +83,7 @@ namespace mage { // Create the shader resource view descriptor. CD3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc(D3D11_SRV_DIMENSION_TEXTURE2D, texture_format); // Create the shader resource view. - const HRESULT result_shader_resource_view = m_device.CreateShaderResourceView(texture.Get(), &shader_resource_view_desc, m_output.m_texture.ReleaseAndGetAddressOf()); + const HRESULT result_shader_resource_view = m_device->CreateShaderResourceView(texture.Get(), &shader_resource_view_desc, m_output.m_texture.ReleaseAndGetAddressOf()); if (FAILED(result_shader_resource_view)) { Error("%ls: failed to create ID3D11ShaderResourceView: %08X.", GetFilename().c_str(), result_texture); return result_shader_resource_view; diff --git a/MAGE/MAGE/src/sprite/spritefont/spritefont_reader.hpp b/MAGE/MAGE/src/sprite/spritefont/spritefont_reader.hpp index 1e954be23..dd2b60a8f 100644 --- a/MAGE/MAGE/src/sprite/spritefont/spritefont_reader.hpp +++ b/MAGE/MAGE/src/sprite/spritefont/spritefont_reader.hpp @@ -20,7 +20,7 @@ namespace mage { public: - SpriteFontReader(ID3D11Device2 &device, SpriteFontOutput &output, const SpriteFontDescriptor &desc); + SpriteFontReader(ID3D11Device2 *device, SpriteFontOutput &output, const SpriteFontDescriptor &desc); virtual ~SpriteFontReader() = default; virtual HRESULT Read() override; @@ -37,7 +37,7 @@ namespace mage { SpriteFontReader &operator=(const SpriteFontReader &reader) = delete; SpriteFontReader &operator=(SpriteFontReader &&reader) = delete; - ID3D11Device2 &m_device; + ID3D11Device2 *m_device; SpriteFontOutput &m_output; const SpriteFontDescriptor &m_desc; }; diff --git a/MAGE/MAGE/src/texture/dds/dds_loader.cpp b/MAGE/MAGE/src/texture/dds/dds_loader.cpp index e3361ab0e..ee11a9946 100644 --- a/MAGE/MAGE/src/texture/dds/dds_loader.cpp +++ b/MAGE/MAGE/src/texture/dds/dds_loader.cpp @@ -36,28 +36,28 @@ //-------------------------------------------------------------------------------------- #ifndef MAKEFOURCC #define MAKEFOURCC(ch0, ch1, ch2, ch3) \ - ((uint32_t)(uint8_t)(ch0) | \ - ((uint32_t)(uint8_t)(ch1) << 8) | \ - ((uint32_t)(uint8_t)(ch2) << 16) | \ - ((uint32_t)(uint8_t)(ch3) << 24 )) + ((uint32_t)(uint8_t)(ch0) | \ + ((uint32_t)(uint8_t)(ch1) << 8) | \ + ((uint32_t)(uint8_t)(ch2) << 16) | \ + ((uint32_t)(uint8_t)(ch3) << 24 )) #endif #pragma pack(push,1) namespace mage { - const uint32_t DDS_MAGIC = 0x20534444; // "DDS " + const uint32_t DDS_MAGIC = 0x20534444; // "DDS " - struct DDS_PIXELFORMAT { - uint32_t size; - uint32_t flags; - uint32_t fourCC; - uint32_t RGBBitCount; - uint32_t RBitMask; - uint32_t GBitMask; - uint32_t BBitMask; - uint32_t ABitMask; - }; + struct DDS_PIXELFORMAT { + uint32_t size; + uint32_t flags; + uint32_t fourCC; + uint32_t RGBBitCount; + uint32_t RBitMask; + uint32_t GBitMask; + uint32_t BBitMask; + uint32_t ABitMask; + }; #define DDS_FOURCC 0x00000004 // DDPF_FOURCC #define DDS_RGB 0x00000040 // DDPF_RGB @@ -77,1265 +77,1269 @@ namespace mage { #define DDS_CUBEMAP_NEGATIVEZ 0x00008200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ #define DDS_CUBEMAP_ALLFACES ( DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX |\ - DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY |\ - DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ ) + DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY |\ + DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ ) #define DDS_CUBEMAP 0x00000200 // DDSCAPS2_CUBEMAP - enum DDS_MISC_FLAGS2 { - DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L - }; - - struct DDS_HEADER { - uint32_t size; - uint32_t flags; - uint32_t height; - uint32_t width; - uint32_t pitch_or_linear_size; - uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags - uint32_t mip_map_count; - uint32_t reserved1[11]; - DDS_PIXELFORMAT ddspf; - uint32_t caps; - uint32_t caps2; - uint32_t caps3; - uint32_t caps4; - uint32_t reserved2; - }; - - struct DDS_HEADER_DXT10 { - DXGI_FORMAT dxgi_format; - uint32_t resource_dimension; - uint32_t misc_flag; // see D3D11_RESOURCE_MISC_FLAG - uint32_t array_size; - uint32_t misc_flags2; - }; + enum DDS_MISC_FLAGS2 { + DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L + }; + + struct DDS_HEADER { + uint32_t size; + uint32_t flags; + uint32_t height; + uint32_t width; + uint32_t pitch_or_linear_size; + uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags + uint32_t mip_map_count; + uint32_t reserved1[11]; + DDS_PIXELFORMAT ddspf; + uint32_t caps; + uint32_t caps2; + uint32_t caps3; + uint32_t caps4; + uint32_t reserved2; + }; + + struct DDS_HEADER_DXT10 { + DXGI_FORMAT dxgi_format; + uint32_t resource_dimension; + uint32_t misc_flag; // see D3D11_RESOURCE_MISC_FLAG + uint32_t array_size; + uint32_t misc_flags2; + }; #pragma pack(pop) - template< UINT TNameLength > - inline void SetDebugObjectName(_In_ ID3D11DeviceChild *resource, _In_ const char(&name)[TNameLength]) { + template< UINT TNameLength > + inline void SetDebugObjectName(_In_ ID3D11DeviceChild *resource, _In_ const char(&name)[TNameLength]) { #if defined(_DEBUG) || defined(PROFILE) - resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name); + resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name); #else - UNREFERENCED_PARAMETER(resource); - UNREFERENCED_PARAMETER(name); + UNREFERENCED_PARAMETER(resource); + UNREFERENCED_PARAMETER(name); #endif - } + } static HRESULT LoadTextureDataFromFile(_In_z_ const wchar_t *file_name, std::unique_ptr &dds_data, DDS_HEADER **header, uint8_t **bit_data, size_t *bit_size) { - if (!header || !bit_data || !bit_size) { - return E_POINTER; - } - - // open the file - UniqueHandle hfile(SafeHandle(CreateFile2(file_name, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr))); - - - if (!hfile) { - return HRESULT_FROM_WIN32(GetLastError()); - } - - // Get the file size - LARGE_INTEGER file_size = { 0 }; - - FILE_STANDARD_INFO file_info; - if (!GetFileInformationByHandleEx(hfile.get(), FileStandardInfo, &file_info, sizeof(file_info))) { - return HRESULT_FROM_WIN32(GetLastError()); - } - file_size = file_info.EndOfFile; - - // File is too big for 32-bit allocation, so reject read - if (file_size.HighPart > 0) { - return E_FAIL; - } - - // Need at least enough data to fill the header and magic number to be a valid DDS - if (file_size.LowPart < (sizeof(DDS_HEADER) + sizeof(uint32_t))) { - return E_FAIL; - } - - // create enough space for the file data - dds_data.reset(new (std::nothrow) uint8_t[file_size.LowPart]); - if (!dds_data) { - return E_OUTOFMEMORY; - } - - // read the data in - DWORD nb_bytes_read = 0; - if (!ReadFile(hfile.get(), dds_data.get(), file_size.LowPart, &nb_bytes_read, nullptr)) { - return HRESULT_FROM_WIN32(GetLastError()); - } - - if (nb_bytes_read < file_size.LowPart) { - return E_FAIL; - } - - // DDS files always start with the same magic number ("DDS ") - uint32_t dw_magic_number = *(const uint32_t*)(dds_data.get()); - if (dw_magic_number != DDS_MAGIC) { - return E_FAIL; - } - - auto hdr = reinterpret_cast(dds_data.get() + sizeof(uint32_t)); - - // Verify header to validate DDS file - if (hdr->size != sizeof(DDS_HEADER) || hdr->ddspf.size != sizeof(DDS_PIXELFORMAT)) { - return E_FAIL; - } - - // Check for DX10 extension - bool bDXT10Header = false; - if ((hdr->ddspf.flags & DDS_FOURCC) && (MAKEFOURCC('D', 'X', '1', '0') == hdr->ddspf.fourCC)) { - // Must be long enough for both headers and magic value - if (file_size.LowPart < (sizeof(DDS_HEADER) + sizeof(uint32_t) + sizeof(DDS_HEADER_DXT10))) { - return E_FAIL; - } - - bDXT10Header = true; - } - - // setup the pointers in the process request - *header = hdr; - ptrdiff_t offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); - *bit_data = dds_data.get() + offset; - *bit_size = file_size.LowPart - offset; - - return S_OK; + if (!header || !bit_data || !bit_size) { + return E_POINTER; + } + + // open the file + UniqueHandle hfile(SafeHandle(CreateFile2(file_name, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr))); + + + if (!hfile) { + return HRESULT_FROM_WIN32(GetLastError()); + } + + // Get the file size + LARGE_INTEGER file_size = { 0 }; + + FILE_STANDARD_INFO file_info; + if (!GetFileInformationByHandleEx(hfile.get(), FileStandardInfo, &file_info, sizeof(file_info))) { + return HRESULT_FROM_WIN32(GetLastError()); + } + file_size = file_info.EndOfFile; + + // File is too big for 32-bit allocation, so reject read + if (file_size.HighPart > 0) { + return E_FAIL; + } + + // Need at least enough data to fill the header and magic number to be a valid DDS + if (file_size.LowPart < (sizeof(DDS_HEADER) + sizeof(uint32_t))) { + return E_FAIL; + } + + // create enough space for the file data + dds_data.reset(new (std::nothrow) uint8_t[file_size.LowPart]); + if (!dds_data) { + return E_OUTOFMEMORY; + } + + // read the data in + DWORD nb_bytes_read = 0; + if (!ReadFile(hfile.get(), dds_data.get(), file_size.LowPart, &nb_bytes_read, nullptr)) { + return HRESULT_FROM_WIN32(GetLastError()); + } + + if (nb_bytes_read < file_size.LowPart) { + return E_FAIL; + } + + // DDS files always start with the same magic number ("DDS ") + uint32_t dw_magic_number = *(const uint32_t*)(dds_data.get()); + if (dw_magic_number != DDS_MAGIC) { + return E_FAIL; + } + + auto hdr = reinterpret_cast(dds_data.get() + sizeof(uint32_t)); + + // Verify header to validate DDS file + if (hdr->size != sizeof(DDS_HEADER) || hdr->ddspf.size != sizeof(DDS_PIXELFORMAT)) { + return E_FAIL; + } + + // Check for DX10 extension + bool bDXT10Header = false; + if ((hdr->ddspf.flags & DDS_FOURCC) && (MAKEFOURCC('D', 'X', '1', '0') == hdr->ddspf.fourCC)) { + // Must be long enough for both headers and magic value + if (file_size.LowPart < (sizeof(DDS_HEADER) + sizeof(uint32_t) + sizeof(DDS_HEADER_DXT10))) { + return E_FAIL; + } + + bDXT10Header = true; + } + + // setup the pointers in the process request + *header = hdr; + ptrdiff_t offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); + *bit_data = dds_data.get() + offset; + *bit_size = file_size.LowPart - offset; + + return S_OK; } //-------------------------------------------------------------------------------------- // Get surface information for a particular format //-------------------------------------------------------------------------------------- static void GetSurfaceInfo(_In_ size_t width, - _In_ size_t height, - _In_ DXGI_FORMAT fmt, - _Out_opt_ size_t* out_nb_bytes, - _Out_opt_ size_t* out_row_bytes, - _Out_opt_ size_t* out_nb_rows) { - size_t nb_bytes = 0; - size_t nb_row_bytes = 0; - size_t nb_rows = 0; - - bool bc = false; - bool packed = false; - bool planar = false; - size_t bpe = 0; - switch (fmt) { - case DXGI_FORMAT_BC1_TYPELESS: - case DXGI_FORMAT_BC1_UNORM: - case DXGI_FORMAT_BC1_UNORM_SRGB: - case DXGI_FORMAT_BC4_TYPELESS: - case DXGI_FORMAT_BC4_UNORM: - case DXGI_FORMAT_BC4_SNORM: - bc = true; - bpe = 8; - break; - - case DXGI_FORMAT_BC2_TYPELESS: - case DXGI_FORMAT_BC2_UNORM: - case DXGI_FORMAT_BC2_UNORM_SRGB: - case DXGI_FORMAT_BC3_TYPELESS: - case DXGI_FORMAT_BC3_UNORM: - case DXGI_FORMAT_BC3_UNORM_SRGB: - case DXGI_FORMAT_BC5_TYPELESS: - case DXGI_FORMAT_BC5_UNORM: - case DXGI_FORMAT_BC5_SNORM: - case DXGI_FORMAT_BC6H_TYPELESS: - case DXGI_FORMAT_BC6H_UF16: - case DXGI_FORMAT_BC6H_SF16: - case DXGI_FORMAT_BC7_TYPELESS: - case DXGI_FORMAT_BC7_UNORM: - case DXGI_FORMAT_BC7_UNORM_SRGB: - bc = true; - bpe = 16; - break; - - case DXGI_FORMAT_R8G8_B8G8_UNORM: - case DXGI_FORMAT_G8R8_G8B8_UNORM: - case DXGI_FORMAT_YUY2: - packed = true; - bpe = 4; - break; - - case DXGI_FORMAT_Y210: - case DXGI_FORMAT_Y216: - packed = true; - bpe = 8; - break; - - case DXGI_FORMAT_NV12: - case DXGI_FORMAT_420_OPAQUE: - planar = true; - bpe = 2; - break; - - case DXGI_FORMAT_P010: - case DXGI_FORMAT_P016: - planar = true; - bpe = 4; - break; - } - - if (bc) { - size_t nb_blocks_wide = 0; - if (width > 0) { - nb_blocks_wide = std::max(1, (width + 3) / 4); - } - size_t nb_blocks_high = 0; - if (height > 0) { - nb_blocks_high = std::max(1, (height + 3) / 4); - } - nb_row_bytes = nb_blocks_wide * bpe; - nb_rows = nb_blocks_high; - nb_bytes = nb_row_bytes * nb_blocks_high; - } - else if (packed) { - nb_row_bytes = ((width + 1) >> 1) * bpe; - nb_rows = height; - nb_bytes = nb_row_bytes * height; - } - else if (fmt == DXGI_FORMAT_NV11) { - nb_row_bytes = ((width + 3) >> 2) * 4; - nb_rows = height * 2; // Direct3D makes this simplifying assumption, although it is larger than the 4:1:1 data - nb_bytes = nb_row_bytes * nb_rows; - } - else if (planar) { - nb_row_bytes = ((width + 1) >> 1) * bpe; - nb_bytes = (nb_row_bytes * height) + ((nb_row_bytes * height + 1) >> 1); - nb_rows = height + ((height + 1) >> 1); - } - else { - size_t bpp = BitsPerPixel(fmt); - nb_row_bytes = (width * bpp + 7) / 8; // round up to nearest byte - nb_rows = height; - nb_bytes = nb_row_bytes * height; - } - - if (out_nb_bytes) { - *out_nb_bytes = nb_bytes; - } - if (out_row_bytes) { - *out_row_bytes = nb_row_bytes; - } - if (out_nb_rows) { - *out_nb_rows = nb_rows; - } + _In_ size_t height, + _In_ DXGI_FORMAT fmt, + _Out_opt_ size_t* out_nb_bytes, + _Out_opt_ size_t* out_row_bytes, + _Out_opt_ size_t* out_nb_rows) { + size_t nb_bytes = 0; + size_t nb_row_bytes = 0; + size_t nb_rows = 0; + + bool bc = false; + bool packed = false; + bool planar = false; + size_t bpe = 0; + switch (fmt) { + case DXGI_FORMAT_BC1_TYPELESS: + case DXGI_FORMAT_BC1_UNORM: + case DXGI_FORMAT_BC1_UNORM_SRGB: + case DXGI_FORMAT_BC4_TYPELESS: + case DXGI_FORMAT_BC4_UNORM: + case DXGI_FORMAT_BC4_SNORM: + bc = true; + bpe = 8; + break; + + case DXGI_FORMAT_BC2_TYPELESS: + case DXGI_FORMAT_BC2_UNORM: + case DXGI_FORMAT_BC2_UNORM_SRGB: + case DXGI_FORMAT_BC3_TYPELESS: + case DXGI_FORMAT_BC3_UNORM: + case DXGI_FORMAT_BC3_UNORM_SRGB: + case DXGI_FORMAT_BC5_TYPELESS: + case DXGI_FORMAT_BC5_UNORM: + case DXGI_FORMAT_BC5_SNORM: + case DXGI_FORMAT_BC6H_TYPELESS: + case DXGI_FORMAT_BC6H_UF16: + case DXGI_FORMAT_BC6H_SF16: + case DXGI_FORMAT_BC7_TYPELESS: + case DXGI_FORMAT_BC7_UNORM: + case DXGI_FORMAT_BC7_UNORM_SRGB: + bc = true; + bpe = 16; + break; + + case DXGI_FORMAT_R8G8_B8G8_UNORM: + case DXGI_FORMAT_G8R8_G8B8_UNORM: + case DXGI_FORMAT_YUY2: + packed = true; + bpe = 4; + break; + + case DXGI_FORMAT_Y210: + case DXGI_FORMAT_Y216: + packed = true; + bpe = 8; + break; + + case DXGI_FORMAT_NV12: + case DXGI_FORMAT_420_OPAQUE: + planar = true; + bpe = 2; + break; + + case DXGI_FORMAT_P010: + case DXGI_FORMAT_P016: + planar = true; + bpe = 4; + break; + } + + if (bc) { + size_t nb_blocks_wide = 0; + if (width > 0) { + nb_blocks_wide = std::max(1, (width + 3) / 4); + } + size_t nb_blocks_high = 0; + if (height > 0) { + nb_blocks_high = std::max(1, (height + 3) / 4); + } + nb_row_bytes = nb_blocks_wide * bpe; + nb_rows = nb_blocks_high; + nb_bytes = nb_row_bytes * nb_blocks_high; + } + else if (packed) { + nb_row_bytes = ((width + 1) >> 1) * bpe; + nb_rows = height; + nb_bytes = nb_row_bytes * height; + } + else if (fmt == DXGI_FORMAT_NV11) { + nb_row_bytes = ((width + 3) >> 2) * 4; + nb_rows = height * 2; // Direct3D makes this simplifying assumption, although it is larger than the 4:1:1 data + nb_bytes = nb_row_bytes * nb_rows; + } + else if (planar) { + nb_row_bytes = ((width + 1) >> 1) * bpe; + nb_bytes = (nb_row_bytes * height) + ((nb_row_bytes * height + 1) >> 1); + nb_rows = height + ((height + 1) >> 1); + } + else { + size_t bpp = BitsPerPixel(fmt); + nb_row_bytes = (width * bpp + 7) / 8; // round up to nearest byte + nb_rows = height; + nb_bytes = nb_row_bytes * height; + } + + if (out_nb_bytes) { + *out_nb_bytes = nb_bytes; + } + if (out_row_bytes) { + *out_row_bytes = nb_row_bytes; + } + if (out_nb_rows) { + *out_nb_rows = nb_rows; + } } #define ISBITMASK( r,g,b,a ) ( ddpf.RBitMask == r && ddpf.GBitMask == g && ddpf.BBitMask == b && ddpf.ABitMask == a ) static DXGI_FORMAT GetDXGIFormat(const DDS_PIXELFORMAT &ddpf) { - if (ddpf.flags & DDS_RGB) { - // Note that sRGB formats are written using the "DX10" extended header - - switch (ddpf.RGBBitCount) { - case 32: - if (ISBITMASK(0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000)) { - return DXGI_FORMAT_R8G8B8A8_UNORM; - } - - if (ISBITMASK(0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000)) { - return DXGI_FORMAT_B8G8R8A8_UNORM; - } - - if (ISBITMASK(0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000)) { - return DXGI_FORMAT_B8G8R8X8_UNORM; - } - - // No DXGI format maps to ISBITMASK(0x000000ff,0x0000ff00,0x00ff0000,0x00000000) aka D3DFMT_X8B8G8R8 - - // Note that many common DDS reader/writers (including D3DX) swap the - // the RED/BLUE masks for 10:10:10:2 formats. We assumme - // below that the 'backwards' header mask is being used since it is most - // likely written by D3DX. The more robust solution is to use the 'DX10' - // header extension and specify the DXGI_FORMAT_R10G10B10A2_UNORM format directly - - // For 'correct' writers, this should be 0x000003ff,0x000ffc00,0x3ff00000 for RGB data - if (ISBITMASK(0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000)) { - return DXGI_FORMAT_R10G10B10A2_UNORM; - } - - // No DXGI format maps to ISBITMASK(0x000003ff,0x000ffc00,0x3ff00000,0xc0000000) aka D3DFMT_A2R10G10B10 - - if (ISBITMASK(0x0000ffff, 0xffff0000, 0x00000000, 0x00000000)) { - return DXGI_FORMAT_R16G16_UNORM; - } - - if (ISBITMASK(0xffffffff, 0x00000000, 0x00000000, 0x00000000)) { - // Only 32-bit color channel format in D3D9 was R32F - return DXGI_FORMAT_R32_FLOAT; // D3DX writes this out as a FourCC of 114 - } - break; - - case 24: - // No 24bpp DXGI formats aka D3DFMT_R8G8B8 - break; - - case 16: - if (ISBITMASK(0x7c00, 0x03e0, 0x001f, 0x8000)) { - return DXGI_FORMAT_B5G5R5A1_UNORM; - } - if (ISBITMASK(0xf800, 0x07e0, 0x001f, 0x0000)) { - return DXGI_FORMAT_B5G6R5_UNORM; - } - - // No DXGI format maps to ISBITMASK(0x7c00,0x03e0,0x001f,0x0000) aka D3DFMT_X1R5G5B5 - - if (ISBITMASK(0x0f00, 0x00f0, 0x000f, 0xf000)) { - return DXGI_FORMAT_B4G4R4A4_UNORM; - } - - // No DXGI format maps to ISBITMASK(0x0f00,0x00f0,0x000f,0x0000) aka D3DFMT_X4R4G4B4 - - // No 3:3:2, 3:3:2:8, or paletted DXGI formats aka D3DFMT_A8R3G3B2, D3DFMT_R3G3B2, D3DFMT_P8, D3DFMT_A8P8, etc. - break; - } - } - else if (ddpf.flags & DDS_LUMINANCE) { - if (8 == ddpf.RGBBitCount) { - if (ISBITMASK(0x000000ff, 0x00000000, 0x00000000, 0x00000000)) { - return DXGI_FORMAT_R8_UNORM; // D3DX10/11 writes this out as DX10 extension - } - - // No DXGI format maps to ISBITMASK(0x0f,0x00,0x00,0xf0) aka D3DFMT_A4L4 - } - - if (16 == ddpf.RGBBitCount) { - if (ISBITMASK(0x0000ffff, 0x00000000, 0x00000000, 0x00000000)) { - return DXGI_FORMAT_R16_UNORM; // D3DX10/11 writes this out as DX10 extension - } - if (ISBITMASK(0x000000ff, 0x00000000, 0x00000000, 0x0000ff00)) { - return DXGI_FORMAT_R8G8_UNORM; // D3DX10/11 writes this out as DX10 extension - } - } - } - else if (ddpf.flags & DDS_ALPHA) { - if (8 == ddpf.RGBBitCount) { - return DXGI_FORMAT_A8_UNORM; - } - } - else if (ddpf.flags & DDS_FOURCC) { - if (MAKEFOURCC('D', 'X', 'T', '1') == ddpf.fourCC) { - return DXGI_FORMAT_BC1_UNORM; - } - if (MAKEFOURCC('D', 'X', 'T', '3') == ddpf.fourCC) { - return DXGI_FORMAT_BC2_UNORM; - } - if (MAKEFOURCC('D', 'X', 'T', '5') == ddpf.fourCC) { - return DXGI_FORMAT_BC3_UNORM; - } - - // While pre-mulitplied alpha isn't directly supported by the DXGI formats, - // they are basically the same as these BC formats so they can be mapped - if (MAKEFOURCC('D', 'X', 'T', '2') == ddpf.fourCC) { - return DXGI_FORMAT_BC2_UNORM; - } - if (MAKEFOURCC('D', 'X', 'T', '4') == ddpf.fourCC) { - return DXGI_FORMAT_BC3_UNORM; - } - - if (MAKEFOURCC('A', 'T', 'I', '1') == ddpf.fourCC) { - return DXGI_FORMAT_BC4_UNORM; - } - if (MAKEFOURCC('B', 'C', '4', 'U') == ddpf.fourCC) { - return DXGI_FORMAT_BC4_UNORM; - } - if (MAKEFOURCC('B', 'C', '4', 'S') == ddpf.fourCC) { - return DXGI_FORMAT_BC4_SNORM; - } - - if (MAKEFOURCC('A', 'T', 'I', '2') == ddpf.fourCC) { - return DXGI_FORMAT_BC5_UNORM; - } - if (MAKEFOURCC('B', 'C', '5', 'U') == ddpf.fourCC) { - return DXGI_FORMAT_BC5_UNORM; - } - if (MAKEFOURCC('B', 'C', '5', 'S') == ddpf.fourCC) { - return DXGI_FORMAT_BC5_SNORM; - } - - // BC6H and BC7 are written using the "DX10" extended header - - if (MAKEFOURCC('R', 'G', 'B', 'G') == ddpf.fourCC) { - return DXGI_FORMAT_R8G8_B8G8_UNORM; - } - if (MAKEFOURCC('G', 'R', 'G', 'B') == ddpf.fourCC) { - return DXGI_FORMAT_G8R8_G8B8_UNORM; - } - - if (MAKEFOURCC('Y', 'U', 'Y', '2') == ddpf.fourCC) { - return DXGI_FORMAT_YUY2; - } - - // Check for D3DFORMAT enums being set here - switch (ddpf.fourCC) { - case 36: // D3DFMT_A16B16G16R16 - return DXGI_FORMAT_R16G16B16A16_UNORM; - case 110: // D3DFMT_Q16W16V16U16 - return DXGI_FORMAT_R16G16B16A16_SNORM; - case 111: // D3DFMT_R16F - return DXGI_FORMAT_R16_FLOAT; - case 112: // D3DFMT_G16R16F - return DXGI_FORMAT_R16G16_FLOAT; - case 113: // D3DFMT_A16B16G16R16F - return DXGI_FORMAT_R16G16B16A16_FLOAT; - case 114: // D3DFMT_R32F - return DXGI_FORMAT_R32_FLOAT; - case 115: // D3DFMT_G32R32F - return DXGI_FORMAT_R32G32_FLOAT; - case 116: // D3DFMT_A32B32G32R32F - return DXGI_FORMAT_R32G32B32A32_FLOAT; - } - } - - return DXGI_FORMAT_UNKNOWN; + if (ddpf.flags & DDS_RGB) { + // Note that sRGB formats are written using the "DX10" extended header + + switch (ddpf.RGBBitCount) { + case 32: + if (ISBITMASK(0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000)) { + return DXGI_FORMAT_R8G8B8A8_UNORM; + } + + if (ISBITMASK(0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000)) { + return DXGI_FORMAT_B8G8R8A8_UNORM; + } + + if (ISBITMASK(0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000)) { + return DXGI_FORMAT_B8G8R8X8_UNORM; + } + + // No DXGI format maps to ISBITMASK(0x000000ff,0x0000ff00,0x00ff0000,0x00000000) aka D3DFMT_X8B8G8R8 + + // Note that many common DDS reader/writers (including D3DX) swap the + // the RED/BLUE masks for 10:10:10:2 formats. We assumme + // below that the 'backwards' header mask is being used since it is most + // likely written by D3DX. The more robust solution is to use the 'DX10' + // header extension and specify the DXGI_FORMAT_R10G10B10A2_UNORM format directly + + // For 'correct' writers, this should be 0x000003ff,0x000ffc00,0x3ff00000 for RGB data + if (ISBITMASK(0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000)) { + return DXGI_FORMAT_R10G10B10A2_UNORM; + } + + // No DXGI format maps to ISBITMASK(0x000003ff,0x000ffc00,0x3ff00000,0xc0000000) aka D3DFMT_A2R10G10B10 + + if (ISBITMASK(0x0000ffff, 0xffff0000, 0x00000000, 0x00000000)) { + return DXGI_FORMAT_R16G16_UNORM; + } + + if (ISBITMASK(0xffffffff, 0x00000000, 0x00000000, 0x00000000)) { + // Only 32-bit color channel format in D3D9 was R32F + return DXGI_FORMAT_R32_FLOAT; // D3DX writes this out as a FourCC of 114 + } + break; + + case 24: + // No 24bpp DXGI formats aka D3DFMT_R8G8B8 + break; + + case 16: + if (ISBITMASK(0x7c00, 0x03e0, 0x001f, 0x8000)) { + return DXGI_FORMAT_B5G5R5A1_UNORM; + } + if (ISBITMASK(0xf800, 0x07e0, 0x001f, 0x0000)) { + return DXGI_FORMAT_B5G6R5_UNORM; + } + + // No DXGI format maps to ISBITMASK(0x7c00,0x03e0,0x001f,0x0000) aka D3DFMT_X1R5G5B5 + + if (ISBITMASK(0x0f00, 0x00f0, 0x000f, 0xf000)) { + return DXGI_FORMAT_B4G4R4A4_UNORM; + } + + // No DXGI format maps to ISBITMASK(0x0f00,0x00f0,0x000f,0x0000) aka D3DFMT_X4R4G4B4 + + // No 3:3:2, 3:3:2:8, or paletted DXGI formats aka D3DFMT_A8R3G3B2, D3DFMT_R3G3B2, D3DFMT_P8, D3DFMT_A8P8, etc. + break; + } + } + else if (ddpf.flags & DDS_LUMINANCE) { + if (8 == ddpf.RGBBitCount) { + if (ISBITMASK(0x000000ff, 0x00000000, 0x00000000, 0x00000000)) { + return DXGI_FORMAT_R8_UNORM; // D3DX10/11 writes this out as DX10 extension + } + + // No DXGI format maps to ISBITMASK(0x0f,0x00,0x00,0xf0) aka D3DFMT_A4L4 + } + + if (16 == ddpf.RGBBitCount) { + if (ISBITMASK(0x0000ffff, 0x00000000, 0x00000000, 0x00000000)) { + return DXGI_FORMAT_R16_UNORM; // D3DX10/11 writes this out as DX10 extension + } + if (ISBITMASK(0x000000ff, 0x00000000, 0x00000000, 0x0000ff00)) { + return DXGI_FORMAT_R8G8_UNORM; // D3DX10/11 writes this out as DX10 extension + } + } + } + else if (ddpf.flags & DDS_ALPHA) { + if (8 == ddpf.RGBBitCount) { + return DXGI_FORMAT_A8_UNORM; + } + } + else if (ddpf.flags & DDS_FOURCC) { + if (MAKEFOURCC('D', 'X', 'T', '1') == ddpf.fourCC) { + return DXGI_FORMAT_BC1_UNORM; + } + if (MAKEFOURCC('D', 'X', 'T', '3') == ddpf.fourCC) { + return DXGI_FORMAT_BC2_UNORM; + } + if (MAKEFOURCC('D', 'X', 'T', '5') == ddpf.fourCC) { + return DXGI_FORMAT_BC3_UNORM; + } + + // While pre-mulitplied alpha isn't directly supported by the DXGI formats, + // they are basically the same as these BC formats so they can be mapped + if (MAKEFOURCC('D', 'X', 'T', '2') == ddpf.fourCC) { + return DXGI_FORMAT_BC2_UNORM; + } + if (MAKEFOURCC('D', 'X', 'T', '4') == ddpf.fourCC) { + return DXGI_FORMAT_BC3_UNORM; + } + + if (MAKEFOURCC('A', 'T', 'I', '1') == ddpf.fourCC) { + return DXGI_FORMAT_BC4_UNORM; + } + if (MAKEFOURCC('B', 'C', '4', 'U') == ddpf.fourCC) { + return DXGI_FORMAT_BC4_UNORM; + } + if (MAKEFOURCC('B', 'C', '4', 'S') == ddpf.fourCC) { + return DXGI_FORMAT_BC4_SNORM; + } + + if (MAKEFOURCC('A', 'T', 'I', '2') == ddpf.fourCC) { + return DXGI_FORMAT_BC5_UNORM; + } + if (MAKEFOURCC('B', 'C', '5', 'U') == ddpf.fourCC) { + return DXGI_FORMAT_BC5_UNORM; + } + if (MAKEFOURCC('B', 'C', '5', 'S') == ddpf.fourCC) { + return DXGI_FORMAT_BC5_SNORM; + } + + // BC6H and BC7 are written using the "DX10" extended header + + if (MAKEFOURCC('R', 'G', 'B', 'G') == ddpf.fourCC) { + return DXGI_FORMAT_R8G8_B8G8_UNORM; + } + if (MAKEFOURCC('G', 'R', 'G', 'B') == ddpf.fourCC) { + return DXGI_FORMAT_G8R8_G8B8_UNORM; + } + + if (MAKEFOURCC('Y', 'U', 'Y', '2') == ddpf.fourCC) { + return DXGI_FORMAT_YUY2; + } + + // Check for D3DFORMAT enums being set here + switch (ddpf.fourCC) { + case 36: // D3DFMT_A16B16G16R16 + return DXGI_FORMAT_R16G16B16A16_UNORM; + case 110: // D3DFMT_Q16W16V16U16 + return DXGI_FORMAT_R16G16B16A16_SNORM; + case 111: // D3DFMT_R16F + return DXGI_FORMAT_R16_FLOAT; + case 112: // D3DFMT_G16R16F + return DXGI_FORMAT_R16G16_FLOAT; + case 113: // D3DFMT_A16B16G16R16F + return DXGI_FORMAT_R16G16B16A16_FLOAT; + case 114: // D3DFMT_R32F + return DXGI_FORMAT_R32_FLOAT; + case 115: // D3DFMT_G32R32F + return DXGI_FORMAT_R32G32_FLOAT; + case 116: // D3DFMT_A32B32G32R32F + return DXGI_FORMAT_R32G32B32A32_FLOAT; + } + } + + return DXGI_FORMAT_UNKNOWN; } static DXGI_FORMAT MakeSRGB(_In_ DXGI_FORMAT format) { - switch (format) { - case DXGI_FORMAT_R8G8B8A8_UNORM: - return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; - case DXGI_FORMAT_BC1_UNORM: - return DXGI_FORMAT_BC1_UNORM_SRGB; - case DXGI_FORMAT_BC2_UNORM: - return DXGI_FORMAT_BC2_UNORM_SRGB; - case DXGI_FORMAT_BC3_UNORM: - return DXGI_FORMAT_BC3_UNORM_SRGB; - case DXGI_FORMAT_B8G8R8A8_UNORM: - return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB; - case DXGI_FORMAT_B8G8R8X8_UNORM: - return DXGI_FORMAT_B8G8R8X8_UNORM_SRGB; - case DXGI_FORMAT_BC7_UNORM: - return DXGI_FORMAT_BC7_UNORM_SRGB; - default: - return format; - } + switch (format) { + case DXGI_FORMAT_R8G8B8A8_UNORM: + return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + case DXGI_FORMAT_BC1_UNORM: + return DXGI_FORMAT_BC1_UNORM_SRGB; + case DXGI_FORMAT_BC2_UNORM: + return DXGI_FORMAT_BC2_UNORM_SRGB; + case DXGI_FORMAT_BC3_UNORM: + return DXGI_FORMAT_BC3_UNORM_SRGB; + case DXGI_FORMAT_B8G8R8A8_UNORM: + return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB; + case DXGI_FORMAT_B8G8R8X8_UNORM: + return DXGI_FORMAT_B8G8R8X8_UNORM_SRGB; + case DXGI_FORMAT_BC7_UNORM: + return DXGI_FORMAT_BC7_UNORM_SRGB; + default: + return format; + } } static HRESULT FillInitData(_In_ size_t width, - _In_ size_t height, - _In_ size_t depth, - _In_ size_t mip_count, - _In_ size_t array_size, - _In_ DXGI_FORMAT format, - _In_ size_t maxsize, - _In_ size_t bit_size, - _In_reads_bytes_(bit_size) const uint8_t *bit_data, - _Out_ size_t &twidth, - _Out_ size_t &theight, - _Out_ size_t &tdepth, - _Out_ size_t &skip_mip, - _Out_writes_(mip_count*array_size) D3D11_SUBRESOURCE_DATA *init_data) { - - if (!bit_data || !init_data) { - return E_POINTER; - } - - skip_mip = 0; - twidth = 0; - theight = 0; - tdepth = 0; - - size_t nb_bytes = 0; - size_t row_bytes = 0; - const uint8_t* src_bits = bit_data; - const uint8_t* end_bits = bit_data + bit_size; - - size_t index = 0; - for (size_t j = 0; j < array_size; ++j) { - size_t w = width; - size_t h = height; - size_t d = depth; - for (size_t i = 0; i < mip_count; ++i) { - GetSurfaceInfo(w, h, format, &nb_bytes, &row_bytes, nullptr); - - if ((mip_count <= 1) || !maxsize || (w <= maxsize && h <= maxsize && d <= maxsize)) { - if (!twidth) { - twidth = w; - theight = h; - tdepth = d; - } - - Assert(index < mip_count * array_size); - _Analysis_assume_(index < mip_count * array_size); - init_data[index].pSysMem = (const void*)src_bits; - init_data[index].SysMemPitch = static_cast(row_bytes); - init_data[index].SysMemSlicePitch = static_cast(nb_bytes); - ++index; - } - else if (!j) { - // Count number of skipped mipmaps (first item only) - ++skip_mip; - } - - if (src_bits + (nb_bytes*d) > end_bits) { - return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF); - } - - src_bits += nb_bytes * d; - - w = w >> 1; - h = h >> 1; - d = d >> 1; - if (w == 0) { - w = 1; - } - if (h == 0) { - h = 1; - } - if (d == 0) { - d = 1; - } - } - } - - return (index > 0) ? S_OK : E_FAIL; + _In_ size_t height, + _In_ size_t depth, + _In_ size_t mip_count, + _In_ size_t array_size, + _In_ DXGI_FORMAT format, + _In_ size_t maxsize, + _In_ size_t bit_size, + _In_reads_bytes_(bit_size) const uint8_t *bit_data, + _Out_ size_t &twidth, + _Out_ size_t &theight, + _Out_ size_t &tdepth, + _Out_ size_t &skip_mip, + _Out_writes_(mip_count*array_size) D3D11_SUBRESOURCE_DATA *init_data) { + + if (!bit_data || !init_data) { + return E_POINTER; + } + + skip_mip = 0; + twidth = 0; + theight = 0; + tdepth = 0; + + size_t nb_bytes = 0; + size_t row_bytes = 0; + const uint8_t* src_bits = bit_data; + const uint8_t* end_bits = bit_data + bit_size; + + size_t index = 0; + for (size_t j = 0; j < array_size; ++j) { + size_t w = width; + size_t h = height; + size_t d = depth; + for (size_t i = 0; i < mip_count; ++i) { + GetSurfaceInfo(w, h, format, &nb_bytes, &row_bytes, nullptr); + + if ((mip_count <= 1) || !maxsize || (w <= maxsize && h <= maxsize && d <= maxsize)) { + if (!twidth) { + twidth = w; + theight = h; + tdepth = d; + } + + Assert(index < mip_count * array_size); + _Analysis_assume_(index < mip_count * array_size); + init_data[index].pSysMem = (const void*)src_bits; + init_data[index].SysMemPitch = static_cast(row_bytes); + init_data[index].SysMemSlicePitch = static_cast(nb_bytes); + ++index; + } + else if (!j) { + // Count number of skipped mipmaps (first item only) + ++skip_mip; + } + + if (src_bits + (nb_bytes*d) > end_bits) { + return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF); + } + + src_bits += nb_bytes * d; + + w = w >> 1; + h = h >> 1; + d = d >> 1; + if (w == 0) { + w = 1; + } + if (h == 0) { + h = 1; + } + if (d == 0) { + d = 1; + } + } + } + + return (index > 0) ? S_OK : E_FAIL; } -static HRESULT CreateD3DResources(_In_ ID3D11Device2 &device, - _In_ uint32_t res_dim, - _In_ size_t width, - _In_ size_t height, - _In_ size_t depth, - _In_ size_t mip_count, - _In_ size_t array_size, - _In_ DXGI_FORMAT format, - _In_ D3D11_USAGE usage, - _In_ uint32_t bindFlags, - _In_ uint32_t cpu_access_flags, - _In_ uint32_t misc_flags, - _In_ bool forceSRGB, - _In_ bool is_cube_map, - _In_reads_opt_(mip_count*array_size) D3D11_SUBRESOURCE_DATA *init_data, - _Outptr_opt_ ID3D11Resource **texture, - _Outptr_opt_ ID3D11ShaderResourceView **texture_view) { - - HRESULT hr = E_FAIL; - - if (forceSRGB) { - format = MakeSRGB(format); - } - - switch (res_dim) { - case D3D11_RESOURCE_DIMENSION_TEXTURE1D: { - D3D11_TEXTURE1D_DESC desc; - desc.Width = static_cast(width); - desc.MipLevels = static_cast(mip_count); - desc.ArraySize = static_cast(array_size); - desc.Format = format; - desc.Usage = usage; - desc.BindFlags = bindFlags; - desc.CPUAccessFlags = cpu_access_flags; - desc.MiscFlags = misc_flags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; - - ID3D11Texture1D* tex = nullptr; - hr = device.CreateTexture1D(&desc, init_data, &tex); - if (SUCCEEDED(hr) && tex != 0) { - if (texture_view != 0) { - D3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_view; - memset(&shader_resource_view, 0, sizeof(shader_resource_view)); - shader_resource_view.Format = format; - - if (array_size > 1) { - shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY; - shader_resource_view.Texture1DArray.MipLevels = (!mip_count) ? -1 : desc.MipLevels; - shader_resource_view.Texture1DArray.ArraySize = static_cast(array_size); - } - else { - shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D; - shader_resource_view.Texture1D.MipLevels = (!mip_count) ? -1 : desc.MipLevels; - } - - hr = device.CreateShaderResourceView(tex, &shader_resource_view, texture_view); - if (FAILED(hr)) { - tex->Release(); - return hr; - } - } - - if (texture != 0) { - *texture = tex; - } - else { - SetDebugObjectName(tex, "DDSTextureLoader"); - tex->Release(); - } - } - } - break; - - case D3D11_RESOURCE_DIMENSION_TEXTURE2D: { - D3D11_TEXTURE2D_DESC desc; - desc.Width = static_cast(width); - desc.Height = static_cast(height); - desc.MipLevels = static_cast(mip_count); - desc.ArraySize = static_cast(array_size); - desc.Format = format; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = usage; - desc.BindFlags = bindFlags; - desc.CPUAccessFlags = cpu_access_flags; - if (is_cube_map) { - desc.MiscFlags = misc_flags | D3D11_RESOURCE_MISC_TEXTURECUBE; - } - else { - desc.MiscFlags = misc_flags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; - } - - ID3D11Texture2D *tex = nullptr; - hr = device.CreateTexture2D(&desc, init_data, &tex); - if (SUCCEEDED(hr) && tex != 0) { - if (texture_view != 0) { - D3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_view; - memset(&shader_resource_view, 0, sizeof(shader_resource_view)); - shader_resource_view.Format = format; - - if (is_cube_map) { - if (array_size > 6) { - shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY; - shader_resource_view.TextureCubeArray.MipLevels = (!mip_count) ? -1 : desc.MipLevels; - - // Earlier we set array_size to (NumCubes * 6) - shader_resource_view.TextureCubeArray.NumCubes = static_cast(array_size / 6); - } - else { - shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - shader_resource_view.TextureCube.MipLevels = (!mip_count) ? -1 : desc.MipLevels; - } - } - else if (array_size > 1) { - shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - shader_resource_view.Texture2DArray.MipLevels = (!mip_count) ? -1 : desc.MipLevels; - shader_resource_view.Texture2DArray.ArraySize = static_cast(array_size); - } - else { - shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - shader_resource_view.Texture2D.MipLevels = (!mip_count) ? -1 : desc.MipLevels; - } - - hr = device.CreateShaderResourceView(tex, &shader_resource_view,texture_view); - if (FAILED(hr)) { - tex->Release(); - return hr; - } - } - - if (texture != 0) - { - *texture = tex; - } - else - { - SetDebugObjectName(tex, "DDSTextureLoader"); - tex->Release(); - } - } - } - break; - - case D3D11_RESOURCE_DIMENSION_TEXTURE3D: { - D3D11_TEXTURE3D_DESC desc; - desc.Width = static_cast(width); - desc.Height = static_cast(height); - desc.Depth = static_cast(depth); - desc.MipLevels = static_cast(mip_count); - desc.Format = format; - desc.Usage = usage; - desc.BindFlags = bindFlags; - desc.CPUAccessFlags = cpu_access_flags; - desc.MiscFlags = misc_flags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; - - ID3D11Texture3D *tex = nullptr; - hr = device.CreateTexture3D(&desc, init_data, &tex); - if (SUCCEEDED(hr) && tex != 0) { - if (texture_view != 0) { - D3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_view; - memset(&shader_resource_view, 0, sizeof(shader_resource_view)); - shader_resource_view.Format = format; - - shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; - shader_resource_view.Texture3D.MipLevels = (!mip_count) ? -1 : desc.MipLevels; - - hr = device.CreateShaderResourceView(tex, &shader_resource_view, texture_view); - if (FAILED(hr)) { - tex->Release(); - return hr; - } - } - - if (texture != 0) { - *texture = tex; - } - else { - SetDebugObjectName(tex, "DDSTextureLoader"); - tex->Release(); - } - } - } - break; - } - - return hr; +static HRESULT CreateD3DResources(_In_ ID3D11Device2 *device, + _In_ uint32_t res_dim, + _In_ size_t width, + _In_ size_t height, + _In_ size_t depth, + _In_ size_t mip_count, + _In_ size_t array_size, + _In_ DXGI_FORMAT format, + _In_ D3D11_USAGE usage, + _In_ uint32_t bindFlags, + _In_ uint32_t cpu_access_flags, + _In_ uint32_t misc_flags, + _In_ bool forceSRGB, + _In_ bool is_cube_map, + _In_reads_opt_(mip_count*array_size) D3D11_SUBRESOURCE_DATA *init_data, + _Outptr_opt_ ID3D11Resource **texture, + _Outptr_opt_ ID3D11ShaderResourceView **texture_view) { + + if (!device) { + return E_POINTER; + } + + HRESULT hr = E_FAIL; + + if (forceSRGB) { + format = MakeSRGB(format); + } + + switch (res_dim) { + case D3D11_RESOURCE_DIMENSION_TEXTURE1D: { + D3D11_TEXTURE1D_DESC desc; + desc.Width = static_cast(width); + desc.MipLevels = static_cast(mip_count); + desc.ArraySize = static_cast(array_size); + desc.Format = format; + desc.Usage = usage; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = cpu_access_flags; + desc.MiscFlags = misc_flags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; + + ID3D11Texture1D* tex = nullptr; + hr = device->CreateTexture1D(&desc, init_data, &tex); + if (SUCCEEDED(hr) && tex != 0) { + if (texture_view != 0) { + D3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_view; + memset(&shader_resource_view, 0, sizeof(shader_resource_view)); + shader_resource_view.Format = format; + + if (array_size > 1) { + shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY; + shader_resource_view.Texture1DArray.MipLevels = (!mip_count) ? -1 : desc.MipLevels; + shader_resource_view.Texture1DArray.ArraySize = static_cast(array_size); + } + else { + shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D; + shader_resource_view.Texture1D.MipLevels = (!mip_count) ? -1 : desc.MipLevels; + } + + hr = device->CreateShaderResourceView(tex, &shader_resource_view, texture_view); + if (FAILED(hr)) { + tex->Release(); + return hr; + } + } + + if (texture != 0) { + *texture = tex; + } + else { + SetDebugObjectName(tex, "DDSTextureLoader"); + tex->Release(); + } + } + } + break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE2D: { + D3D11_TEXTURE2D_DESC desc; + desc.Width = static_cast(width); + desc.Height = static_cast(height); + desc.MipLevels = static_cast(mip_count); + desc.ArraySize = static_cast(array_size); + desc.Format = format; + desc.SampleDesc.Count = 1; + desc.SampleDesc.Quality = 0; + desc.Usage = usage; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = cpu_access_flags; + if (is_cube_map) { + desc.MiscFlags = misc_flags | D3D11_RESOURCE_MISC_TEXTURECUBE; + } + else { + desc.MiscFlags = misc_flags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; + } + + ID3D11Texture2D *tex = nullptr; + hr = device->CreateTexture2D(&desc, init_data, &tex); + if (SUCCEEDED(hr) && tex != 0) { + if (texture_view != 0) { + D3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_view; + memset(&shader_resource_view, 0, sizeof(shader_resource_view)); + shader_resource_view.Format = format; + + if (is_cube_map) { + if (array_size > 6) { + shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY; + shader_resource_view.TextureCubeArray.MipLevels = (!mip_count) ? -1 : desc.MipLevels; + + // Earlier we set array_size to (NumCubes * 6) + shader_resource_view.TextureCubeArray.NumCubes = static_cast(array_size / 6); + } + else { + shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; + shader_resource_view.TextureCube.MipLevels = (!mip_count) ? -1 : desc.MipLevels; + } + } + else if (array_size > 1) { + shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; + shader_resource_view.Texture2DArray.MipLevels = (!mip_count) ? -1 : desc.MipLevels; + shader_resource_view.Texture2DArray.ArraySize = static_cast(array_size); + } + else { + shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + shader_resource_view.Texture2D.MipLevels = (!mip_count) ? -1 : desc.MipLevels; + } + + hr = device->CreateShaderResourceView(tex, &shader_resource_view,texture_view); + if (FAILED(hr)) { + tex->Release(); + return hr; + } + } + + if (texture != 0) + { + *texture = tex; + } + else + { + SetDebugObjectName(tex, "DDSTextureLoader"); + tex->Release(); + } + } + } + break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE3D: { + D3D11_TEXTURE3D_DESC desc; + desc.Width = static_cast(width); + desc.Height = static_cast(height); + desc.Depth = static_cast(depth); + desc.MipLevels = static_cast(mip_count); + desc.Format = format; + desc.Usage = usage; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = cpu_access_flags; + desc.MiscFlags = misc_flags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; + + ID3D11Texture3D *tex = nullptr; + hr = device->CreateTexture3D(&desc, init_data, &tex); + if (SUCCEEDED(hr) && tex != 0) { + if (texture_view != 0) { + D3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_view; + memset(&shader_resource_view, 0, sizeof(shader_resource_view)); + shader_resource_view.Format = format; + + shader_resource_view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; + shader_resource_view.Texture3D.MipLevels = (!mip_count) ? -1 : desc.MipLevels; + + hr = device->CreateShaderResourceView(tex, &shader_resource_view, texture_view); + if (FAILED(hr)) { + tex->Release(); + return hr; + } + } + + if (texture != 0) { + *texture = tex; + } + else { + SetDebugObjectName(tex, "DDSTextureLoader"); + tex->Release(); + } + } + } + break; + } + + return hr; } -static HRESULT CreateTextureFromDDS(_In_ ID3D11Device2 &device, - _In_opt_ ID3D11DeviceContext *d3dContext, - _In_ const DDS_HEADER *header, - _In_reads_bytes_(bit_size) const uint8_t *bit_data, - _In_ size_t bit_size, - _In_ size_t maxsize, - _In_ D3D11_USAGE usage, - _In_ uint32_t bindFlags, - _In_ uint32_t cpu_access_flags, - _In_ uint32_t misc_flags, - _In_ bool forceSRGB, - _Outptr_opt_ ID3D11Resource **texture, - _Outptr_opt_ ID3D11ShaderResourceView **texture_view) { - - HRESULT hr = S_OK; - - size_t width = header->width; - size_t height = header->height; - size_t depth = header->depth; - - uint32_t res_dim = D3D11_RESOURCE_DIMENSION_UNKNOWN; - size_t array_size = 1; - DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN; - bool is_cube_map = false; - - size_t mip_count = header->mip_map_count; - if (0 == mip_count) { - mip_count = 1; - } - - if ((header->ddspf.flags & DDS_FOURCC) && (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)) { - auto d3d10ext = reinterpret_cast((const char*)header + sizeof(DDS_HEADER)); - - array_size = d3d10ext->array_size; - if (array_size == 0) { - return HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - } - - switch (d3d10ext->dxgi_format) { - case DXGI_FORMAT_AI44: - case DXGI_FORMAT_IA44: - case DXGI_FORMAT_P8: - case DXGI_FORMAT_A8P8: - return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - - default: - if (BitsPerPixel(d3d10ext->dxgi_format) == 0) { - return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - } - } - - format = d3d10ext->dxgi_format; - - switch (d3d10ext->resource_dimension) { - case D3D11_RESOURCE_DIMENSION_TEXTURE1D: - // D3DX writes 1D textures with a fixed Height of 1 - if ((header->flags & DDS_HEIGHT) && height != 1) { - return HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - } - height = depth = 1; - break; - - case D3D11_RESOURCE_DIMENSION_TEXTURE2D: - if (d3d10ext->misc_flag & D3D11_RESOURCE_MISC_TEXTURECUBE) { - array_size *= 6; - is_cube_map = true; - } - depth = 1; - break; - - case D3D11_RESOURCE_DIMENSION_TEXTURE3D: - if (!(header->flags & DDS_HEADER_FLAGS_VOLUME)) { - return HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - } - - if (array_size > 1) { - return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - } - break; - - default: - return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - } - - res_dim = d3d10ext->resource_dimension; - } - else { - format = GetDXGIFormat(header->ddspf); - - if (format == DXGI_FORMAT_UNKNOWN) { - return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - } - - if (header->flags & DDS_HEADER_FLAGS_VOLUME) { - res_dim = D3D11_RESOURCE_DIMENSION_TEXTURE3D; - } - else { - if (header->caps2 & DDS_CUBEMAP) { - // We require all six faces to be defined - if ((header->caps2 & DDS_CUBEMAP_ALLFACES) != DDS_CUBEMAP_ALLFACES) { - return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - } - - array_size = 6; - is_cube_map = true; - } - - depth = 1; - res_dim = D3D11_RESOURCE_DIMENSION_TEXTURE2D; - - // Note there's no way for a legacy Direct3D 9 DDS to express a '1D' texture - } - - Assert(BitsPerPixel(format) != 0); - } - - // Bound sizes (for security purposes we don't trust DDS file metadata larger than the D3D 11.x hardware requirements) - if (mip_count > D3D11_REQ_MIP_LEVELS) { - return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - } - - switch (res_dim) { - case D3D11_RESOURCE_DIMENSION_TEXTURE1D: - if ((array_size > D3D11_REQ_TEXTURE1D_ARRAY_AXIS_DIMENSION) || (width > D3D11_REQ_TEXTURE1D_U_DIMENSION)) { - return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - } - break; - - case D3D11_RESOURCE_DIMENSION_TEXTURE2D: - if (is_cube_map) { - // This is the right bound because we set array_size to (NumCubes*6) above - if ((array_size > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) || - (width > D3D11_REQ_TEXTURECUBE_DIMENSION) || - (height > D3D11_REQ_TEXTURECUBE_DIMENSION)) { - return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - } - } - else if ((array_size > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) || - (width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION) || - (height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) { - return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - } - break; - - case D3D11_RESOURCE_DIMENSION_TEXTURE3D: - if ((array_size > 1) || - (width > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION) || - (height > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION) || - (depth > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION)) { - return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - } - break; - } - - bool autogen = false; - if (mip_count == 1 && d3dContext != 0 && texture_view != 0) {// Must have context and shader-view to auto generate mipmaps - // See if format is supported for auto-gen mipmaps (varies by feature level) - UINT fmtSupport = 0; - hr = device.CheckFormatSupport(format, &fmtSupport); - if (SUCCEEDED(hr) && (fmtSupport & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN)) { - // 10level9 feature levels do not support auto-gen mipgen for volume textures - if ((res_dim != D3D11_RESOURCE_DIMENSION_TEXTURE3D) || (device.GetFeatureLevel() >= D3D_FEATURE_LEVEL_10_0)) { - autogen = true; - } - } - } - - if (autogen) { - // Create texture with auto-generated mipmaps - ID3D11Resource *tex = nullptr; - hr = CreateD3DResources(device, res_dim, width, height, depth, 0, array_size, - format, usage, - bindFlags | D3D11_BIND_RENDER_TARGET, - cpu_access_flags, - misc_flags | D3D11_RESOURCE_MISC_GENERATE_MIPS, forceSRGB, - is_cube_map, nullptr, &tex, texture_view); - if (SUCCEEDED(hr)) { - size_t nb_bytes = 0; - size_t nb_row_bytes = 0; - GetSurfaceInfo(width, height, format, &nb_bytes, &nb_row_bytes, nullptr); - - if (nb_bytes > bit_size) { - (*texture_view)->Release(); - *texture_view = nullptr; - tex->Release(); - return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF); - } - - if (array_size > 1) { - D3D11_SHADER_RESOURCE_VIEW_DESC desc; - (*texture_view)->GetDesc(&desc); - - UINT mipLevels = 1; - - switch (desc.ViewDimension) { - case D3D_SRV_DIMENSION_TEXTURE1D: mipLevels = desc.Texture1D.MipLevels; break; - case D3D_SRV_DIMENSION_TEXTURE1DARRAY: mipLevels = desc.Texture1DArray.MipLevels; break; - case D3D_SRV_DIMENSION_TEXTURE2D: mipLevels = desc.Texture2D.MipLevels; break; - case D3D_SRV_DIMENSION_TEXTURE2DARRAY: mipLevels = desc.Texture2DArray.MipLevels; break; - case D3D_SRV_DIMENSION_TEXTURECUBE: mipLevels = desc.TextureCube.MipLevels; break; - case D3D_SRV_DIMENSION_TEXTURECUBEARRAY:mipLevels = desc.TextureCubeArray.MipLevels; break; - default: - (*texture_view)->Release(); - *texture_view = nullptr; - tex->Release(); - return E_UNEXPECTED; - } - - const uint8_t* src_bits = bit_data; - const uint8_t* end_bits = bit_data + bit_size; - for (UINT item = 0; item < array_size; ++item) { - if ((src_bits + nb_bytes) > end_bits) { - (*texture_view)->Release(); - *texture_view = nullptr; - tex->Release(); - return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF); - } - - UINT res = D3D11CalcSubresource(0, item, mipLevels); - d3dContext->UpdateSubresource(tex, res, nullptr, src_bits, static_cast(nb_row_bytes), static_cast(nb_bytes)); - src_bits += nb_bytes; - } - } - else { - d3dContext->UpdateSubresource(tex, 0, nullptr, bit_data, static_cast(nb_row_bytes), static_cast(nb_bytes)); - } - - d3dContext->GenerateMips(*texture_view); - - if (texture) { - *texture = tex; - } - else { - tex->Release(); - } - } - } - else { - // Create the texture - std::unique_ptr init_data(new (std::nothrow) D3D11_SUBRESOURCE_DATA[mip_count * array_size]); - if (!init_data) { - return E_OUTOFMEMORY; - } - - size_t skip_mip = 0; - size_t twidth = 0; - size_t theight = 0; - size_t tdepth = 0; - hr = FillInitData(width, height, depth, mip_count, array_size, format, maxsize, bit_size, bit_data, - twidth, theight, tdepth, skip_mip, init_data.get()); - - if (SUCCEEDED(hr)) { - hr = CreateD3DResources(device, res_dim, twidth, theight, tdepth, mip_count - skip_mip, array_size, - format, usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, - is_cube_map, init_data.get(), texture, texture_view); - - if (FAILED(hr) && !maxsize && (mip_count > 1)) { - // Retry with a maxsize determined by feature level - switch (device.GetFeatureLevel()) { - case D3D_FEATURE_LEVEL_9_1: - case D3D_FEATURE_LEVEL_9_2: - if (is_cube_map) { - maxsize = 512 /*D3D_FL9_1_REQ_TEXTURECUBE_DIMENSION*/; - } - else { - maxsize = (res_dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D) - ? 256 /*D3D_FL9_1_REQ_TEXTURE3D_U_V_OR_W_DIMENSION*/ - : 2048 /*D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION*/; - } - break; - - case D3D_FEATURE_LEVEL_9_3: - maxsize = (res_dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D) - ? 256 /*D3D_FL9_1_REQ_TEXTURE3D_U_V_OR_W_DIMENSION*/ - : 4096 /*D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION*/; - break; - - default: // D3D_FEATURE_LEVEL_10_0 & D3D_FEATURE_LEVEL_10_1 - maxsize = (res_dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D) - ? 2048 /*D3D10_REQ_TEXTURE3D_U_V_OR_W_DIMENSION*/ - : 8192 /*D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION*/; - break; - } - - hr = FillInitData(width, height, depth, mip_count, array_size, format, maxsize, bit_size, bit_data, - twidth, theight, tdepth, skip_mip, init_data.get()); - if (SUCCEEDED(hr)) { - hr = CreateD3DResources(device, res_dim, twidth, theight, tdepth, mip_count - skip_mip, array_size, - format, usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, - is_cube_map, init_data.get(), texture, texture_view); - } - } - } - } - - return hr; +static HRESULT CreateTextureFromDDS(_In_ ID3D11Device2 *device, + _In_opt_ ID3D11DeviceContext *device_context, + _In_ const DDS_HEADER *header, + _In_reads_bytes_(bit_size) const uint8_t *bit_data, + _In_ size_t bit_size, + _In_ size_t maxsize, + _In_ D3D11_USAGE usage, + _In_ uint32_t bindFlags, + _In_ uint32_t cpu_access_flags, + _In_ uint32_t misc_flags, + _In_ bool forceSRGB, + _Outptr_opt_ ID3D11Resource **texture, + _Outptr_opt_ ID3D11ShaderResourceView **texture_view) { + + HRESULT hr = S_OK; + + size_t width = header->width; + size_t height = header->height; + size_t depth = header->depth; + + uint32_t res_dim = D3D11_RESOURCE_DIMENSION_UNKNOWN; + size_t array_size = 1; + DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN; + bool is_cube_map = false; + + size_t mip_count = header->mip_map_count; + if (0 == mip_count) { + mip_count = 1; + } + + if ((header->ddspf.flags & DDS_FOURCC) && (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)) { + auto d3d10ext = reinterpret_cast((const char*)header + sizeof(DDS_HEADER)); + + array_size = d3d10ext->array_size; + if (array_size == 0) { + return HRESULT_FROM_WIN32(ERROR_INVALID_DATA); + } + + switch (d3d10ext->dxgi_format) { + case DXGI_FORMAT_AI44: + case DXGI_FORMAT_IA44: + case DXGI_FORMAT_P8: + case DXGI_FORMAT_A8P8: + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + + default: + if (BitsPerPixel(d3d10ext->dxgi_format) == 0) { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + } + + format = d3d10ext->dxgi_format; + + switch (d3d10ext->resource_dimension) { + case D3D11_RESOURCE_DIMENSION_TEXTURE1D: + // D3DX writes 1D textures with a fixed Height of 1 + if ((header->flags & DDS_HEIGHT) && height != 1) { + return HRESULT_FROM_WIN32(ERROR_INVALID_DATA); + } + height = depth = 1; + break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE2D: + if (d3d10ext->misc_flag & D3D11_RESOURCE_MISC_TEXTURECUBE) { + array_size *= 6; + is_cube_map = true; + } + depth = 1; + break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE3D: + if (!(header->flags & DDS_HEADER_FLAGS_VOLUME)) { + return HRESULT_FROM_WIN32(ERROR_INVALID_DATA); + } + + if (array_size > 1) { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + break; + + default: + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + + res_dim = d3d10ext->resource_dimension; + } + else { + format = GetDXGIFormat(header->ddspf); + + if (format == DXGI_FORMAT_UNKNOWN) { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + + if (header->flags & DDS_HEADER_FLAGS_VOLUME) { + res_dim = D3D11_RESOURCE_DIMENSION_TEXTURE3D; + } + else { + if (header->caps2 & DDS_CUBEMAP) { + // We require all six faces to be defined + if ((header->caps2 & DDS_CUBEMAP_ALLFACES) != DDS_CUBEMAP_ALLFACES) { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + + array_size = 6; + is_cube_map = true; + } + + depth = 1; + res_dim = D3D11_RESOURCE_DIMENSION_TEXTURE2D; + + // Note there's no way for a legacy Direct3D 9 DDS to express a '1D' texture + } + + Assert(BitsPerPixel(format) != 0); + } + + // Bound sizes (for security purposes we don't trust DDS file metadata larger than the D3D 11.x hardware requirements) + if (mip_count > D3D11_REQ_MIP_LEVELS) { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + + switch (res_dim) { + case D3D11_RESOURCE_DIMENSION_TEXTURE1D: + if ((array_size > D3D11_REQ_TEXTURE1D_ARRAY_AXIS_DIMENSION) || (width > D3D11_REQ_TEXTURE1D_U_DIMENSION)) { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE2D: + if (is_cube_map) { + // This is the right bound because we set array_size to (NumCubes*6) above + if ((array_size > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) || + (width > D3D11_REQ_TEXTURECUBE_DIMENSION) || + (height > D3D11_REQ_TEXTURECUBE_DIMENSION)) { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + } + else if ((array_size > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) || + (width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION) || + (height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE3D: + if ((array_size > 1) || + (width > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION) || + (height > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION) || + (depth > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION)) { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + break; + } + + bool autogen = false; + if (mip_count == 1 && device_context != 0 && texture_view != 0) {// Must have context and shader-view to auto generate mipmaps + // See if format is supported for auto-gen mipmaps (varies by feature level) + UINT fmtSupport = 0; + hr = device->CheckFormatSupport(format, &fmtSupport); + if (SUCCEEDED(hr) && (fmtSupport & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN)) { + // 10level9 feature levels do not support auto-gen mipgen for volume textures + if ((res_dim != D3D11_RESOURCE_DIMENSION_TEXTURE3D) || (device->GetFeatureLevel() >= D3D_FEATURE_LEVEL_10_0)) { + autogen = true; + } + } + } + + if (autogen) { + // Create texture with auto-generated mipmaps + ID3D11Resource *tex = nullptr; + hr = CreateD3DResources(device, res_dim, width, height, depth, 0, array_size, + format, usage, + bindFlags | D3D11_BIND_RENDER_TARGET, + cpu_access_flags, + misc_flags | D3D11_RESOURCE_MISC_GENERATE_MIPS, forceSRGB, + is_cube_map, nullptr, &tex, texture_view); + if (SUCCEEDED(hr)) { + size_t nb_bytes = 0; + size_t nb_row_bytes = 0; + GetSurfaceInfo(width, height, format, &nb_bytes, &nb_row_bytes, nullptr); + + if (nb_bytes > bit_size) { + (*texture_view)->Release(); + *texture_view = nullptr; + tex->Release(); + return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF); + } + + if (array_size > 1) { + D3D11_SHADER_RESOURCE_VIEW_DESC desc; + (*texture_view)->GetDesc(&desc); + + UINT mipLevels = 1; + + switch (desc.ViewDimension) { + case D3D_SRV_DIMENSION_TEXTURE1D: mipLevels = desc.Texture1D.MipLevels; break; + case D3D_SRV_DIMENSION_TEXTURE1DARRAY: mipLevels = desc.Texture1DArray.MipLevels; break; + case D3D_SRV_DIMENSION_TEXTURE2D: mipLevels = desc.Texture2D.MipLevels; break; + case D3D_SRV_DIMENSION_TEXTURE2DARRAY: mipLevels = desc.Texture2DArray.MipLevels; break; + case D3D_SRV_DIMENSION_TEXTURECUBE: mipLevels = desc.TextureCube.MipLevels; break; + case D3D_SRV_DIMENSION_TEXTURECUBEARRAY:mipLevels = desc.TextureCubeArray.MipLevels; break; + default: + (*texture_view)->Release(); + *texture_view = nullptr; + tex->Release(); + return E_UNEXPECTED; + } + + const uint8_t* src_bits = bit_data; + const uint8_t* end_bits = bit_data + bit_size; + for (UINT item = 0; item < array_size; ++item) { + if ((src_bits + nb_bytes) > end_bits) { + (*texture_view)->Release(); + *texture_view = nullptr; + tex->Release(); + return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF); + } + + UINT res = D3D11CalcSubresource(0, item, mipLevels); + device_context->UpdateSubresource(tex, res, nullptr, src_bits, static_cast(nb_row_bytes), static_cast(nb_bytes)); + src_bits += nb_bytes; + } + } + else { + device_context->UpdateSubresource(tex, 0, nullptr, bit_data, static_cast(nb_row_bytes), static_cast(nb_bytes)); + } + + device_context->GenerateMips(*texture_view); + + if (texture) { + *texture = tex; + } + else { + tex->Release(); + } + } + } + else { + // Create the texture + std::unique_ptr init_data(new (std::nothrow) D3D11_SUBRESOURCE_DATA[mip_count * array_size]); + if (!init_data) { + return E_OUTOFMEMORY; + } + + size_t skip_mip = 0; + size_t twidth = 0; + size_t theight = 0; + size_t tdepth = 0; + hr = FillInitData(width, height, depth, mip_count, array_size, format, maxsize, bit_size, bit_data, + twidth, theight, tdepth, skip_mip, init_data.get()); + + if (SUCCEEDED(hr)) { + hr = CreateD3DResources(device, res_dim, twidth, theight, tdepth, mip_count - skip_mip, array_size, + format, usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, + is_cube_map, init_data.get(), texture, texture_view); + + if (FAILED(hr) && !maxsize && (mip_count > 1)) { + // Retry with a maxsize determined by feature level + switch (device->GetFeatureLevel()) { + case D3D_FEATURE_LEVEL_9_1: + case D3D_FEATURE_LEVEL_9_2: + if (is_cube_map) { + maxsize = 512 /*D3D_FL9_1_REQ_TEXTURECUBE_DIMENSION*/; + } + else { + maxsize = (res_dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D) + ? 256 /*D3D_FL9_1_REQ_TEXTURE3D_U_V_OR_W_DIMENSION*/ + : 2048 /*D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION*/; + } + break; + + case D3D_FEATURE_LEVEL_9_3: + maxsize = (res_dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D) + ? 256 /*D3D_FL9_1_REQ_TEXTURE3D_U_V_OR_W_DIMENSION*/ + : 4096 /*D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION*/; + break; + + default: // D3D_FEATURE_LEVEL_10_0 & D3D_FEATURE_LEVEL_10_1 + maxsize = (res_dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D) + ? 2048 /*D3D10_REQ_TEXTURE3D_U_V_OR_W_DIMENSION*/ + : 8192 /*D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION*/; + break; + } + + hr = FillInitData(width, height, depth, mip_count, array_size, format, maxsize, bit_size, bit_data, + twidth, theight, tdepth, skip_mip, init_data.get()); + if (SUCCEEDED(hr)) { + hr = CreateD3DResources(device, res_dim, twidth, theight, tdepth, mip_count - skip_mip, array_size, + format, usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, + is_cube_map, init_data.get(), texture, texture_view); + } + } + } + } + + return hr; } static DDS_ALPHA_MODE GetAlphaMode(_In_ const DDS_HEADER *header) { - if (header->ddspf.flags & DDS_FOURCC) { - if (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC) { - auto d3d10ext = reinterpret_cast((const char*)header + sizeof(DDS_HEADER)); - auto mode = static_cast(d3d10ext->misc_flags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK); - switch (mode) { - case DDS_ALPHA_MODE_STRAIGHT: - case DDS_ALPHA_MODE_PREMULTIPLIED: - case DDS_ALPHA_MODE_OPAQUE: - case DDS_ALPHA_MODE_CUSTOM: - return mode; - } - } - else if ((MAKEFOURCC('D', 'X', 'T', '2') == header->ddspf.fourCC) - || (MAKEFOURCC('D', 'X', 'T', '4') == header->ddspf.fourCC)) { - return DDS_ALPHA_MODE_PREMULTIPLIED; - } - } - - return DDS_ALPHA_MODE_UNKNOWN; + if (header->ddspf.flags & DDS_FOURCC) { + if (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC) { + auto d3d10ext = reinterpret_cast((const char*)header + sizeof(DDS_HEADER)); + auto mode = static_cast(d3d10ext->misc_flags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK); + switch (mode) { + case DDS_ALPHA_MODE_STRAIGHT: + case DDS_ALPHA_MODE_PREMULTIPLIED: + case DDS_ALPHA_MODE_OPAQUE: + case DDS_ALPHA_MODE_CUSTOM: + return mode; + } + } + else if ((MAKEFOURCC('D', 'X', 'T', '2') == header->ddspf.fourCC) + || (MAKEFOURCC('D', 'X', 'T', '4') == header->ddspf.fourCC)) { + return DDS_ALPHA_MODE_PREMULTIPLIED; + } + } + + return DDS_ALPHA_MODE_UNKNOWN; } _Use_decl_annotations_ -HRESULT CreateDDSTextureFromMemory(ID3D11Device2 &device, - const uint8_t *dds_data, - size_t dds_dataSize, - ID3D11Resource **texture, - ID3D11ShaderResourceView **texture_view, - size_t maxsize, - DDS_ALPHA_MODE *alpha_mode) { - return CreateDDSTextureFromMemoryEx(device, nullptr, dds_data, dds_dataSize, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, - texture, texture_view, alpha_mode); +HRESULT CreateDDSTextureFromMemory(ID3D11Device2 *device, + const uint8_t *dds_data, + size_t dds_dataSize, + ID3D11Resource **texture, + ID3D11ShaderResourceView **texture_view, + size_t maxsize, + DDS_ALPHA_MODE *alpha_mode) { + return CreateDDSTextureFromMemoryEx(device, nullptr, dds_data, dds_dataSize, maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, + texture, texture_view, alpha_mode); } _Use_decl_annotations_ -HRESULT CreateDDSTextureFromMemory(ID3D11Device2 &device, - ID3D11DeviceContext *d3dContext, - const uint8_t *dds_data, - size_t dds_dataSize, - ID3D11Resource **texture, - ID3D11ShaderResourceView **texture_view, - size_t maxsize, - DDS_ALPHA_MODE *alpha_mode) { - return CreateDDSTextureFromMemoryEx(device, d3dContext, dds_data, dds_dataSize, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, - texture, texture_view, alpha_mode); +HRESULT CreateDDSTextureFromMemory(ID3D11Device2 *device, + ID3D11DeviceContext *device_context, + const uint8_t *dds_data, + size_t dds_dataSize, + ID3D11Resource **texture, + ID3D11ShaderResourceView **texture_view, + size_t maxsize, + DDS_ALPHA_MODE *alpha_mode) { + return CreateDDSTextureFromMemoryEx(device, device_context, dds_data, dds_dataSize, maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, + texture, texture_view, alpha_mode); } _Use_decl_annotations_ -HRESULT CreateDDSTextureFromMemoryEx(ID3D11Device2 &device, - const uint8_t *dds_data, - size_t dds_dataSize, - size_t maxsize, - D3D11_USAGE usage, - uint32_t bindFlags, - uint32_t cpu_access_flags, - uint32_t misc_flags, - bool forceSRGB, - ID3D11Resource **texture, - ID3D11ShaderResourceView **texture_view, - DDS_ALPHA_MODE *alpha_mode) { - return CreateDDSTextureFromMemoryEx(device, nullptr, dds_data, dds_dataSize, maxsize, - usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, - texture, texture_view, alpha_mode); +HRESULT CreateDDSTextureFromMemoryEx(ID3D11Device2 *device, + const uint8_t *dds_data, + size_t dds_dataSize, + size_t maxsize, + D3D11_USAGE usage, + uint32_t bindFlags, + uint32_t cpu_access_flags, + uint32_t misc_flags, + bool forceSRGB, + ID3D11Resource **texture, + ID3D11ShaderResourceView **texture_view, + DDS_ALPHA_MODE *alpha_mode) { + return CreateDDSTextureFromMemoryEx(device, nullptr, dds_data, dds_dataSize, maxsize, + usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, + texture, texture_view, alpha_mode); } _Use_decl_annotations_ -HRESULT CreateDDSTextureFromMemoryEx(ID3D11Device2 &device, - ID3D11DeviceContext *d3dContext, - const uint8_t *dds_data, - size_t dds_dataSize, - size_t maxsize, - D3D11_USAGE usage, - uint32_t bindFlags, - uint32_t cpu_access_flags, - uint32_t misc_flags, - bool forceSRGB, - ID3D11Resource **texture, - ID3D11ShaderResourceView **texture_view, - DDS_ALPHA_MODE *alpha_mode) { +HRESULT CreateDDSTextureFromMemoryEx(ID3D11Device2 *device, + ID3D11DeviceContext *device_context, + const uint8_t *dds_data, + size_t dds_dataSize, + size_t maxsize, + D3D11_USAGE usage, + uint32_t bindFlags, + uint32_t cpu_access_flags, + uint32_t misc_flags, + bool forceSRGB, + ID3D11Resource **texture, + ID3D11ShaderResourceView **texture_view, + DDS_ALPHA_MODE *alpha_mode) { - if (texture) { - *texture = nullptr; - } - if (texture_view) { - *texture_view = nullptr; - } - if (alpha_mode) { - *alpha_mode = DDS_ALPHA_MODE_UNKNOWN; - } - - if (!dds_data || (!texture && !texture_view)) { - return E_INVALIDARG; - } - - // Validate DDS file in memory - if (dds_dataSize < (sizeof(uint32_t) + sizeof(DDS_HEADER))) { - return E_FAIL; - } - - uint32_t dw_magic_number = *(const uint32_t*)(dds_data); - if (dw_magic_number != DDS_MAGIC) { - return E_FAIL; - } - - auto header = reinterpret_cast(dds_data + sizeof(uint32_t)); - - // Verify header to validate DDS file - if (header->size != sizeof(DDS_HEADER) || header->ddspf.size != sizeof(DDS_PIXELFORMAT)) { - return E_FAIL; - } - - // Check for DX10 extension - bool bDXT10Header = false; - if ((header->ddspf.flags & DDS_FOURCC) && (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)) { - // Must be long enough for both headers and magic value - if (dds_dataSize < (sizeof(DDS_HEADER) + sizeof(uint32_t) + sizeof(DDS_HEADER_DXT10))) { - return E_FAIL; - } - - bDXT10Header = true; - } - - ptrdiff_t offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); - - HRESULT hr = CreateTextureFromDDS(device, d3dContext, header, - dds_data + offset, dds_dataSize - offset, maxsize, - usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, - texture, texture_view); - if (SUCCEEDED(hr)) { - if (texture != 0 && *texture != 0) { - SetDebugObjectName(*texture, "DDSTextureLoader"); - } - - if (texture_view != 0 && *texture_view != 0) { - SetDebugObjectName(*texture_view, "DDSTextureLoader"); - } - - if (alpha_mode) { - *alpha_mode = GetAlphaMode(header); - } - } - - return hr; + if (texture) { + *texture = nullptr; + } + if (texture_view) { + *texture_view = nullptr; + } + if (alpha_mode) { + *alpha_mode = DDS_ALPHA_MODE_UNKNOWN; + } + + if (!device || !dds_data || (!texture && !texture_view)) { + return E_INVALIDARG; + } + + // Validate DDS file in memory + if (dds_dataSize < (sizeof(uint32_t) + sizeof(DDS_HEADER))) { + return E_FAIL; + } + + uint32_t dw_magic_number = *(const uint32_t*)(dds_data); + if (dw_magic_number != DDS_MAGIC) { + return E_FAIL; + } + + auto header = reinterpret_cast(dds_data + sizeof(uint32_t)); + + // Verify header to validate DDS file + if (header->size != sizeof(DDS_HEADER) || header->ddspf.size != sizeof(DDS_PIXELFORMAT)) { + return E_FAIL; + } + + // Check for DX10 extension + bool bDXT10Header = false; + if ((header->ddspf.flags & DDS_FOURCC) && (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)) { + // Must be long enough for both headers and magic value + if (dds_dataSize < (sizeof(DDS_HEADER) + sizeof(uint32_t) + sizeof(DDS_HEADER_DXT10))) { + return E_FAIL; + } + + bDXT10Header = true; + } + + ptrdiff_t offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); + + HRESULT hr = CreateTextureFromDDS(device, device_context, header, + dds_data + offset, dds_dataSize - offset, maxsize, + usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, + texture, texture_view); + if (SUCCEEDED(hr)) { + if (texture != 0 && *texture != 0) { + SetDebugObjectName(*texture, "DDSTextureLoader"); + } + + if (texture_view != 0 && *texture_view != 0) { + SetDebugObjectName(*texture_view, "DDSTextureLoader"); + } + + if (alpha_mode) { + *alpha_mode = GetAlphaMode(header); + } + } + + return hr; } _Use_decl_annotations_ -HRESULT CreateDDSTextureFromFile(ID3D11Device2 &device, - const wchar_t *file_name, - ID3D11Resource **texture, - ID3D11ShaderResourceView **texture_view, - size_t maxsize, - DDS_ALPHA_MODE *alpha_mode) { - return CreateDDSTextureFromFileEx(device, nullptr, file_name, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, - texture, texture_view, alpha_mode); +HRESULT CreateDDSTextureFromFile(ID3D11Device2 *device, + const wchar_t *file_name, + ID3D11Resource **texture, + ID3D11ShaderResourceView **texture_view, + size_t maxsize, + DDS_ALPHA_MODE *alpha_mode) { + return CreateDDSTextureFromFileEx(device, nullptr, file_name, maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, + texture, texture_view, alpha_mode); } _Use_decl_annotations_ -HRESULT CreateDDSTextureFromFile(ID3D11Device2 &device, - ID3D11DeviceContext *d3dContext, - const wchar_t *file_name, - ID3D11Resource **texture, - ID3D11ShaderResourceView **texture_view, - size_t maxsize, - DDS_ALPHA_MODE *alpha_mode) { - return CreateDDSTextureFromFileEx(device, d3dContext, file_name, maxsize, - D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, - texture, texture_view, alpha_mode); +HRESULT CreateDDSTextureFromFile(ID3D11Device2 *device, + ID3D11DeviceContext *device_context, + const wchar_t *file_name, + ID3D11Resource **texture, + ID3D11ShaderResourceView **texture_view, + size_t maxsize, + DDS_ALPHA_MODE *alpha_mode) { + return CreateDDSTextureFromFileEx(device, device_context, file_name, maxsize, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false, + texture, texture_view, alpha_mode); } _Use_decl_annotations_ -HRESULT CreateDDSTextureFromFileEx(ID3D11Device2 &device, - const wchar_t *file_name, - size_t maxsize, - D3D11_USAGE usage, - uint32_t bindFlags, - uint32_t cpu_access_flags, - uint32_t misc_flags, - bool forceSRGB, - ID3D11Resource **texture, - ID3D11ShaderResourceView **texture_view, - DDS_ALPHA_MODE *alpha_mode) { - return CreateDDSTextureFromFileEx(device, nullptr, file_name, maxsize, - usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, - texture, texture_view, alpha_mode); +HRESULT CreateDDSTextureFromFileEx(ID3D11Device2 *device, + const wchar_t *file_name, + size_t maxsize, + D3D11_USAGE usage, + uint32_t bindFlags, + uint32_t cpu_access_flags, + uint32_t misc_flags, + bool forceSRGB, + ID3D11Resource **texture, + ID3D11ShaderResourceView **texture_view, + DDS_ALPHA_MODE *alpha_mode) { + return CreateDDSTextureFromFileEx(device, nullptr, file_name, maxsize, + usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, + texture, texture_view, alpha_mode); } _Use_decl_annotations_ -HRESULT CreateDDSTextureFromFileEx(ID3D11Device2 &device, - ID3D11DeviceContext *d3dContext, - const wchar_t *file_name, - size_t maxsize, - D3D11_USAGE usage, - uint32_t bindFlags, - uint32_t cpu_access_flags, - uint32_t misc_flags, - bool forceSRGB, - ID3D11Resource **texture, - ID3D11ShaderResourceView **texture_view, - DDS_ALPHA_MODE *alpha_mode) { - - if (texture) { - *texture = nullptr; - } - if (texture_view) { - *texture_view = nullptr; - } - if (alpha_mode) { - *alpha_mode = DDS_ALPHA_MODE_UNKNOWN; - } - - if (!file_name || (!texture && !texture_view)) { - return E_INVALIDARG; - } - - DDS_HEADER* header = nullptr; - uint8_t* bit_data = nullptr; - size_t bit_size = 0; - - std::unique_ptr dds_data; - HRESULT hr = LoadTextureDataFromFile(file_name, dds_data, &header, &bit_data, &bit_size); - if (FAILED(hr)) { - return hr; - } - - hr = CreateTextureFromDDS(device, d3dContext, header, bit_data, bit_size, maxsize, usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, texture, texture_view); - - if (SUCCEEDED(hr)) { +HRESULT CreateDDSTextureFromFileEx(ID3D11Device2 *device, + ID3D11DeviceContext *device_context, + const wchar_t *file_name, + size_t maxsize, + D3D11_USAGE usage, + uint32_t bindFlags, + uint32_t cpu_access_flags, + uint32_t misc_flags, + bool forceSRGB, + ID3D11Resource **texture, + ID3D11ShaderResourceView **texture_view, + DDS_ALPHA_MODE *alpha_mode) { + + if (texture) { + *texture = nullptr; + } + if (texture_view) { + *texture_view = nullptr; + } + if (alpha_mode) { + *alpha_mode = DDS_ALPHA_MODE_UNKNOWN; + } + + if (!device || !file_name || (!texture && !texture_view)) { + return E_INVALIDARG; + } + + DDS_HEADER* header = nullptr; + uint8_t* bit_data = nullptr; + size_t bit_size = 0; + + std::unique_ptr dds_data; + HRESULT hr = LoadTextureDataFromFile(file_name, dds_data, &header, &bit_data, &bit_size); + if (FAILED(hr)) { + return hr; + } + + hr = CreateTextureFromDDS(device, device_context, header, bit_data, bit_size, maxsize, usage, bindFlags, cpu_access_flags, misc_flags, forceSRGB, texture, texture_view); + + if (SUCCEEDED(hr)) { #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) - if (texture != 0 || texture_view != 0) { - CHAR strFileA[MAX_PATH]; - int result = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, file_name, -1, strFileA, MAX_PATH, nullptr, FALSE); - - if (result > 0) { - const CHAR* pstrName = strrchr(strFileA, '\\'); - if (!pstrName) { - pstrName = strFileA; - } - else { - ++pstrName; - } - - if (texture != 0 && *texture != 0) { - (*texture)->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast(strnlen_s(pstrName, MAX_PATH)), pstrName); - } - if (texture_view != 0 && *texture_view != 0) { - (*texture_view)->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast(strnlen_s(pstrName, MAX_PATH)), pstrName); - } - } - } + if (texture != 0 || texture_view != 0) { + CHAR strFileA[MAX_PATH]; + int result = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, file_name, -1, strFileA, MAX_PATH, nullptr, FALSE); + + if (result > 0) { + const CHAR* pstrName = strrchr(strFileA, '\\'); + if (!pstrName) { + pstrName = strFileA; + } + else { + ++pstrName; + } + + if (texture != 0 && *texture != 0) { + (*texture)->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast(strnlen_s(pstrName, MAX_PATH)), pstrName); + } + if (texture_view != 0 && *texture_view != 0) { + (*texture_view)->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast(strnlen_s(pstrName, MAX_PATH)), pstrName); + } + } + } #endif - if (alpha_mode) { - *alpha_mode = GetAlphaMode(header); - } - } + if (alpha_mode) { + *alpha_mode = GetAlphaMode(header); + } + } - return hr; + return hr; } } \ No newline at end of file diff --git a/MAGE/MAGE/src/texture/dds/dds_loader.hpp b/MAGE/MAGE/src/texture/dds/dds_loader.hpp index d8bd109ec..d8a913661 100644 --- a/MAGE/MAGE/src/texture/dds/dds_loader.hpp +++ b/MAGE/MAGE/src/texture/dds/dds_loader.hpp @@ -50,7 +50,7 @@ namespace mage { }; // Standard version - HRESULT CreateDDSTextureFromMemory(_In_ ID3D11Device2 &device, + HRESULT CreateDDSTextureFromMemory(_In_ ID3D11Device2 *device, _In_reads_bytes_(dds_dataSize) const uint8_t *dds_data, _In_ size_t dds_dataSize, _Outptr_opt_ ID3D11Resource **texture, @@ -59,7 +59,7 @@ namespace mage { _Out_opt_ DDS_ALPHA_MODE *alpha_mode = nullptr ); - HRESULT CreateDDSTextureFromFile(_In_ ID3D11Device2 &device, + HRESULT CreateDDSTextureFromFile(_In_ ID3D11Device2 *device, _In_z_ const wchar_t *szFileName, _Outptr_opt_ ID3D11Resource **texture, _Outptr_opt_ ID3D11ShaderResourceView **texture_view, @@ -68,8 +68,8 @@ namespace mage { ); // Standard version with optional auto-gen mipmap support - HRESULT CreateDDSTextureFromMemory(_In_ ID3D11Device2 &device, - _In_opt_ ID3D11DeviceContext *d3dContext, + HRESULT CreateDDSTextureFromMemory(_In_ ID3D11Device2 *device, + _In_opt_ ID3D11DeviceContext *device_context, _In_reads_bytes_(dds_dataSize) const uint8_t *dds_data, _In_ size_t dds_dataSize, _Outptr_opt_ ID3D11Resource **texture, @@ -78,8 +78,8 @@ namespace mage { _Out_opt_ DDS_ALPHA_MODE *alpha_mode = nullptr ); - HRESULT CreateDDSTextureFromFile(_In_ ID3D11Device2 &device, - _In_opt_ ID3D11DeviceContext *d3dContext, + HRESULT CreateDDSTextureFromFile(_In_ ID3D11Device2 *device, + _In_opt_ ID3D11DeviceContext *device_context, _In_z_ const wchar_t *szFileName, _Outptr_opt_ ID3D11Resource **texture, _Outptr_opt_ ID3D11ShaderResourceView **texture_view, @@ -88,7 +88,7 @@ namespace mage { ); // Extended version - HRESULT CreateDDSTextureFromMemoryEx(_In_ ID3D11Device2 &device, + HRESULT CreateDDSTextureFromMemoryEx(_In_ ID3D11Device2 *device, _In_reads_bytes_(dds_dataSize) const uint8_t *dds_data, _In_ size_t dds_dataSize, _In_ size_t maxsize, @@ -102,7 +102,7 @@ namespace mage { _Out_opt_ DDS_ALPHA_MODE* alpha_mode = nullptr ); - HRESULT CreateDDSTextureFromFileEx(_In_ ID3D11Device2 &device, + HRESULT CreateDDSTextureFromFileEx(_In_ ID3D11Device2 *device, _In_z_ const wchar_t* szFileName, _In_ size_t maxsize, _In_ D3D11_USAGE usage, @@ -116,8 +116,8 @@ namespace mage { ); // Extended version with optional auto-gen mipmap support - HRESULT CreateDDSTextureFromMemoryEx(_In_ ID3D11Device2 &device, - _In_opt_ ID3D11DeviceContext* d3dContext, + HRESULT CreateDDSTextureFromMemoryEx(_In_ ID3D11Device2 *device, + _In_opt_ ID3D11DeviceContext* device_context, _In_reads_bytes_(dds_dataSize) const uint8_t *dds_data, _In_ size_t dds_dataSize, _In_ size_t maxsize, @@ -131,8 +131,8 @@ namespace mage { _Out_opt_ DDS_ALPHA_MODE* alpha_mode = nullptr ); - HRESULT CreateDDSTextureFromFileEx(_In_ ID3D11Device2 &device, - _In_opt_ ID3D11DeviceContext *d3dContext, + HRESULT CreateDDSTextureFromFileEx(_In_ ID3D11Device2 *device, + _In_opt_ ID3D11DeviceContext *device_context, _In_z_ const wchar_t *szFileName, _In_ size_t maxsize, _In_ D3D11_USAGE usage, diff --git a/MAGE/MAGE/src/texture/texture.cpp b/MAGE/MAGE/src/texture/texture.cpp index 33c6bec5d..4932fd1bb 100644 --- a/MAGE/MAGE/src/texture/texture.cpp +++ b/MAGE/MAGE/src/texture/texture.cpp @@ -13,11 +13,11 @@ //----------------------------------------------------------------------------- namespace mage { - Texture::Texture(ComPtr< ID3D11Device2 > device, const wstring &fname) + Texture::Texture(ID3D11Device2 *device, const wstring &fname) : FileResource(fname), m_device(device) { // Create the pixel shader. - const HRESULT result_texture_import = ImportTextureFromFile(GetFilename(), *m_device.Get(), m_texture_resource_view.ReleaseAndGetAddressOf()); + const HRESULT result_texture_import = ImportTextureFromFile(GetFilename(), m_device, m_texture_resource_view.ReleaseAndGetAddressOf()); if (FAILED(result_texture_import)) { Error("Texture initialization failed: %08X.", result_texture_import); return; @@ -25,7 +25,7 @@ namespace mage { } SharedPtr< Texture > CreateTexture(const wstring &fname) { - ComPtr< ID3D11Device2 > device = GetRenderingDevice(); + ID3D11Device2 *device = GetRenderingDevice(); ResourceFactory &factory = GetResourceFactory(); return factory.CreateTexture(device, fname); } diff --git a/MAGE/MAGE/src/texture/texture.hpp b/MAGE/MAGE/src/texture/texture.hpp index a2277c847..1b981744d 100644 --- a/MAGE/MAGE/src/texture/texture.hpp +++ b/MAGE/MAGE/src/texture/texture.hpp @@ -20,11 +20,14 @@ namespace mage { public: - Texture(ComPtr< ID3D11Device2 > device, const wstring &fname); + Texture(ID3D11Device2 *device, const wstring &fname); virtual ~Texture() = default; - ComPtr< ID3D11ShaderResourceView > GetTextureResourceView() const { - return m_texture_resource_view; + ID3D11ShaderResourceView *GetTextureResourceView() const { + return m_texture_resource_view.Get(); + } + ID3D11ShaderResourceView **GetTextureResourceViewAddress() { + return m_texture_resource_view.GetAddressOf(); } private: @@ -34,7 +37,7 @@ namespace mage { Texture &operator=(const Texture &texture) = delete; Texture &operator=(Texture &&texture) = delete; - ComPtr< ID3D11Device2 > m_device; + ID3D11Device2 * const m_device; ComPtr< ID3D11ShaderResourceView > m_texture_resource_view; }; diff --git a/MAGE/MAGE/src/texture/texture_loader.cpp b/MAGE/MAGE/src/texture/texture_loader.cpp index baf2f6e0a..92da3797a 100644 --- a/MAGE/MAGE/src/texture/texture_loader.cpp +++ b/MAGE/MAGE/src/texture/texture_loader.cpp @@ -15,7 +15,7 @@ //----------------------------------------------------------------------------- namespace mage { - HRESULT ImportTextureFromFile(const wstring &fname, ID3D11Device2 &device, ID3D11ShaderResourceView **texture_resource_view) { + HRESULT ImportTextureFromFile(const wstring &fname, ID3D11Device2 *device, ID3D11ShaderResourceView **texture_resource_view) { const wstring extension = GetFileExtension(fname); if (extension == L"dds" || extension == L"DDS") { diff --git a/MAGE/MAGE/src/texture/texture_loader.hpp b/MAGE/MAGE/src/texture/texture_loader.hpp index 9c57d67d0..6df68fd91 100644 --- a/MAGE/MAGE/src/texture/texture_loader.hpp +++ b/MAGE/MAGE/src/texture/texture_loader.hpp @@ -21,10 +21,10 @@ namespace mage { @param[in] fname A reference to the filename. @param[in] device - A reference to the rendering device. + A pointer to the device. @param[out] texture_resource_view A pointer to a pointer to a shader resource view. @return A success/error value. */ - HRESULT ImportTextureFromFile(const wstring &fname, ID3D11Device2 &device, ID3D11ShaderResourceView **texture_resource_view); + HRESULT ImportTextureFromFile(const wstring &fname, ID3D11Device2 *device, ID3D11ShaderResourceView **texture_resource_view); } \ No newline at end of file