glx11.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/unix/glx11.h
  3. // Purpose: class common for all X11-based wxGLCanvas implementations
  4. // Author: Vadim Zeitlin
  5. // Created: 2007-04-15
  6. // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_UNIX_GLX11_H_
  10. #define _WX_UNIX_GLX11_H_
  11. #include <GL/glx.h>
  12. // ----------------------------------------------------------------------------
  13. // wxGLContext
  14. // ----------------------------------------------------------------------------
  15. class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
  16. {
  17. public:
  18. wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
  19. virtual ~wxGLContext();
  20. virtual bool SetCurrent(const wxGLCanvas& win) const;
  21. private:
  22. // attach context to the drawable or unset it (if NULL)
  23. static bool MakeCurrent(GLXDrawable drawable, GLXContext context);
  24. GLXContext m_glContext;
  25. DECLARE_CLASS(wxGLContext)
  26. };
  27. // ----------------------------------------------------------------------------
  28. // wxGLCanvasX11
  29. // ----------------------------------------------------------------------------
  30. class WXDLLIMPEXP_GL wxGLCanvasX11 : public wxGLCanvasBase
  31. {
  32. public:
  33. // initialization and dtor
  34. // -----------------------
  35. // default ctor doesn't do anything, InitVisual() must be called
  36. wxGLCanvasX11();
  37. // initializes the XVisualInfo corresponding to the given attributes
  38. bool InitVisual(const int *attribList);
  39. // frees XVisualInfo info
  40. virtual ~wxGLCanvasX11();
  41. // implement wxGLCanvasBase methods
  42. // --------------------------------
  43. virtual bool SwapBuffers();
  44. // X11-specific methods
  45. // --------------------
  46. // return GLX version: 13 means 1.3 &c
  47. static int GetGLXVersion();
  48. // return true if multisample extension is available
  49. static bool IsGLXMultiSampleAvailable();
  50. // get the X11 handle of this window
  51. virtual Window GetXWindow() const = 0;
  52. // override some wxWindow methods
  53. // ------------------------------
  54. // return true only if the window is realized: OpenGL context can't be
  55. // created until we are
  56. virtual bool IsShownOnScreen() const;
  57. // implementation only from now on
  58. // -------------------------------
  59. // get the GLXFBConfig/XVisualInfo we use
  60. GLXFBConfig *GetGLXFBConfig() const { return m_fbc; }
  61. XVisualInfo *GetXVisualInfo() const { return m_vi; }
  62. // initialize the global default GL visual, return false if matching visual
  63. // not found
  64. static bool InitDefaultVisualInfo(const int *attribList);
  65. // get the default GL X11 visual (may be NULL, shouldn't be freed by caller)
  66. static XVisualInfo *GetDefaultXVisualInfo() { return ms_glVisualInfo; }
  67. // free the global GL visual, called by wxGLApp
  68. static void FreeDefaultVisualInfo();
  69. // initializes XVisualInfo (in any case) and, if supported, GLXFBConfig
  70. //
  71. // returns false if XVisualInfo couldn't be initialized, otherwise caller
  72. // is responsible for freeing the pointers
  73. static bool InitXVisualInfo(const int *attribList,
  74. GLXFBConfig **pFBC, XVisualInfo **pXVisual);
  75. private:
  76. // fills in glattrs with attributes defined by wxattrs which must be
  77. // 0-terminated if it is non-NULL
  78. //
  79. // n is the max size of glattrs, false is returned if we overflow it, it
  80. // should be at least 16 to accommodate the default attributes
  81. static bool ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n);
  82. // this is only used if it's supported i.e. if GL >= 1.3
  83. GLXFBConfig *m_fbc;
  84. // used for all GL versions, obtained from GLXFBConfig for GL >= 1.3
  85. XVisualInfo *m_vi;
  86. // the global/default versions of the above
  87. static GLXFBConfig *ms_glFBCInfo;
  88. static XVisualInfo *ms_glVisualInfo;
  89. };
  90. // ----------------------------------------------------------------------------
  91. // wxGLApp
  92. // ----------------------------------------------------------------------------
  93. // this is used in wx/glcanvas.h, prevent it from defining a generic wxGLApp
  94. #define wxGL_APP_DEFINED
  95. class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase
  96. {
  97. public:
  98. wxGLApp() : wxGLAppBase() { }
  99. // implement wxGLAppBase method
  100. virtual bool InitGLVisual(const int *attribList)
  101. {
  102. return wxGLCanvasX11::InitDefaultVisualInfo(attribList);
  103. }
  104. // and implement this wxGTK::wxApp method too
  105. virtual void *GetXVisualInfo()
  106. {
  107. return wxGLCanvasX11::GetDefaultXVisualInfo();
  108. }
  109. // and override this wxApp method to clean up
  110. virtual int OnExit()
  111. {
  112. wxGLCanvasX11::FreeDefaultVisualInfo();
  113. return wxGLAppBase::OnExit();
  114. }
  115. private:
  116. DECLARE_DYNAMIC_CLASS(wxGLApp)
  117. };
  118. #endif // _WX_UNIX_GLX11_H_