BsD3D9Mappings.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #pragma once
  2. #include "BsD3D9Prerequisites.h"
  3. #include "BsRenderAPI.h"
  4. #include "BsHardwareBuffer.h"
  5. #include "BsIndexBuffer.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Provides helper methods for mapping between engine and DirectX 9 types.
  10. */
  11. class BS_D3D9_EXPORT D3D9Mappings
  12. {
  13. public:
  14. /**
  15. * @brief DirectX 9 texture types.
  16. */
  17. enum D3DTexType
  18. {
  19. D3D_TEX_TYPE_NORMAL,
  20. D3D_TEX_TYPE_CUBE,
  21. D3D_TEX_TYPE_VOLUME,
  22. D3D_TEX_TYPE_NONE
  23. };
  24. /**
  25. * @brief Returns DirectX 9 texture addressing mode. Returns exact mode if supported, or
  26. * nearest available if not.
  27. */
  28. static D3DTEXTUREADDRESS get(TextureAddressingMode tam, const D3DCAPS9& devCaps);
  29. /**
  30. * @brief Returns DirectX 9 blend factor.
  31. */
  32. static D3DBLEND get(BlendFactor sbf);
  33. /**
  34. * @brief Returns DirectX 9 blend operation
  35. */
  36. static D3DBLENDOP get(BlendOperation sbo);
  37. /**
  38. * @brief Return DirectX 9 compare function.
  39. */
  40. static DWORD get(CompareFunction cf);
  41. /**
  42. * @brief Returns DirectX 9 culling mode. Optionally flip the mode so that
  43. * engine CCW is DX9 CW and reverse.
  44. */
  45. static DWORD get(CullingMode cm, bool flip);
  46. /**
  47. * @brief Return DirectX 9 fill mode depending on provided polygon mode.
  48. */
  49. static D3DFILLMODE get(PolygonMode level);
  50. /**
  51. * @brief Return DirectX 9 stencil operation and optionally
  52. * invert it (greater than becomes less than, etc.)
  53. */
  54. static DWORD get(StencilOperation op, bool invert = false);
  55. /**
  56. * @brief Returns DirectX 9 sampler state based on provided filter type.
  57. */
  58. static D3DSAMPLERSTATETYPE get(FilterType ft);
  59. /**
  60. * @brief Returns a DirectX 9 texture filter type based on provided filter type, options and texture type.
  61. * If wanted filter type is not available closest type will be returned.
  62. */
  63. static DWORD get(FilterType ft, FilterOptions fo, const D3DCAPS9& devCaps, D3DTexType texType);
  64. /**
  65. * @brief Returns DirectX 9 texture type.
  66. */
  67. static D3DTexType get(TextureType textype);
  68. /**
  69. * @brief Return DirectX 9 buffer usage.
  70. */
  71. static DWORD get(GpuBufferUsage usage);
  72. /**
  73. * @brief Returns DirectX 9 lock options, constrained by the provided usage.
  74. */
  75. static DWORD get(GpuLockOptions options, GpuBufferUsage usage);
  76. /**
  77. * @brief Returns DirectX 9 index buffer type.
  78. */
  79. static D3DFORMAT get(IndexType itype);
  80. /**
  81. * @brief Returns DirectX 9 vertex element type.
  82. */
  83. static D3DDECLTYPE get(VertexElementType vType);
  84. /**
  85. * @brief Returns DirectX9 vertex element semantic.
  86. */
  87. static D3DDECLUSAGE get(VertexElementSemantic sem);
  88. /**
  89. * @brief Converts DirectX9 vertex element semantic to engine vertex element semantic.
  90. */
  91. static VertexElementSemantic get(D3DDECLUSAGE sem);
  92. /**
  93. * @brief Converts a matrix to one usable by DirectX 9 API.
  94. */
  95. static D3DXMATRIX makeD3DXMatrix(const Matrix4& mat);
  96. /**
  97. * @brief Converts matrix returned by DirectX 9 API to engine matrix.
  98. */
  99. static Matrix4 convertD3DXMatrix(const D3DXMATRIX& mat);
  100. /**
  101. * @brief Converts DirectX 9 pixel format to engine pixel format.
  102. */
  103. static PixelFormat _getPF(D3DFORMAT d3dPF);
  104. /**
  105. * @brief Converts engine pixel format to DirectX 9 pixel format.
  106. */
  107. static D3DFORMAT _getPF(PixelFormat pf);
  108. /**
  109. * @brief Returns closest pixel format supported by DirectX 9.
  110. */
  111. static PixelFormat _getClosestSupportedPF(PixelFormat pf);
  112. /**
  113. * @brief Returns closest color render target pixel format supported by DirectX 9.
  114. */
  115. static PixelFormat _getClosestSupportedRenderTargetPF(PixelFormat pf);
  116. /**
  117. * @brief Returns closest depth/stencil format supported by DirectX 9.
  118. */
  119. static PixelFormat _getClosestSupportedDepthStencilPF(PixelFormat pf);
  120. };
  121. }