]>
Commit | Line | Data |
---|---|---|
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 | // Constants for attriblist | |
26 | //--------------------------------------------------------------------------- | |
27 | ||
28 | enum | |
29 | { | |
30 | WX_GL_RGBA=1, /* use true color palette */ | |
31 | WX_GL_BUFFER_SIZE, /* bits for buffer if not WX_GL_RGBA */ | |
32 | WX_GL_LEVEL, /* 0 for main buffer, >0 for overlay, <0 for underlay */ | |
33 | WX_GL_DOUBLEBUFFER, /* use doublebuffer */ | |
34 | WX_GL_STEREO, /* use stereoscopic display */ | |
35 | WX_GL_AUX_BUFFERS, /* number of auxiliary buffers */ | |
36 | WX_GL_MIN_RED, /* use red buffer with most bits (> MIN_RED bits) */ | |
37 | WX_GL_MIN_GREEN, /* use green buffer with most bits (> MIN_GREEN bits) */ | |
38 | WX_GL_MIN_BLUE, /* use blue buffer with most bits (> MIN_BLUE bits) */ | |
39 | WX_GL_MIN_ALPHA, /* use blue buffer with most bits (> MIN_ALPHA bits) */ | |
40 | WX_GL_DEPTH_SIZE, /* bits for Z-buffer (0,16,32) */ | |
41 | WX_GL_STENCIL_SIZE, /* bits for stencil buffer */ | |
42 | WX_GL_MIN_ACCUM_RED, /* use red accum buffer with most bits (> MIN_ACCUM_RED bits) */ | |
43 | WX_GL_MIN_ACCUM_GREEN, /* use green buffer with most bits (> MIN_ACCUM_GREEN bits) */ | |
44 | WX_GL_MIN_ACCUM_BLUE, /* use blue buffer with most bits (> MIN_ACCUM_BLUE bits) */ | |
45 | WX_GL_MIN_ACCUM_ALPHA /* use blue buffer with most bits (> MIN_ACCUM_ALPHA bits) */ | |
46 | }; | |
47 | ||
48 | //--------------------------------------------------------------------------- | |
49 | // classes | |
50 | //--------------------------------------------------------------------------- | |
51 | ||
52 | class WXDLLEXPORT wxGLContext; | |
53 | class WXDLLEXPORT wxGLCanvas; | |
54 | ||
55 | //--------------------------------------------------------------------------- | |
56 | // wxGLContext | |
57 | //--------------------------------------------------------------------------- | |
58 | ||
59 | ||
60 | class WXDLLEXPORT wxGLContext: public wxObject | |
61 | { | |
62 | public: | |
63 | wxGLContext( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette ); | |
64 | wxGLContext( | |
65 | bool WXUNUSED(isRGB), wxWindow *win, | |
66 | const wxPalette& WXUNUSED(palette), | |
67 | const wxGLContext *other /* for sharing display lists */ | |
68 | ); | |
69 | ~wxGLContext(); | |
70 | ||
71 | void SetCurrent(); | |
72 | void SetColour(const wxChar *colour); | |
73 | void SwapBuffers(); | |
74 | ||
75 | void SetupPixelFormat(); | |
76 | void SetupPalette(const wxPalette& palette); | |
77 | wxPalette CreateDefaultPalette(); | |
78 | ||
79 | inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; } | |
80 | inline wxWindow* GetWindow() const { return m_window; } | |
81 | inline GtkWidget* GetWidget() const { return m_widget; } | |
82 | inline GLXContext GetContext() const { return m_glContext; } | |
83 | ||
84 | public: | |
85 | GLXContext m_glContext; | |
86 | ||
87 | GtkWidget *m_widget; | |
88 | wxPalette m_palette; | |
89 | wxWindow* m_window; | |
90 | ||
91 | private: | |
92 | DECLARE_CLASS(wxGLContext) | |
93 | }; | |
94 | ||
95 | //--------------------------------------------------------------------------- | |
96 | // wxGLCanvas | |
97 | //--------------------------------------------------------------------------- | |
98 | ||
99 | class WXDLLEXPORT wxGLCanvas: public wxWindow | |
100 | { | |
101 | public: | |
102 | inline wxGLCanvas() { | |
103 | m_glContext = (wxGLContext*) NULL; | |
104 | m_sharedContext = (wxGLContext*) NULL; | |
105 | m_glWidget = (GtkWidget*) NULL; | |
106 | m_vi = (void*) NULL; | |
107 | m_exposed = FALSE; | |
108 | } | |
109 | wxGLCanvas( wxWindow *parent, wxWindowID id = -1, | |
110 | const wxPoint& pos = wxDefaultPosition, | |
111 | const wxSize& size = wxDefaultSize, | |
112 | long style = 0, const wxString& name = wxGLCanvasName, | |
113 | int *attribList = (int*) NULL, | |
114 | const wxPalette& palette = wxNullPalette ); | |
115 | wxGLCanvas( wxWindow *parent, const wxGLContext *shared, | |
116 | wxWindowID id = -1, | |
117 | const wxPoint& pos = wxDefaultPosition, | |
118 | const wxSize& size = wxDefaultSize, | |
119 | long style = 0, const wxString& name = wxGLCanvasName, | |
120 | int *attribList = (int*) NULL, | |
121 | const wxPalette& palette = wxNullPalette ); | |
122 | wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, | |
123 | wxWindowID id = -1, | |
124 | const wxPoint& pos = wxDefaultPosition, | |
125 | const wxSize& size = wxDefaultSize, | |
126 | long style = 0, const wxString& name = wxGLCanvasName, | |
127 | int *attribList = (int*) NULL, | |
128 | const wxPalette& palette = wxNullPalette ); | |
129 | ||
130 | bool Create( wxWindow *parent, | |
131 | const wxGLContext *shared = (wxGLContext*)NULL, | |
132 | const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL, | |
133 | wxWindowID id = -1, | |
134 | const wxPoint& pos = wxDefaultPosition, | |
135 | const wxSize& size = wxDefaultSize, | |
136 | long style = 0, | |
137 | const wxString& name = wxGLCanvasName, | |
138 | int *attribList = (int*) NULL, | |
139 | const wxPalette& palette = wxNullPalette ); | |
140 | ||
141 | ~wxGLCanvas(); | |
142 | ||
143 | void SetCurrent(); | |
144 | void SetColour(const wxChar *colour); | |
145 | void SwapBuffers(); | |
146 | ||
147 | void OnSize(wxSizeEvent& event); | |
148 | ||
149 | void OnInternalIdle(); | |
150 | ||
151 | inline wxGLContext* GetContext() const { return m_glContext; } | |
152 | ||
153 | // implementation | |
154 | ||
155 | wxGLContext *m_glContext, | |
156 | *m_sharedContext; | |
157 | wxGLCanvas *m_sharedContextOf; | |
158 | void *m_vi; // actually an XVisualInfo* | |
159 | GLXFBConfig *m_fbc; | |
160 | bool m_canFreeVi; | |
161 | bool m_canFreeFBC; | |
162 | GtkWidget *m_glWidget; | |
163 | bool m_exposed; | |
164 | ||
165 | // returns an XVisualInfo* based on desired GL attributes; | |
166 | // returns NULL if an appropriate visual is not found. The | |
167 | // caller is reponsible for using XFree() to deallocate | |
168 | // the returned structure. | |
169 | static void* ChooseGLVisual(int *attribList); | |
170 | static void* ChooseGLFBC(int *attribList); | |
171 | static void GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList ); | |
172 | ||
173 | static void QueryGLXVersion(); | |
174 | static int GetGLXVersion(); | |
175 | static int m_glxVersion; | |
176 | private: | |
177 | DECLARE_EVENT_TABLE() | |
178 | DECLARE_CLASS(wxGLCanvas) | |
179 | }; | |
180 | ||
181 | #endif | |
182 | // _WX_GLCANVAS_H_ | |
183 |