]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/glcanvas.h
Compile fixes
[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 // 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(wxWindow* win, const wxGLContext* other=NULL /* for sharing display lists */);
64 virtual ~wxGLContext();
65
66 public:
67 // The win wxGLCanvas needs not necessarily be the same as the wxGLCanvas with which this context was created!
68 void SetCurrent(const wxGLCanvas& win) const;
69
70
71 private:
72 GLXContext m_glContext;
73
74 private:
75 DECLARE_CLASS(wxGLContext)
76 };
77
78 //---------------------------------------------------------------------------
79 // wxGLCanvas
80 //---------------------------------------------------------------------------
81
82 class WXDLLEXPORT wxGLCanvas: public wxWindow
83 {
84 public:
85 // This ctor is identical to the next, except for the fact that it
86 // doesn't create an implicit wxGLContext.
87 // The attribList parameter has been moved to avoid overload clashes.
88 wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
89 int *attribList = (int*) NULL,
90 const wxPoint& pos = wxDefaultPosition,
91 const wxSize& size = wxDefaultSize,
92 long style = 0, const wxString& name = wxGLCanvasName,
93 const wxPalette& palette = wxNullPalette );
94
95 wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
96 const wxPoint& pos = wxDefaultPosition,
97 const wxSize& size = wxDefaultSize,
98 long style = 0, const wxString& name = wxGLCanvasName,
99 int *attribList = (int*) NULL,
100 const wxPalette& palette = wxNullPalette );
101
102 wxGLCanvas( wxWindow *parent, const wxGLContext *shared,
103 wxWindowID id = -1,
104 const wxPoint& pos = wxDefaultPosition,
105 const wxSize& size = wxDefaultSize,
106 long style = 0, const wxString& name = wxGLCanvasName,
107 int *attribList = (int*) NULL,
108 const wxPalette& palette = wxNullPalette );
109
110 wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared,
111 wxWindowID id = -1,
112 const wxPoint& pos = wxDefaultPosition,
113 const wxSize& size = wxDefaultSize,
114 long style = 0, const wxString& name = wxGLCanvasName,
115 int *attribList = (int*) NULL,
116 const wxPalette& palette = wxNullPalette );
117
118 bool Create( wxWindow *parent,
119 const wxGLContext *shared = (wxGLContext*)NULL,
120 const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL,
121 wxWindowID id = -1,
122 const wxPoint& pos = wxDefaultPosition,
123 const wxSize& size = wxDefaultSize,
124 long style = 0,
125 const wxString& name = wxGLCanvasName,
126 int *attribList = (int*) NULL,
127 const wxPalette& palette = wxNullPalette );
128
129 virtual ~wxGLCanvas();
130
131 void SetCurrent(const wxGLContext& RC) const;
132 void SetCurrent();
133 void SetColour(const wxChar *colour);
134 void SwapBuffers();
135
136 void OnSize(wxSizeEvent& event);
137
138 void OnInternalIdle();
139
140 inline wxGLContext* GetContext() const { return m_glContext; }
141
142 // implementation
143
144 wxGLContext *m_glContext,
145 *m_sharedContext;
146 wxGLCanvas *m_sharedContextOf;
147 const bool m_createImplicitContext;
148 void *m_vi; // actually an XVisualInfo*
149 GLXFBConfig *m_fbc;
150 bool m_canFreeVi;
151 bool m_canFreeFBC;
152 GtkWidget *m_glWidget;
153 bool m_exposed;
154
155 // returns an XVisualInfo* based on desired GL attributes;
156 // returns NULL if an appropriate visual is not found. The
157 // caller is reponsible for using XFree() to deallocate
158 // the returned structure.
159 static void* ChooseGLVisual(int *attribList);
160 static void* ChooseGLFBC(int *attribList);
161 static void GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList );
162
163 static void QueryGLXVersion();
164 static int GetGLXVersion();
165 static int m_glxVersion;
166
167 private:
168 DECLARE_EVENT_TABLE()
169 DECLARE_CLASS(wxGLCanvas)
170 };
171
172 #endif
173 // _WX_GLCANVAS_H_
174