BsD3D11Mappings.h 5.3 KB

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