]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/glcanvas.h
derive wxConfig classes from wxObject and add wxRTTI macros to them (patch 1587607)
[wxWidgets.git] / include / wx / gtk / glcanvas.h
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$
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 WXDLLEXPORT wxGLContext;
29 class WXDLLEXPORT wxGLCanvas;
30
31 //---------------------------------------------------------------------------
32 // wxGLContext
33 //---------------------------------------------------------------------------
34
35
36 class WXDLLEXPORT wxGLContext: public wxObject
37 {
38 public:
39 wxGLContext(wxWindow* win, const wxGLContext* other=NULL /* for sharing display lists */);
40 virtual ~wxGLContext();
41
42 public:
43 // The win wxGLCanvas needs not necessarily be the same as the wxGLCanvas with which this context was created!
44 void SetCurrent(const wxGLCanvas& win) const;
45
46
47 private:
48 GLXContext m_glContext;
49
50 private:
51 DECLARE_CLASS(wxGLContext)
52 };
53
54 //---------------------------------------------------------------------------
55 // wxGLCanvas
56 //---------------------------------------------------------------------------
57
58 class WXDLLEXPORT wxGLCanvas: public wxWindow
59 {
60 public:
61 // This ctor is identical to the next, except for the fact that it
62 // doesn't create an implicit wxGLContext.
63 // The attribList parameter has been moved to avoid overload clashes.
64 wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
65 int *attribList = (int*) NULL,
66 const wxPoint& pos = wxDefaultPosition,
67 const wxSize& size = wxDefaultSize,
68 long style = 0, const wxString& name = wxGLCanvasName,
69 const wxPalette& palette = wxNullPalette );
70
71 wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
72 const wxPoint& pos = wxDefaultPosition,
73 const wxSize& size = wxDefaultSize,
74 long style = 0, const wxString& name = wxGLCanvasName,
75 int *attribList = (int*) NULL,
76 const wxPalette& palette = wxNullPalette );
77
78 wxGLCanvas( wxWindow *parent, const wxGLContext *shared,
79 wxWindowID id = -1,
80 const wxPoint& pos = wxDefaultPosition,
81 const wxSize& size = wxDefaultSize,
82 long style = 0, const wxString& name = wxGLCanvasName,
83 int *attribList = (int*) NULL,
84 const wxPalette& palette = wxNullPalette );
85
86 wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared,
87 wxWindowID id = -1,
88 const wxPoint& pos = wxDefaultPosition,
89 const wxSize& size = wxDefaultSize,
90 long style = 0, const wxString& name = wxGLCanvasName,
91 int *attribList = (int*) NULL,
92 const wxPalette& palette = wxNullPalette );
93
94 bool Create( wxWindow *parent,
95 const wxGLContext *shared = (wxGLContext*)NULL,
96 const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL,
97 wxWindowID id = -1,
98 const wxPoint& pos = wxDefaultPosition,
99 const wxSize& size = wxDefaultSize,
100 long style = 0,
101 const wxString& name = wxGLCanvasName,
102 int *attribList = (int*) NULL,
103 const wxPalette& palette = wxNullPalette );
104
105 virtual ~wxGLCanvas();
106
107 void SetCurrent(const wxGLContext& RC) const;
108 void SetCurrent();
109 void SetColour(const wxChar *colour);
110 void SwapBuffers();
111
112 void OnSize(wxSizeEvent& event);
113
114 void OnInternalIdle();
115
116 inline wxGLContext* GetContext() const { return m_glContext; }
117
118 // implementation
119
120 wxGLContext *m_glContext,
121 *m_sharedContext;
122 wxGLCanvas *m_sharedContextOf;
123 const bool m_createImplicitContext;
124 void *m_vi; // actually an XVisualInfo*
125 GLXFBConfig *m_fbc;
126 bool m_canFreeVi;
127 bool m_canFreeFBC;
128 GtkWidget *m_glWidget;
129 bool m_exposed;
130
131 // returns an XVisualInfo* based on desired GL attributes;
132 // returns NULL if an appropriate visual is not found. The
133 // caller is reponsible for using XFree() to deallocate
134 // the returned structure.
135 static void* ChooseGLVisual(int *attribList);
136 static void* ChooseGLFBC(int *attribList);
137 static void GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList );
138
139 static void QueryGLXVersion();
140 static int GetGLXVersion();
141 static int m_glxVersion;
142
143 private:
144 DECLARE_EVENT_TABLE()
145 DECLARE_CLASS(wxGLCanvas)
146 };
147
148 #endif
149 // _WX_GLCANVAS_H_
150