1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        glcanvas.h
3 // Purpose:     wxGLCanvas, for using OpenGL/Mesa with wxWidgets and GTK
4 // Author:      Robert Roebling
5 // Modified by:
6 // Created:     17/8/98
7 // RCS-ID:      $Id: glcanvas.h 47196 2007-07-06 15:43:06Z VZ $
8 // Copyright:   (c) Robert Roebling
9 // Licence:     wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef _WX_GLCANVAS_H_
13 #define _WX_GLCANVAS_H_
14 
15 #include "wx/scrolwin.h"
16 #include "wx/app.h"
17 
18 extern "C" {
19 #include <GL/gl.h>
20 #include <GL/glx.h>
21 #include <GL/glu.h>
22 }
23 
24 //---------------------------------------------------------------------------
25 // classes
26 //---------------------------------------------------------------------------
27 
28 class WXDLLIMPEXP_GL wxGLCanvas;
29 
30 //---------------------------------------------------------------------------
31 // wxGLContext
32 //---------------------------------------------------------------------------
33 
34 
35 class WXDLLIMPEXP_GL wxGLContext: public wxObject
36 {
37 public:
38     wxGLContext(wxWindow* win, const wxGLContext* other=NULL /* for sharing display lists */);
39     virtual ~wxGLContext();
40 
41 public:
42     // The win wxGLCanvas needs not necessarily be the same as the wxGLCanvas with which this context was created!
43     void SetCurrent(const wxGLCanvas& win) const;
44 
45 
46 private:
47     GLXContext m_glContext;
48 
49 private:
50     DECLARE_CLASS(wxGLContext)
51 };
52 
53 //---------------------------------------------------------------------------
54 // wxGLCanvas
55 //---------------------------------------------------------------------------
56 
57 class WXDLLIMPEXP_GL wxGLCanvas: public wxWindow
58 {
59 public:
60     // This ctor is identical to the next, except for the fact that it
61     // doesn't create an implicit wxGLContext.
62     // The attribList parameter has been moved to avoid overload clashes.
63     wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
64         int *attribList = (int*) NULL,
65         const wxPoint& pos = wxDefaultPosition,
66         const wxSize& size = wxDefaultSize,
67         long style = 0, const wxString& name = wxGLCanvasName,
68         const wxPalette& palette = wxNullPalette );
69 
70    wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
71         const wxPoint& pos = wxDefaultPosition,
72         const wxSize& size = wxDefaultSize,
73         long style = 0, const wxString& name = wxGLCanvasName,
74         int *attribList = (int*) NULL,
75         const wxPalette& palette = wxNullPalette );
76 
77    wxGLCanvas( wxWindow *parent, const wxGLContext *shared,
78         wxWindowID id = -1,
79         const wxPoint& pos = wxDefaultPosition,
80         const wxSize& size = wxDefaultSize,
81         long style = 0, const wxString& name = wxGLCanvasName,
82         int *attribList = (int*) NULL,
83         const wxPalette& palette = wxNullPalette );
84 
85    wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared,
86         wxWindowID id = -1,
87         const wxPoint& pos = wxDefaultPosition,
88         const wxSize& size = wxDefaultSize,
89         long style = 0, const wxString& name = wxGLCanvasName,
90         int *attribList = (int*) NULL,
91         const wxPalette& palette = wxNullPalette );
92 
93    bool Create( wxWindow *parent,
94                 const wxGLContext *shared = (wxGLContext*)NULL,
95                 const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL,
96                 wxWindowID id = -1,
97                 const wxPoint& pos = wxDefaultPosition,
98                 const wxSize& size = wxDefaultSize,
99                 long style = 0,
100                 const wxString& name = wxGLCanvasName,
101                 int *attribList = (int*) NULL,
102                 const wxPalette& palette = wxNullPalette );
103 
104    virtual ~wxGLCanvas();
105 
106    void SetCurrent(const wxGLContext& RC) const;
107    void SetCurrent();
108    void SetColour(const wxChar *colour);
109    void SwapBuffers();
110 
111    void OnSize(wxSizeEvent& event);
112 
113    void OnInternalIdle();
114 
GetContext()115    inline wxGLContext* GetContext() const { return m_glContext; }
116 
117  // implementation
118 
119     wxGLContext      *m_glContext,
120                      *m_sharedContext;
121     wxGLCanvas       *m_sharedContextOf;
122     const bool        m_createImplicitContext;
123     void             *m_vi; // actually an XVisualInfo*
124     GLXFBConfig      *m_fbc;
125     bool              m_canFreeVi;
126     bool              m_canFreeFBC;
127     GtkWidget        *m_glWidget;
128     bool              m_exposed;
129 
130     // returns an XVisualInfo* based on desired GL attributes;
131     // returns NULL if an appropriate visual is not found. The
132     // caller is reponsible for using XFree() to deallocate
133     // the returned structure.
134     static void* ChooseGLVisual(int *attribList);
135     static void* ChooseGLFBC(int *attribList);
136     static void GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList );
137 
138     static void QueryGLXVersion();
139     static int GetGLXVersion();
140     static int m_glxVersion;
141 
142 private:
143     DECLARE_EVENT_TABLE()
144     DECLARE_CLASS(wxGLCanvas)
145 };
146 
147 #endif
148     // _WX_GLCANVAS_H_
149 
150