CmD3D11InputLayoutManager.h 1.9 KB

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