You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.3 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __GUIOPENGLPROVIDER_H_INCL__
  2. #define __GUIOPENGLPROVIDER_H_INCL__
  3. #include <WinSock2.h>
  4. #include "windows.h"
  5. #include <gl/GL.h>
  6. #include <gl/GLU.h>
  7. #pragma comment(lib, "opengl32.lib")
  8. #pragma comment(lib, "glu32.lib")
  9. #include "../components/base/basicMutex.h"
  10. #include "gui.h"
  11. #include <QtGui/QOpenGLFunctions>
  12. /**
  13. * guiOpenGLProvider singletone class to provide OpenGL context globally
  14. *
  15. * @author gagua
  16. */
  17. class guiOpenGLProvider {
  18. public:
  19. // Method to fetch singleton instance.
  20. static guiOpenGLProvider* getInstance();
  21. // Destructor
  22. virtual ~guiOpenGLProvider();
  23. QOpenGLContext *grabContext( void );
  24. QOpenGLContext *tryGrabContext( void );
  25. void releaseContext( void );
  26. protected:
  27. // Constructor - protected so users cannot call it.
  28. guiOpenGLProvider();
  29. private:
  30. // private static member referencing the single instance of the object
  31. // TODO: Replace guiOpenGLProvider with the type of object you want to
  32. // return the single instance of
  33. static guiOpenGLProvider *_instance;
  34. basicMutex *m_pContextProtectorMutex;
  35. // Copy constructor
  36. // Declared but not defined to prevent auto-generated
  37. // copy constructor. Refer to "Effective C++" by Meyers
  38. guiOpenGLProvider(const guiOpenGLProvider& src);
  39. // Assignment operator
  40. // Declared but not defined to prevent auto-generated
  41. // assignment operator. Refer to "Effective C++" by Meyers
  42. guiOpenGLProvider& operator=(const guiOpenGLProvider& src);
  43. QOpenGLContext *m_pContext;
  44. };
  45. // Constructor implementation
  46. inline guiOpenGLProvider::guiOpenGLProvider(){
  47. m_pContextProtectorMutex = new basicMutex();
  48. m_pContext = new QOpenGLContext();
  49. //initializeOpenGLFunctions();
  50. }
  51. // Destructor implementation
  52. inline guiOpenGLProvider::~guiOpenGLProvider(){
  53. emit m_pContext->aboutToBeDestroyed();
  54. delete(m_pContextProtectorMutex);
  55. delete(m_pContext);
  56. }
  57. // TODO: Uncomment the copy constructor when you need it.
  58. //inline guiOpenGLProvider::guiOpenGLProvider(const guiOpenGLProvider& src)
  59. //{
  60. // // TODO: copy
  61. //}
  62. // TODO: Uncomment the assignment operator when you need it.
  63. //inline guiOpenGLProvider& guiOpenGLProvider::operator=(const guiOpenGLProvider& rhs)
  64. //{
  65. // if (this == &rhs) {
  66. // return *this;
  67. // }
  68. //
  69. // // TODO: assignment
  70. //
  71. // return *this;
  72. //}
  73. #endif // __GUIOPENGLPROVIDER_H_INCL__