BsGLSLProgramPipelineManager.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include "BsGLPrerequisites.h"
  3. namespace BansheeEngine
  4. {
  5. /**
  6. * @brief Wrapper around OpenGL pipeline object.
  7. */
  8. struct GLSLProgramPipeline
  9. {
  10. GLuint glHandle;
  11. };
  12. /**
  13. * @brief Managed OpenGL pipeline objects that are used for binding a certain combination
  14. * of GPU programs to the render system.
  15. *
  16. * @note In OpenGL you cannot bind GPU programs to the pipeline manually. Instead as a preprocessing step
  17. * you create a pipeline object containing the programs you plan on using, and then later you bind the
  18. * previously created pipeline object.
  19. */
  20. class GLSLProgramPipelineManager
  21. {
  22. public:
  23. /**
  24. * @brief Creates or returns an existing pipeline that uses the provided combination of GPU programs. Provide
  25. * null for unused programs.
  26. */
  27. const GLSLProgramPipeline* getPipeline(GLSLGpuProgram* vertexProgram, GLSLGpuProgram* fragmentProgram,
  28. GLSLGpuProgram* geometryProgram, GLSLGpuProgram* hullProgram, GLSLGpuProgram* domainProgram);
  29. private:
  30. /**
  31. * @brief Key that uniquely identifies a pipeline object.
  32. */
  33. struct ProgramPipelineKey
  34. {
  35. UINT32 vertexProgKey;
  36. UINT32 fragmentProgKey;
  37. UINT32 geometryProgKey;
  38. UINT32 hullProgKey;
  39. UINT32 domainProgKey;
  40. };
  41. /**
  42. * @brief Used for calculating a hash code from pipeline object key.
  43. */
  44. class ProgramPipelineKeyHashFunction
  45. {
  46. public:
  47. ::std::size_t operator()(const ProgramPipelineKey &key) const;
  48. };
  49. /**
  50. * @brief Used for comparing two pipeline objects for equality.
  51. */
  52. class ProgramPipelineKeyEqual
  53. {
  54. public:
  55. bool operator()(const ProgramPipelineKey &a, const ProgramPipelineKey &b) const;
  56. };
  57. typedef UnorderedMap<ProgramPipelineKey, GLSLProgramPipeline, ProgramPipelineKeyHashFunction, ProgramPipelineKeyEqual> ProgramPipelineMap;
  58. ProgramPipelineMap mPipelines;
  59. };
  60. }