BsGLSLProgramPipelineManager.h 2.1 KB

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