BsGLVertexArrayObjectManager.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include "Utility/BsModule.h"
  6. namespace bs { namespace ct
  7. {
  8. /** @addtogroup GL
  9. * @{
  10. */
  11. /**
  12. * Vertex array object that contains vertex buffer object bindings and vertex attribute pointers for a specific set of
  13. * vertex buffers and a vertex declaration.
  14. */
  15. class GLVertexArrayObject
  16. {
  17. private:
  18. /** Generates hash value for the VAO object. */
  19. class Hash
  20. {
  21. public:
  22. ::std::size_t operator()(const GLVertexArrayObject& vao) const;
  23. };
  24. /** Checks if two VAO objects are equal. */
  25. class Equal
  26. {
  27. public:
  28. bool operator()(const GLVertexArrayObject &a, const GLVertexArrayObject &b) const;
  29. };
  30. public:
  31. bool operator== (const GLVertexArrayObject& obj);
  32. bool operator!= (const GLVertexArrayObject& obj);
  33. /** Returns internal OpenGL VBO handle. */
  34. GLuint getGLHandle() const { return mHandle; }
  35. private:
  36. friend class GLVertexArrayObjectManager;
  37. GLVertexArrayObject();
  38. GLVertexArrayObject(GLuint handle, UINT64 vertexProgramId, GLVertexBuffer** attachedBuffers, UINT32 numBuffers);
  39. GLuint mHandle;
  40. UINT64 mVertProgId;
  41. GLVertexBuffer** mAttachedBuffers;
  42. UINT32 mNumBuffers;
  43. };
  44. /** Manager that handles creation and destruction of vertex array objects. */
  45. class GLVertexArrayObjectManager : public Module<GLVertexArrayObjectManager>
  46. {
  47. public:
  48. ~GLVertexArrayObjectManager();
  49. /**
  50. * Attempts to find an existing vertex array object matching the provided set of vertex buffers, vertex declaration,
  51. * and vertex shader input parameters. If one cannot be found new one is created and returned.
  52. *
  53. * Lifetime of returned VAO is managed by the vertex buffers that it binds.
  54. */
  55. const GLVertexArrayObject& getVAO(const SPtr<GLSLGpuProgram>& vertexProgram,
  56. const SPtr<VertexDeclaration>& vertexDecl, const std::array<SPtr<VertexBuffer>, 32>& boundBuffers);
  57. /** Called when a vertex buffer containing the provided VAO is destroyed. */
  58. void notifyBufferDestroyed(GLVertexArrayObject vao);
  59. private:
  60. typedef UnorderedSet<GLVertexArrayObject, GLVertexArrayObject::Hash, GLVertexArrayObject::Equal> VAOMap;
  61. VAOMap mVAObjects;
  62. };
  63. /** @} */
  64. }}