BsGLVertexArrayObjectManager.h 2.4 KB

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