BsD3D11Mappings.h 5.0 KB

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