BsGLVertexArrayObjectManager.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. class Hash
  14. {
  15. public:
  16. ::std::size_t operator()(const GLVertexArrayObject &vao) const;
  17. };
  18. class Equal
  19. {
  20. public:
  21. bool operator()(const GLVertexArrayObject &a, const GLVertexArrayObject &b) const;
  22. };
  23. public:
  24. bool operator== (const GLVertexArrayObject& obj);
  25. bool operator!= (const GLVertexArrayObject& obj);
  26. /**
  27. * @brief Returns internal OpenGL VBO handle.
  28. */
  29. GLuint getGLHandle() const { return mHandle; }
  30. private:
  31. friend class GLVertexArrayObjectManager;
  32. GLVertexArrayObject();
  33. GLVertexArrayObject(GLuint handle, UINT64 vertexProgramId, GLVertexBuffer** attachedBuffers, UINT32 numBuffers);
  34. GLuint mHandle;
  35. UINT64 mVertProgId;
  36. GLVertexBuffer** mAttachedBuffers;
  37. UINT32 mNumBuffers;
  38. };
  39. /**
  40. * @brief Manager that handles creation and destruction of vertex array objects.
  41. */
  42. class BS_RSGL_EXPORT GLVertexArrayObjectManager : public Module<GLVertexArrayObjectManager>
  43. {
  44. public:
  45. ~GLVertexArrayObjectManager();
  46. /**
  47. * @brief Attempts to find an existing vertex array object matching the provided set of vertex buffers,
  48. * vertex declaration, and vertex shader input parameters. If one cannot be found new one is created
  49. * and returned.
  50. *
  51. * Lifetime of returned VAO is managed by the vertex buffers that it binds.
  52. */
  53. const GLVertexArrayObject& getVAO(const GLSLGpuProgramPtr& vertexProgram,
  54. const VertexDeclarationPtr& vertexDecl, const Vector<VertexBufferPtr>& boundBuffers);
  55. /**
  56. * @brief Called when a vertex buffer containing the provided VAO is destroyed.
  57. */
  58. void notifyBufferDestroyed(const GLVertexArrayObject& vao);
  59. private:
  60. typedef UnorderedSet<GLVertexArrayObject, GLVertexArrayObject::Hash, GLVertexArrayObject::Equal> VAOMap;
  61. VAOMap mVAObjects;
  62. };
  63. }