BsGLVertexArrayObjectManager.h 2.5 KB

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