CmD3D11InputLayoutManager.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include "CmD3D11Prerequisites.h"
  3. #include "CmVertexDeclaration.h"
  4. namespace BansheeEngine
  5. {
  6. class D3D11InputLayoutManager
  7. {
  8. public:
  9. struct VertexDeclarationKey
  10. {
  11. UINT64 vertxDeclId;
  12. UINT32 vertexProgramId;
  13. };
  14. class HashFunc
  15. {
  16. public:
  17. ::std::size_t operator()(const VertexDeclarationKey &key) const;
  18. };
  19. class EqualFunc
  20. {
  21. public:
  22. bool operator()(const VertexDeclarationKey &a, const VertexDeclarationKey &b) const;
  23. };
  24. struct InputLayoutEntry
  25. {
  26. InputLayoutEntry() {}
  27. ID3D11InputLayout* inputLayout;
  28. UINT32 lastUsedIdx;
  29. };
  30. public:
  31. D3D11InputLayoutManager();
  32. ~D3D11InputLayoutManager();
  33. /**
  34. * @brief Finds an existing one or creates a new D3D11 input layout.
  35. *
  36. * The created declaration will try to match the input to the provided shader with the
  37. * data provided in the vertex buffer (described by the vertex buffer declaration).
  38. *
  39. * Error may be thrown if the vertex buffer doesn't provide all the necessary data.
  40. * (TODO: Depends on how the driver handles missing data)
  41. */
  42. ID3D11InputLayout* retrieveInputLayout(VertexDeclarationPtr vertexShaderDecl, VertexDeclarationPtr vertexBufferDecl, D3D11GpuProgram& vertexProgram);
  43. private:
  44. static const int DECLARATION_BUFFER_SIZE = 1024;
  45. static const int NUM_ELEMENTS_TO_PRUNE = 64;
  46. UnorderedMap<VertexDeclarationKey, InputLayoutEntry*, HashFunc, EqualFunc> mInputLayoutMap;
  47. bool mWarningShown;
  48. UINT32 mLastUsedCounter;
  49. void addNewInputLayout(VertexDeclarationPtr vertexShaderDecl, VertexDeclarationPtr vertexBufferDecl, D3D11GpuProgram& vertexProgram);
  50. void removeLeastUsed();
  51. bool areCompatible(VertexDeclarationPtr vertexShaderDecl, VertexDeclarationPtr vertexBufferDecl);
  52. };
  53. }