]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/glcanvas.h
Commit Carsten Fuchs' patch for separating wxGLCanvas
[wxWidgets.git] / include / wx / msw / glcanvas.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/glcanvas.h
3 // Purpose: wxGLCanvas, for using OpenGL with wxWidgets under Windows
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GLCANVAS_H_
13 #define _WX_GLCANVAS_H_
14
15 #include "wx/palette.h"
16 #include "wx/scrolwin.h"
17
18 #include <windows.h>
19 #include "wx/msw/winundef.h"
20
21 #include <GL/gl.h>
22
23 //---------------------------------------------------------------------------
24 // Constants for attriblist
25 //---------------------------------------------------------------------------
26
27 // The generic GL implementation doesn't support most of these options,
28 // such as stereo, auxiliary buffers, alpha channel, and accum buffer.
29 // Other implementations may actually support them.
30
31 enum
32 {
33 WX_GL_RGBA=1, /* use true color palette */
34 WX_GL_BUFFER_SIZE, /* bits for buffer if not WX_GL_RGBA */
35 WX_GL_LEVEL, /* 0 for main buffer, >0 for overlay, <0 for underlay */
36 WX_GL_DOUBLEBUFFER, /* use doublebuffer */
37 WX_GL_STEREO, /* use stereoscopic display */
38 WX_GL_AUX_BUFFERS, /* number of auxiliary buffers */
39 WX_GL_MIN_RED, /* use red buffer with most bits (> MIN_RED bits) */
40 WX_GL_MIN_GREEN, /* use green buffer with most bits (> MIN_GREEN bits) */
41 WX_GL_MIN_BLUE, /* use blue buffer with most bits (> MIN_BLUE bits) */
42 WX_GL_MIN_ALPHA, /* use blue buffer with most bits (> MIN_ALPHA bits) */
43 WX_GL_DEPTH_SIZE, /* bits for Z-buffer (0,16,32) */
44 WX_GL_STENCIL_SIZE, /* bits for stencil buffer */
45 WX_GL_MIN_ACCUM_RED, /* use red accum buffer with most bits (> MIN_ACCUM_RED bits) */
46 WX_GL_MIN_ACCUM_GREEN, /* use green buffer with most bits (> MIN_ACCUM_GREEN bits) */
47 WX_GL_MIN_ACCUM_BLUE, /* use blue buffer with most bits (> MIN_ACCUM_BLUE bits) */
48 WX_GL_MIN_ACCUM_ALPHA /* use blue buffer with most bits (> MIN_ACCUM_ALPHA bits) */
49 };
50
51 class WXDLLIMPEXP_GL wxGLCanvas; /* forward reference */
52
53 class WXDLLIMPEXP_GL wxGLContext: public wxObject
54 {
55 public:
56 wxGLContext(wxGLCanvas *win, const wxGLContext* other=NULL /* for sharing display lists */ );
57 virtual ~wxGLContext();
58
59 inline HGLRC GetGLRC() const { return m_glContext; }
60
61 protected:
62 HGLRC m_glContext;
63
64 private:
65 DECLARE_CLASS(wxGLContext)
66 };
67
68 class WXDLLIMPEXP_GL wxGLCanvas: public wxWindow
69 {
70 public:
71 // This ctor is identical to the next, except for the fact that it
72 // doesn't create an implicit wxGLContext.
73 // The attribList parameter has been moved to avoid overload clashes.
74 wxGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY,
75 int* attribList = 0,
76 const wxPoint& pos = wxDefaultPosition,
77 const wxSize& size = wxDefaultSize, long style = 0,
78 const wxString& name = wxGLCanvasName,
79 const wxPalette& palette = wxNullPalette);
80
81 wxGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY,
82 const wxPoint& pos = wxDefaultPosition,
83 const wxSize& size = wxDefaultSize, long style = 0,
84 const wxString& name = wxGLCanvasName, int *attribList = 0,
85 const wxPalette& palette = wxNullPalette);
86
87 wxGLCanvas(wxWindow *parent,
88 const wxGLContext *shared,
89 wxWindowID id = wxID_ANY,
90 const wxPoint& pos = wxDefaultPosition,
91 const wxSize& size = wxDefaultSize,
92 long style = 0,
93 const wxString& name = wxGLCanvasName,
94 int *attribList = (int *) NULL,
95 const wxPalette& palette = wxNullPalette);
96
97 wxGLCanvas(wxWindow *parent,
98 const wxGLCanvas *shared,
99 wxWindowID id = wxID_ANY,
100 const wxPoint& pos = wxDefaultPosition,
101 const wxSize& size = wxDefaultSize,
102 long style = 0,
103 const wxString& name = wxGLCanvasName,
104 int *attribList = 0,
105 const wxPalette& palette = wxNullPalette);
106
107 virtual ~wxGLCanvas();
108
109 // Replaces wxWindow::Create functionality, since
110 // we need to use a different window class
111 bool Create(wxWindow *parent, wxWindowID id,
112 const wxPoint& pos, const wxSize& size,
113 long style, const wxString& name);
114
115 void SetCurrent(const wxGLContext& RC) const;
116 void SetCurrent();
117
118 #ifdef __WXUNIVERSAL__
119 virtual bool SetCurrent(bool doit) { return wxWindow::SetCurrent(doit); };
120 #endif
121
122 void SetColour(const wxChar *colour);
123
124 void SwapBuffers();
125
126 void OnSize(wxSizeEvent& event);
127
128 void OnQueryNewPalette(wxQueryNewPaletteEvent& event);
129
130 void OnPaletteChanged(wxPaletteChangedEvent& event);
131
132 inline wxGLContext* GetContext() const { return m_glContext; }
133
134 inline WXHDC GetHDC() const { return m_hDC; }
135
136 void SetupPixelFormat(int *attribList = (int *) NULL);
137
138 void SetupPalette(const wxPalette& palette);
139
140 wxPalette CreateDefaultPalette();
141
142 inline wxPalette* GetPalette() const { return (wxPalette *) &m_palette; }
143
144 protected:
145 wxGLContext* m_glContext; // this is typedef-ed ptr, in fact
146 wxPalette m_palette;
147 WXHDC m_hDC;
148
149 private:
150 DECLARE_EVENT_TABLE()
151 DECLARE_CLASS(wxGLCanvas)
152 };
153
154 #endif
155 // _WX_GLCANVAS_H_
156