BsD3D11Mappings.h 5.1 KB

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