]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/glcanvas.h
correct access for virtuals
[wxWidgets.git] / include / wx / gtk1 / glcanvas.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk1/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( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette );
40 wxGLContext(
41 bool WXUNUSED(isRGB), wxWindow *win,
42 const wxPalette& WXUNUSED(palette),
43 const wxGLContext *other /* for sharing display lists */
44 );
45 virtual ~wxGLContext();
46
47 void SetCurrent();
48 void SetColour(const wxChar *colour);
49 void SwapBuffers();
50
51 void SetupPixelFormat();
52 void SetupPalette(const wxPalette& palette);
53 wxPalette CreateDefaultPalette();
54
55 inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; }
56 inline wxWindow* GetWindow() const { return m_window; }
57 inline GtkWidget* GetWidget() const { return m_widget; }
58 inline GLXContext GetContext() const { return m_glContext; }
59
60 public:
61 GLXContext m_glContext;
62
63 GtkWidget *m_widget;
64 wxPalette m_palette;
65 wxWindow* m_window;
66
67 private:
68 DECLARE_CLASS(wxGLContext)
69 };
70
71 //---------------------------------------------------------------------------
72 // wxGLCanvas
73 //---------------------------------------------------------------------------
74
75 class WXDLLEXPORT wxGLCanvas: public wxWindow
76 {
77 public:
78 inline wxGLCanvas() {
79 m_glContext = (wxGLContext*) NULL;
80 m_sharedContext = (wxGLContext*) NULL;
81 m_glWidget = (GtkWidget*) NULL;
82 m_vi = (void*) NULL;
83 m_exposed = FALSE;
84 }
85 wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
86 const wxPoint& pos = wxDefaultPosition,
87 const wxSize& size = wxDefaultSize,
88 long style = 0, const wxString& name = wxGLCanvasName,
89 int *attribList = (int*) NULL,
90 const wxPalette& palette = wxNullPalette );
91 wxGLCanvas( wxWindow *parent, const wxGLContext *shared,
92 wxWindowID id = -1,
93 const wxPoint& pos = wxDefaultPosition,
94 const wxSize& size = wxDefaultSize,
95 long style = 0, const wxString& name = wxGLCanvasName,
96 int *attribList = (int*) NULL,
97 const wxPalette& palette = wxNullPalette );
98 wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared,
99 wxWindowID id = -1,
100 const wxPoint& pos = wxDefaultPosition,
101 const wxSize& size = wxDefaultSize,
102 long style = 0, const wxString& name = wxGLCanvasName,
103 int *attribList = (int*) NULL,
104 const wxPalette& palette = wxNullPalette );
105
106 bool Create( wxWindow *parent,
107 const wxGLContext *shared = (wxGLContext*)NULL,
108 const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL,
109 wxWindowID id = -1,
110 const wxPoint& pos = wxDefaultPosition,
111 const wxSize& size = wxDefaultSize,
112 long style = 0,
113 const wxString& name = wxGLCanvasName,
114 int *attribList = (int*) NULL,
115 const wxPalette& palette = wxNullPalette );
116
117 virtual ~wxGLCanvas();
118
119 void SetCurrent();
120 void SetColour(const wxChar *colour);
121 void SwapBuffers();
122
123 void OnSize(wxSizeEvent& event);
124
125 void OnInternalIdle();
126
127 inline wxGLContext* GetContext() const { return m_glContext; }
128
129 // implementation
130
131 wxGLContext *m_glContext,
132 *m_sharedContext;
133 wxGLCanvas *m_sharedContextOf;
134 void *m_vi; // actually an XVisualInfo*
135 GLXFBConfig *m_fbc;
136 bool m_canFreeVi;
137 bool m_canFreeFBC;
138 GtkWidget *m_glWidget;
139 bool m_exposed;
140
141 // returns an XVisualInfo* based on desired GL attributes;
142 // returns NULL if an appropriate visual is not found. The
143 // caller is reponsible for using XFree() to deallocate
144 // the returned structure.
145 static void* ChooseGLVisual(int *attribList);
146 static void* ChooseGLFBC(int *attribList);
147 static void GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList );
148
149 static void QueryGLXVersion();
150 static int GetGLXVersion();
151 static int m_glxVersion;
152 private:
153 DECLARE_EVENT_TABLE()
154 DECLARE_CLASS(wxGLCanvas)
155 };
156
157 #endif
158 // _WX_GLCANVAS_H_
159