BsD3D11Mappings.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsD3D11Prerequisites.h"
  5. #include "BsTexture.h"
  6. #include "BsPixelData.h"
  7. #include "BsIndexBuffer.h"
  8. #include "BsVertexData.h"
  9. #include "BsSamplerState.h"
  10. namespace BansheeEngine
  11. {
  12. /** @addtogroup D3D11
  13. * @{
  14. */
  15. /** Helper class that maps engine types to DirectX 11 types. */
  16. class BS_D3D11_EXPORT D3D11Mappings
  17. {
  18. public:
  19. /** Converts engine to DX11 specific texture addressing mode. */
  20. static D3D11_TEXTURE_ADDRESS_MODE get(TextureAddressingMode tam);
  21. /** Converts engine to DX11 specific blend factor. */
  22. static D3D11_BLEND get(BlendFactor bf);
  23. /** Converts engine to DX11 specific blend operation. */
  24. static D3D11_BLEND_OP get(BlendOperation bo);
  25. /** Converts engine to DX11 specific comparison function. */
  26. static D3D11_COMPARISON_FUNC get(CompareFunction cf);
  27. /** Converts engine to DX11 specific culling mode. */
  28. static D3D11_CULL_MODE get(CullingMode cm);
  29. /** Converts engine to DX11 specific polygon fill mode. */
  30. static D3D11_FILL_MODE get(PolygonMode mode);
  31. /** Return DirectX 11 stencil operation and optionally invert it (greater than becomes less than, etc.). */
  32. static D3D11_STENCIL_OP get(StencilOperation op, bool invert = false);
  33. /**
  34. * Converts engine texture filter type to DirectX 11 filter shift (used for combining to get actual min/mag/mip
  35. * filter bit location).
  36. */
  37. static DWORD get(FilterType ft);
  38. /**
  39. * Returns DirectX 11 texture filter from the provided min, mag and mip filter options, and optionally a filter
  40. * with comparison support.
  41. */
  42. static D3D11_FILTER get(const FilterOptions min, const FilterOptions mag,
  43. const FilterOptions mip, const bool comparison = false);
  44. /** Converts engine to DX11 buffer usage. */
  45. static DWORD get(GpuBufferUsage usage);
  46. /** Converts engine to DX11 lock options, while also constraining the options depending on provided usage type. */
  47. static D3D11_MAP get(GpuLockOptions options, GpuBufferUsage usage);
  48. /** Converts engine to DX11 vertex element type. */
  49. static DXGI_FORMAT get(VertexElementType type);
  50. /** Returns a string describing the provided vertex element semantic. */
  51. static LPCSTR get(VertexElementSemantic sem);
  52. /**
  53. * Returns engine semantic from the provided semantic string. Throws an exception for semantics that do not exist.
  54. */
  55. static VertexElementSemantic get(LPCSTR sem);
  56. /** Converts DirectX 11 GPU parameter component type to engine vertex element type. */
  57. static VertexElementType getInputType(D3D_REGISTER_COMPONENT_TYPE type);
  58. /** Returns DX11 primitive topology based on the provided draw operation type. */
  59. static D3D11_PRIMITIVE_TOPOLOGY getPrimitiveType(DrawOperationType type);
  60. /** Converts engine color to DX11 color. */
  61. static void get(const Color& inColor, float* outColor);
  62. /** Checks does the provided map value include writing. */
  63. static bool isMappingWrite(D3D11_MAP map);
  64. /** Checks does the provided map value include reading. */
  65. static bool isMappingRead(D3D11_MAP map);
  66. /** Converts DX11 pixel format to engine pixel format. */
  67. static PixelFormat getPF(DXGI_FORMAT d3dPF);
  68. /**
  69. * Converts engine pixel format to DX11 pixel format. Some formats depend on whether hardware gamma is used or not,
  70. * in which case set the @p hwGamma parameter as needed.
  71. */
  72. static DXGI_FORMAT getPF(PixelFormat format, bool hwGamma);
  73. /** Converts engine GPU buffer format to DX11 GPU buffer format. */
  74. static DXGI_FORMAT getBF(GpuBufferFormat format);
  75. /**
  76. * Returns a typeless version of a depth stencil format. Required for creating a depth stencil texture it can be
  77. * bound both for shader reading and depth/stencil writing.
  78. */
  79. static DXGI_FORMAT getTypelessDepthStencilPF(PixelFormat format);
  80. /** Returns a format of a depth stencil texture that can be used for reading the texture in the shader. */
  81. static DXGI_FORMAT getShaderResourceDepthStencilPF(PixelFormat format);
  82. /** Converts engine to DX11 buffer usage. */
  83. static D3D11_USAGE getUsage(GpuBufferUsage mUsage);
  84. /** Converts engine to DX11 buffer access flags. */
  85. static UINT getAccessFlags(GpuBufferUsage mUsage);
  86. /** Converts engine to DX11 lock options. */
  87. static D3D11_MAP getLockOptions(GpuLockOptions lockOptions);
  88. /** Checks is the provided buffer usage dynamic. */
  89. static bool isDynamic(GpuBufferUsage mUsage);
  90. /** Finds the closest pixel format that DX11 supports. */
  91. static PixelFormat getClosestSupportedPF(PixelFormat format, bool hwGamma);
  92. /**
  93. * Returns size in bytes of a pixel surface of the specified size and format, while using DX11 allocation rules for
  94. * padding.
  95. */
  96. static UINT32 getSizeInBytes(PixelFormat pf, UINT32 width = 1, UINT32 height = 1);
  97. };
  98. /** @} */
  99. }