2
0

BsGLVertexArrayObjectManager.h 2.2 KB

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