Skip to content

Commit

Permalink
Added DDSTextureLoader wrapper.
Browse files Browse the repository at this point in the history
Added DDSTextureLoader wrapper. Added new formats to ContainerFormat. Updated read-me. Renamed TextureHelper to WICTextureHelper. Updated sample program.
  • Loading branch information
unknown committed Dec 1, 2024
1 parent 551bb4d commit bae73e2
Show file tree
Hide file tree
Showing 16 changed files with 291 additions and 80 deletions.
6 changes: 3 additions & 3 deletions DirectXTK.NET/DirectXTK.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTK.NET", "DirectXTK.NET\DirectXTK.NET.vcxproj", "{7FD78022-FB2F-434F-9803-E4757E857776}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DirectXTKSample", "DirectXTKSample\DirectXTKSample.csproj", "{4D23C806-8D34-49CC-B6D9-214C2E4910C6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DirectXTKSample", "DirectXTKSample\DirectXTKSample.csproj", "{4D23C806-8D34-49CC-B6D9-214C2E4910C6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -31,8 +31,8 @@ Global
{7FD78022-FB2F-434F-9803-E4757E857776}.Release|x86.Build.0 = Release|Win32
{4D23C806-8D34-49CC-B6D9-214C2E4910C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D23C806-8D34-49CC-B6D9-214C2E4910C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D23C806-8D34-49CC-B6D9-214C2E4910C6}.Debug|x64.ActiveCfg = Debug|Any CPU
{4D23C806-8D34-49CC-B6D9-214C2E4910C6}.Debug|x64.Build.0 = Debug|Any CPU
{4D23C806-8D34-49CC-B6D9-214C2E4910C6}.Debug|x64.ActiveCfg = Debug|x64
{4D23C806-8D34-49CC-B6D9-214C2E4910C6}.Debug|x64.Build.0 = Debug|x64
{4D23C806-8D34-49CC-B6D9-214C2E4910C6}.Debug|x86.ActiveCfg = Debug|Any CPU
{4D23C806-8D34-49CC-B6D9-214C2E4910C6}.Debug|x86.Build.0 = Debug|Any CPU
{4D23C806-8D34-49CC-B6D9-214C2E4910C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
18 changes: 10 additions & 8 deletions DirectXTK.NET/DirectXTK.NET/DirectXTK.NET.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Source\DDSTextureHelper.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Source\Enums.h" />
<ClInclude Include="Source\StdAfx.h" />
<ClInclude Include="Source\TextureHelper.h" />
<ClInclude Include="Source\WICTextureHelper.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source\StdAfx.cpp" />
<ClCompile Include="Source\TextureHelper.cpp" />
<ClCompile Include="Source\DDSTextureHelper.cpp" />
<ClCompile Include="Source\WICTextureHelper.cpp" />
</ItemGroup>
<ItemGroup>
<Reference Include="Silk.NET.Direct3D11">
<HintPath>..\DirectXTKSample\bin\Debug\net8.0\Silk.NET.Direct3D11.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<ResourceCompile Include="DirectXTK.NET.rc" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DirectXTK.NET.rc" />
<None Include="packages.config" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
Expand All @@ -48,7 +48,7 @@
<TargetFrameworkVersion>
</TargetFrameworkVersion>
<TargetFramework>net80</TargetFramework>
<WindowsTargetPlatformMinVersion>7.0</WindowsTargetPlatformMinVersion>
<WindowsTargetPlatformMinVersion>8.0</WindowsTargetPlatformMinVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -139,7 +139,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;DIRECTXTKNET_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
Expand Down Expand Up @@ -170,11 +170,13 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="packages\directxtk_uwp.2024.6.5.1\build\native\directxtk_uwp.targets" Condition="Exists('packages\directxtk_uwp.2024.6.5.1\build\native\directxtk_uwp.targets')" />
<Import Project="..\packages\directxtk_uwp.2024.10.29.1\build\native\directxtk_uwp.targets" Condition="Exists('..\packages\directxtk_uwp.2024.10.29.1\build\native\directxtk_uwp.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\directxtk_uwp.2024.6.5.1\build\native\directxtk_uwp.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\directxtk_uwp.2024.6.5.1\build\native\directxtk_uwp.targets'))" />
<Error Condition="!Exists('..\packages\directxtk_uwp.2024.10.29.1\build\native\directxtk_uwp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\directxtk_uwp.2024.10.29.1\build\native\directxtk_uwp.targets'))" />
</Target>
</Project>
27 changes: 19 additions & 8 deletions DirectXTK.NET/DirectXTK.NET/DirectXTK.NET.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,34 @@
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="TextureHelpers">
<UniqueIdentifier>{a3d4dbcc-2d46-4c50-a6bc-e1487e70afa6}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Source\StdAfx.h" />
<ClInclude Include="Source\TextureHelper.h" />
<ClInclude Include="Source\Enums.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Source\WICTextureHelper.h">
<Filter>TextureHelpers</Filter>
</ClInclude>
<ClInclude Include="Source\DDSTextureHelper.h">
<Filter>TextureHelpers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source\StdAfx.cpp" />
<ClCompile Include="Source\TextureHelper.cpp" />
<ResourceCompile Include="DirectXTK.NET.rc">
<Filter>Ressourcendateien</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<ClCompile Include="Source\WICTextureHelper.cpp">
<Filter>TextureHelpers</Filter>
</ClCompile>
<ClCompile Include="Source\DDSTextureHelper.cpp">
<Filter>TextureHelpers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DirectXTK.NET.rc">
<Filter>Ressourcendateien</Filter>
</ResourceCompile>
<None Include="packages.config" />
</ItemGroup>
</Project>
50 changes: 50 additions & 0 deletions DirectXTK.NET/DirectXTK.NET/Source/DDSTextureHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "DDSTextureHelper.h"

using namespace System;
using namespace System::Runtime::InteropServices;

HRESULT DirectXTK::DDSTextureHelper::CreateDDSTextureFromFile(Silk::NET::Direct3D11::ID3D11Device* device, String^ filePath, Silk::NET::Direct3D11::ID3D11Resource** texture, Silk::NET::Direct3D11::ID3D11ShaderResourceView** textureView, UINT maxSize, DDSAlphaMode alphaMode)
{
auto chars = (wchar_t*)Marshal::StringToHGlobalUni(filePath).ToPointer();
auto nativeAlphaMode = static_cast<DirectX::DDS_ALPHA_MODE>(alphaMode);

HRESULT result = DirectX::CreateDDSTextureFromFile((ID3D11Device*)device, chars, (ID3D11Resource**)texture, (ID3D11ShaderResourceView**)textureView, maxSize, &nativeAlphaMode);

Marshal::FreeHGlobal(IntPtr(chars));
return result;
}

HRESULT DirectXTK::DDSTextureHelper::CreateDDSTextureFromFile(Silk::NET::Direct3D11::ID3D11Device* device, Silk::NET::Direct3D11::ID3D11DeviceContext* deviceContext, String^ filePath, Silk::NET::Direct3D11::ID3D11Resource** texture, Silk::NET::Direct3D11::ID3D11ShaderResourceView** textureView, UINT maxSize, DDSAlphaMode alphaMode)
{
auto chars = (wchar_t*)Marshal::StringToHGlobalUni(filePath).ToPointer();
auto nativeAlphaMode = static_cast<DirectX::DDS_ALPHA_MODE>(alphaMode);

HRESULT result = DirectX::CreateDDSTextureFromFile((ID3D11Device*)device, (ID3D11DeviceContext*)deviceContext, chars, (ID3D11Resource**)texture, (ID3D11ShaderResourceView**)textureView, maxSize, &nativeAlphaMode);

Marshal::FreeHGlobal(IntPtr(chars));
return result;
}

HRESULT DirectXTK::DDSTextureHelper::CreateDDSTextureFromFile(Silk::NET::Direct3D11::ID3D11Device* device, String^ filePath, UINT maxSize, Silk::NET::Direct3D11::Usage usage, UINT bindFlags, UINT cpuAccessFlags, Silk::NET::Direct3D11::ResourceMiscFlag miscFlags, DDSLoaderFlag loadFlags, Silk::NET::Direct3D11::ID3D11Resource** texture, Silk::NET::Direct3D11::ID3D11ShaderResourceView** textureView, DDSAlphaMode alphaMode)
{
auto chars = (wchar_t*)Marshal::StringToHGlobalUni(filePath).ToPointer();
auto nativeAlphaMode = static_cast<DirectX::DDS_ALPHA_MODE>(alphaMode);
auto nativeLoadFlags = static_cast<DirectX::DDS_LOADER_FLAGS>(loadFlags);

HRESULT result = DirectX::CreateDDSTextureFromFileEx((ID3D11Device*)device, chars, maxSize, (D3D11_USAGE)usage, bindFlags, cpuAccessFlags, (UINT)miscFlags, nativeLoadFlags, (ID3D11Resource**)texture, (ID3D11ShaderResourceView**)textureView, &nativeAlphaMode);

Marshal::FreeHGlobal(IntPtr(chars));
return result;
}

HRESULT DirectXTK::DDSTextureHelper::CreateDDSTextureFromFile(Silk::NET::Direct3D11::ID3D11Device* device, Silk::NET::Direct3D11::ID3D11DeviceContext* deviceContext, String^ filePath, UINT maxSize, Silk::NET::Direct3D11::Usage usage, UINT bindFlags, UINT cpuAccessFlags, Silk::NET::Direct3D11::ResourceMiscFlag miscFlags, DDSLoaderFlag loadFlags, Silk::NET::Direct3D11::ID3D11Resource** texture, Silk::NET::Direct3D11::ID3D11ShaderResourceView** textureView, DDSAlphaMode alphaMode)
{
auto chars = (wchar_t*)Marshal::StringToHGlobalUni(filePath).ToPointer();
auto nativeAlphaMode = static_cast<DirectX::DDS_ALPHA_MODE>(alphaMode);
auto nativeLoadFlags = static_cast<DirectX::DDS_LOADER_FLAGS>(loadFlags);

HRESULT result = DirectX::CreateDDSTextureFromFileEx((ID3D11Device*)device, (ID3D11DeviceContext*)deviceContext, chars, maxSize, (D3D11_USAGE)usage, bindFlags, cpuAccessFlags, (UINT)miscFlags, nativeLoadFlags, (ID3D11Resource**)texture, (ID3D11ShaderResourceView**)textureView, &nativeAlphaMode);

Marshal::FreeHGlobal(IntPtr(chars));
return result;
}
82 changes: 82 additions & 0 deletions DirectXTK.NET/DirectXTK.NET/Source/DDSTextureHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "DDSTextureLoader.h"

using namespace System;

namespace DirectXTK
{
public enum class DDSAlphaMode {
Unknown,
Straight,
Premltiplied,
Opaque,
Custom
};

public enum class DDSLoaderFlag {
Default = 0,
ForceSRGB = 1,
IgnoreSRGB = 2,
};

public ref class DDSTextureHelper
{
public:
static HRESULT CreateDDSTextureFromFile(
Silk::NET::Direct3D11::ID3D11Device* device,
String^ filePath,
Silk::NET::Direct3D11::ID3D11Resource** texture,
Silk::NET::Direct3D11::ID3D11ShaderResourceView** textureView,
[Runtime::InteropServices::OptionalAttribute] UINT maxsize,
[Runtime::InteropServices::OptionalAttribute] DDSAlphaMode alphaMode);

static HRESULT CreateDDSTextureFromFile(
Silk::NET::Direct3D11::ID3D11Device* device,
Silk::NET::Direct3D11::ID3D11DeviceContext* deviceContext,
String^ filePath,
Silk::NET::Direct3D11::ID3D11Resource** texture,
Silk::NET::Direct3D11::ID3D11ShaderResourceView** textureView,
[Runtime::InteropServices::OptionalAttribute] UINT maxSize,
[Runtime::InteropServices::OptionalAttribute] DDSAlphaMode alphaMode);

static HRESULT CreateDDSTextureFromFile(
Silk::NET::Direct3D11::ID3D11Device* device,
String^ filePath,
UINT maxsize,
Silk::NET::Direct3D11::Usage usage,
UINT bindFlags,
UINT cpuAccessFlags,
Silk::NET::Direct3D11::ResourceMiscFlag miscFlags,
DDSLoaderFlag loadFlags,
Silk::NET::Direct3D11::ID3D11Resource** texture,
Silk::NET::Direct3D11::ID3D11ShaderResourceView** textureView,
DDSAlphaMode alphaMode);

static HRESULT CreateDDSTextureFromFile(
Silk::NET::Direct3D11::ID3D11Device* device,
Silk::NET::Direct3D11::ID3D11DeviceContext* deviceContext,
String^ filePath,
UINT maxsize,
Silk::NET::Direct3D11::Usage usage,
UINT bindFlags,
UINT cpuAccessFlags,
Silk::NET::Direct3D11::ResourceMiscFlag miscFlags,
DDSLoaderFlag loadFlags,
Silk::NET::Direct3D11::ID3D11Resource** texture,
Silk::NET::Direct3D11::ID3D11ShaderResourceView** textureView,
DDSAlphaMode alphaMode);

//static HRESULT CreateDDSTextureFromFileEx(
// Silk::NET::Direct3D11::ID3D11Device* d3dDevice,
// Silk::NET::Direct3D11::ID3D11DeviceContext* d3dContext,
// System::String^ filePath,
// size_t maxsize,
// D3D11_USAGE usage,
// unsigned int bindFlags,
// unsigned int cpuAccessFlags,
// unsigned int miscFlags,
// DDS_LOADER_FLAGS loadFlags,
// Silk::NET::Direct3D11::ID3D11Resource** texture,
// Silk::NET::Direct3D11::ID3D11ShaderResourceView** textureView,
// DDS_ALPHA_MODE* alphaMode = nullptr);
};
}
26 changes: 19 additions & 7 deletions DirectXTK.NET/DirectXTK.NET/Source/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

#include <wincodec.h>

using namespace System;

namespace DirectXTK
{
public enum class ContainerFormat
{
Bmp = 0,
Png,
Adng,
Bmp,
Dds,
Gif,
Heif,
Ico,
Jpeg,
Png,
Raw,
Tiff,
Gif,
Webp,
Wmp
};

Expand Down Expand Up @@ -113,14 +120,19 @@ namespace DirectXTK
{
switch (containerFormat)
{
case ContainerFormat::Adng: return GUID_ContainerFormatAdng;
case ContainerFormat::Bmp: return GUID_ContainerFormatBmp;
case ContainerFormat::Png: return GUID_ContainerFormatPng;
case ContainerFormat::Dds: return GUID_ContainerFormatDds;
case ContainerFormat::Gif: return GUID_ContainerFormatGif;
case ContainerFormat::Heif: return GUID_ContainerFormatHeif;
case ContainerFormat::Ico: return GUID_ContainerFormatIco;
case ContainerFormat::Jpeg: return GUID_ContainerFormatJpeg;
case ContainerFormat::Png: return GUID_ContainerFormatPng;
case ContainerFormat::Raw: return GUID_ContainerFormatRaw;
case ContainerFormat::Tiff: return GUID_ContainerFormatTiff;
case ContainerFormat::Gif: return GUID_ContainerFormatGif;
case ContainerFormat::Webp: return GUID_ContainerFormatWebp;
case ContainerFormat::Wmp: return GUID_ContainerFormatWmp;
default: throw gcnew System::ArgumentOutOfRangeException("containerFormat");
default: throw gcnew ArgumentOutOfRangeException("containerFormat");
}
}

Expand Down Expand Up @@ -218,7 +230,7 @@ namespace DirectXTK
case PixelFormat::Format16bppYQuantizedDctCoefficients: return GUID_WICPixelFormat16bppYQuantizedDctCoefficients;
case PixelFormat::Format16bppCbQuantizedDctCoefficients: return GUID_WICPixelFormat16bppCbQuantizedDctCoefficients;
case PixelFormat::Format16bppCrQuantizedDctCoefficients: return GUID_WICPixelFormat16bppCrQuantizedDctCoefficients;
default: throw gcnew System::ArgumentOutOfRangeException("pixelFormat");
default: throw gcnew ArgumentOutOfRangeException("pixelFormat");
}
}
}
29 changes: 0 additions & 29 deletions DirectXTK.NET/DirectXTK.NET/Source/TextureHelper.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions DirectXTK.NET/DirectXTK.NET/Source/TextureHelper.h

This file was deleted.

Loading

0 comments on commit bae73e2

Please sign in to comment.