BsGLSLProgramPipelineManager.h 2.2 KB

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