BsD3D9Mappings.h 4.2 KB

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