GLObjects 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSG_GLOBJECTS
  14. #define OSG_GLOBJECTS 1
  15. #include <osg/Referenced>
  16. #include <osg/GL>
  17. #include <list>
  18. #include <string>
  19. namespace osg {
  20. // forward declare
  21. class FrameStamp;
  22. /** Flush all deleted OpenGL objects within the specified availableTime.
  23. * Note, must be called from a thread which has current the graphics context associated with contextID. */
  24. extern OSG_EXPORT void flushDeletedGLObjects(unsigned int contextID, double currentTime, double& availableTime);
  25. /** Flush all deleted OpenGL objects.
  26. * Note, must be called from a thread which has current the graphics context associated with contextID. */
  27. extern OSG_EXPORT void flushAllDeletedGLObjects(unsigned int contextID);
  28. /** Do a GL delete all OpenGL objects.
  29. * Note, must be called from a thread which has current the graphics context associated with contextID. */
  30. extern OSG_EXPORT void deleteAllGLObjects(unsigned int contextID);
  31. /** Discard all OpenGL objects.
  32. * Note, unlike deleteAllGLjects discard does not
  33. * do any OpenGL calls so can be called from any thread, but as a consequence it
  34. * also doesn't remove the associated OpenGL resource so discard should only be
  35. * called when the associated graphics context is being/has been closed. */
  36. extern OSG_EXPORT void discardAllGLObjects(unsigned int contextID);
  37. class OSG_EXPORT GraphicsObject : public osg::Referenced
  38. {
  39. public:
  40. GraphicsObject();
  41. protected:
  42. virtual ~GraphicsObject();
  43. };
  44. class OSG_EXPORT GraphicsObjectManager : public osg::Referenced
  45. {
  46. public:
  47. GraphicsObjectManager(const std::string& name, unsigned int contextID);
  48. unsigned int getContextID() const { return _contextID; }
  49. /** Signal that a new frame has started.*/
  50. virtual void newFrame(osg::FrameStamp* /*fs*/) {}
  51. virtual void resetStats() {}
  52. virtual void reportStats(std::ostream& /*out*/) {}
  53. virtual void recomputeStats(std::ostream& /*out*/) const {}
  54. /** Flush all deleted OpenGL objects within the specified availableTime.
  55. * Note, must be called from a thread which has current the graphics context associated with contextID. */
  56. virtual void flushDeletedGLObjects(double currentTime, double& availableTime) = 0;
  57. /** Flush all deleted OpenGL objects.
  58. * Note, must be called from a thread which has current the graphics context associated with contextID. */
  59. virtual void flushAllDeletedGLObjects() = 0;
  60. /** Do a GL delete all OpenGL objects.
  61. * Note, must be called from a thread which has current the graphics context associated with contextID. */
  62. virtual void deleteAllGLObjects() = 0;
  63. /** Discard all OpenGL objects.
  64. * Note, unlike deleteAllGLjects discard does not
  65. * do any OpenGL calls so can be called from any thread, but as a consequence it
  66. * also doesn't remove the associated OpenGL resource so discard should only be
  67. * called when the associated graphics context is being/has been closed. */
  68. virtual void discardAllGLObjects() = 0;
  69. protected:
  70. virtual ~GraphicsObjectManager();
  71. std::string _name;
  72. unsigned int _contextID;
  73. };
  74. class OSG_EXPORT GLObjectManager : public GraphicsObjectManager
  75. {
  76. public:
  77. GLObjectManager(const std::string& name, unsigned int contextID);
  78. virtual void flushDeletedGLObjects(double currentTime, double& availableTime);
  79. virtual void flushAllDeletedGLObjects();
  80. virtual void deleteAllGLObjects();
  81. virtual void discardAllGLObjects();
  82. /** schedule a GL object for deletion by the graphics thread.*/
  83. virtual void scheduleGLObjectForDeletion(GLuint globj);
  84. /** implementation of the actual creation of an GL object - subclasses from GLObjectManager must implement the appropriate GL calls.*/
  85. virtual GLuint createGLObject();
  86. /** implementation of the actual deletion of an GL object - subclasses from GLObjectManager must implement the appropriate GL calls.*/
  87. virtual void deleteGLObject(GLuint globj) = 0;
  88. protected:
  89. virtual ~GLObjectManager();
  90. typedef std::list<GLuint> GLObjectHandleList;
  91. OpenThreads::Mutex _mutex;
  92. GLObjectHandleList _deleteGLObjectHandles;
  93. };
  94. }
  95. #endif