home *** CD-ROM | disk | FTP | other *** search
/ Introduction to 3D Game …ogramming with DirectX 12 / Introduction-to-3D-Game-Programming-with-DirectX-12.ISO / Code.Textures / Common / DDSTextureLoader.h < prev    next >
Encoding:
C/C++ Source or Header  |  2016-03-02  |  9.1 KB  |  172 lines

  1. //--------------------------------------------------------------------------------------
  2. // File: DDSTextureLoader.h
  3. //
  4. // Functions for loading a DDS texture and creating a Direct3D 11 runtime resource for it
  5. //
  6. // Note these functions are useful as a light-weight runtime loader for DDS files. For
  7. // a full-featured DDS file reader, writer, and texture processing pipeline see
  8. // the 'Texconv' sample and the 'DirectXTex' library.
  9. //
  10. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  11. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  12. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  13. // PARTICULAR PURPOSE.
  14. //
  15. // Copyright (c) Microsoft Corporation. All rights reserved.
  16. //
  17. // http://go.microsoft.com/fwlink/?LinkId=248926
  18. // http://go.microsoft.com/fwlink/?LinkId=248929
  19. //--------------------------------------------------------------------------------------
  20.  
  21. #ifdef _MSC_VER
  22. #pragma once
  23. #endif
  24.  
  25. #include <wrl.h>
  26. #include <d3d11_1.h>
  27. #include "d3dx12.h"
  28.  
  29. #pragma warning(push)
  30. #pragma warning(disable : 4005)
  31. #include <stdint.h>
  32.  
  33. #pragma warning(pop)
  34.  
  35. #if defined(_MSC_VER) && (_MSC_VER<1610) && !defined(_In_reads_)
  36. #define _In_reads_(exp)
  37. #define _Out_writes_(exp)
  38. #define _In_reads_bytes_(exp)
  39. #define _In_reads_opt_(exp)
  40. #define _Outptr_opt_
  41. #endif
  42.  
  43. #ifndef _Use_decl_annotations_
  44. #define _Use_decl_annotations_
  45. #endif
  46.  
  47. namespace DirectX
  48. {
  49.     enum DDS_ALPHA_MODE
  50.     {
  51.         DDS_ALPHA_MODE_UNKNOWN       = 0,
  52.         DDS_ALPHA_MODE_STRAIGHT      = 1,
  53.         DDS_ALPHA_MODE_PREMULTIPLIED = 2,
  54.         DDS_ALPHA_MODE_OPAQUE        = 3,
  55.         DDS_ALPHA_MODE_CUSTOM        = 4,
  56.     };
  57.  
  58.     // Standard version
  59.     HRESULT CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice,
  60.                                         _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
  61.                                         _In_ size_t ddsDataSize,
  62.                                         _Outptr_opt_ ID3D11Resource** texture,
  63.                                         _Outptr_opt_ ID3D11ShaderResourceView** textureView,
  64.                                         _In_ size_t maxsize = 0,
  65.                                         _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
  66.                                       );
  67.  
  68.     HRESULT CreateDDSTextureFromMemory12(_In_ ID3D12Device* device,
  69.                                          _In_ ID3D12GraphicsCommandList* cmdList,
  70.                                          _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
  71.                                          _In_ size_t ddsDataSize,
  72.                                          _Out_ Microsoft::WRL::ComPtr<ID3D12Resource>& texture,
  73.                                          _Out_ Microsoft::WRL::ComPtr<ID3D12Resource>& textureUploadHeap,
  74.                                          _In_ size_t maxsize = 0,
  75.                                          _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
  76.                                          );
  77.  
  78.     HRESULT CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice,
  79.                                       _In_z_ const wchar_t* szFileName,
  80.                                       _Outptr_opt_ ID3D11Resource** texture,
  81.                                       _Outptr_opt_ ID3D11ShaderResourceView** textureView,
  82.                                       _In_ size_t maxsize = 0,
  83.                                       _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
  84.                                     );
  85.  
  86.     HRESULT CreateDDSTextureFromFile12(_In_ ID3D12Device* device,
  87.                                        _In_ ID3D12GraphicsCommandList* cmdList,
  88.                                        _In_z_ const wchar_t* szFileName,
  89.                                        _Out_ Microsoft::WRL::ComPtr<ID3D12Resource>& texture,
  90.                                        _Out_ Microsoft::WRL::ComPtr<ID3D12Resource>& textureUploadHeap,
  91.                                        _In_ size_t maxsize = 0,
  92.                                        _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
  93.                                        );
  94.  
  95.     // Standard version with optional auto-gen mipmap support
  96.     HRESULT CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice,
  97.                                         _In_opt_ ID3D11DeviceContext* d3dContext,
  98.                                         _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
  99.                                         _In_ size_t ddsDataSize,
  100.                                         _Outptr_opt_ ID3D11Resource** texture,
  101.                                         _Outptr_opt_ ID3D11ShaderResourceView** textureView,
  102.                                         _In_ size_t maxsize = 0,
  103.                                         _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
  104.                                       );
  105.  
  106.     HRESULT CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice,
  107.                                       _In_opt_ ID3D11DeviceContext* d3dContext,
  108.                                       _In_z_ const wchar_t* szFileName,
  109.                                       _Outptr_opt_ ID3D11Resource** texture,
  110.                                       _Outptr_opt_ ID3D11ShaderResourceView** textureView,
  111.                                       _In_ size_t maxsize = 0,
  112.                                       _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
  113.                                     );
  114.  
  115.     // Extended version
  116.     HRESULT CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
  117.                                           _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
  118.                                           _In_ size_t ddsDataSize,
  119.                                           _In_ size_t maxsize,
  120.                                           _In_ D3D11_USAGE usage,
  121.                                           _In_ unsigned int bindFlags,
  122.                                           _In_ unsigned int cpuAccessFlags,
  123.                                           _In_ unsigned int miscFlags,
  124.                                           _In_ bool forceSRGB,
  125.                                           _Outptr_opt_ ID3D11Resource** texture,
  126.                                           _Outptr_opt_ ID3D11ShaderResourceView** textureView,
  127.                                           _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
  128.                                       );
  129.  
  130.     HRESULT CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
  131.                                         _In_z_ const wchar_t* szFileName,
  132.                                         _In_ size_t maxsize,
  133.                                         _In_ D3D11_USAGE usage,
  134.                                         _In_ unsigned int bindFlags,
  135.                                         _In_ unsigned int cpuAccessFlags,
  136.                                         _In_ unsigned int miscFlags,
  137.                                         _In_ bool forceSRGB,
  138.                                         _Outptr_opt_ ID3D11Resource** texture,
  139.                                         _Outptr_opt_ ID3D11ShaderResourceView** textureView,
  140.                                         _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
  141.                                     );
  142.  
  143.     // Extended version with optional auto-gen mipmap support
  144.     HRESULT CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
  145.                                           _In_opt_ ID3D11DeviceContext* d3dContext,
  146.                                           _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
  147.                                           _In_ size_t ddsDataSize,
  148.                                           _In_ size_t maxsize,
  149.                                           _In_ D3D11_USAGE usage,
  150.                                           _In_ unsigned int bindFlags,
  151.                                           _In_ unsigned int cpuAccessFlags,
  152.                                           _In_ unsigned int miscFlags,
  153.                                           _In_ bool forceSRGB,
  154.                                           _Outptr_opt_ ID3D11Resource** texture,
  155.                                           _Outptr_opt_ ID3D11ShaderResourceView** textureView,
  156.                                           _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
  157.                                       );
  158.  
  159.     HRESULT CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
  160.                                         _In_opt_ ID3D11DeviceContext* d3dContext,
  161.                                         _In_z_ const wchar_t* szFileName,
  162.                                         _In_ size_t maxsize,
  163.                                         _In_ D3D11_USAGE usage,
  164.                                         _In_ unsigned int bindFlags,
  165.                                         _In_ unsigned int cpuAccessFlags,
  166.                                         _In_ unsigned int miscFlags,
  167.                                         _In_ bool forceSRGB,
  168.                                         _Outptr_opt_ ID3D11Resource** texture,
  169.                                         _Outptr_opt_ ID3D11ShaderResourceView** textureView,
  170.                                         _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
  171.                                     );
  172. }