]> git.saurik.com Git - wxWidgets.git/blob - utils/glcanvas/gtk/glcanvas.h
In order to make shared wxGLContext work,\nadd new wxGLCanvas ctor passing a wxGLCanv...
[wxWidgets.git] / utils / glcanvas / gtk / glcanvas.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: glcanvas.h
3 // Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWindows 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 #ifdef __GNUG__
13 #pragma interface "glcanvas.h"
14 #endif
15
16 #ifndef _WX_GLCANVAS_H_
17 #define _WX_GLCANVAS_H_
18
19 #include "wx/defs.h"
20 #include "wx/scrolwin.h"
21
22 extern "C" {
23 #include "GL/gl.h"
24 #include "GL/glx.h"
25 #include "GL/glu.h"
26 }
27
28 //---------------------------------------------------------------------------
29 // Constants for attriblist
30 //---------------------------------------------------------------------------
31
32 enum
33 {
34 WX_GL_RGBA=1, /* use true color palette */
35 WX_GL_DEPTH_SIZE, /* bits for Z-buffer (0,16,32) */
36 WX_GL_DOUBLEBUFFER, /* use doublebuffer */
37 WX_GL_MIN_RED, /* use red buffer with most bits (> MIN_RED bits) */
38 WX_GL_MIN_GREEN, /* use green buffer with most bits (> MIN_GREEN bits) */
39 WX_GL_MIN_BLUE /* use blue buffer with most bits (> MIN_BLUE bits) */
40 /* these are enough constants for now, the remaining will be added later */
41 };
42
43 //---------------------------------------------------------------------------
44 // classes
45 //---------------------------------------------------------------------------
46
47 class wxGLContext;
48 class wxGLCanvas;
49
50 //---------------------------------------------------------------------------
51 // wxGLContext
52 //---------------------------------------------------------------------------
53
54
55 class wxGLContext: public wxObject
56 {
57 public:
58 wxGLContext( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette );
59 wxGLContext(
60 bool WXUNUSED(isRGB), wxWindow *win,
61 const wxPalette& WXUNUSED(palette),
62 const wxGLContext *other /* for sharing display lists */
63 );
64 ~wxGLContext();
65
66 void SetCurrent();
67 void SetColour(const char *colour);
68 void SwapBuffers();
69
70 void SetupPixelFormat();
71 void SetupPalette(const wxPalette& palette);
72 wxPalette CreateDefaultPalette();
73
74 inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; }
75 inline wxWindow* GetWindow() const { return m_window; }
76 inline GtkWidget* GetWidget() const { return m_widget; }
77 inline GLXContext GetContext() const { return m_glContext; }
78
79 public:
80 GLXContext m_glContext;
81
82 GtkWidget *m_widget;
83 wxPalette m_palette;
84 wxWindow* m_window;
85
86 private:
87 DECLARE_CLASS(wxGLContext)
88 };
89
90 //---------------------------------------------------------------------------
91 // wxGLContext
92 //---------------------------------------------------------------------------
93
94 class wxGLCanvas: public wxScrolledWindow
95 {
96 public:
97 inline wxGLCanvas() {
98 m_glContext = (wxGLContext*) NULL;
99 m_sharedContext = (wxGLContext*) NULL;
100 m_glWidget = (GtkWidget*) NULL;
101 m_vi = (void*) NULL;
102 m_exposed = FALSE;
103 }
104 wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
105 const wxPoint& pos = wxDefaultPosition,
106 const wxSize& size = wxDefaultSize,
107 long style = 0, const wxString& name = "GLCanvas",
108 int *attribList = (int*) NULL,
109 const wxPalette& palette = wxNullPalette );
110 wxGLCanvas( wxWindow *parent, const wxGLContext *shared = (wxGLContext *)NULL,
111 wxWindowID id = -1,
112 const wxPoint& pos = wxDefaultPosition,
113 const wxSize& size = wxDefaultSize,
114 long style = 0, const wxString& name = "GLCanvas",
115 int *attribList = (int*) NULL,
116 const wxPalette& palette = wxNullPalette );
117 wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared = (wxGLCanvas *)NULL,
118 wxWindowID id = -1,
119 const wxPoint& pos = wxDefaultPosition,
120 const wxSize& size = wxDefaultSize,
121 long style = 0, const wxString& name = "GLCanvas",
122 int *attribList = (int*) NULL,
123 const wxPalette& palette = wxNullPalette );
124
125 bool Create( wxWindow *parent,
126 const wxGLContext *shared = (wxGLContext*)NULL,
127 const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL,
128 wxWindowID id = -1,
129 const wxPoint& pos = wxDefaultPosition,
130 const wxSize& size = wxDefaultSize,
131 long style = 0, const wxString& name = "GLCanvas",
132 int *attribList = (int*) NULL,
133 const wxPalette& palette = wxNullPalette );
134
135 ~wxGLCanvas();
136
137 void SetCurrent();
138 void SetColour(const char *colour);
139 void SwapBuffers();
140
141 void OnSize(wxSizeEvent& event);
142
143 void OnInternalIdle();
144
145 inline wxGLContext* GetContext() const { return m_glContext; }
146
147 // implementation
148
149 wxGLContext *m_glContext,
150 *m_sharedContext;
151 wxGLCanvas *m_sharedContextOf;
152 void *m_vi;
153 GtkWidget *m_glWidget;
154 bool m_exposed;
155
156 private:
157 DECLARE_EVENT_TABLE()
158 DECLARE_CLASS(wxGLCanvas)
159 };
160
161 #endif