Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SoWinGLWidget.h
1 #ifndef SOWIN_GLWIDGET_H
2 #define SOWIN_GLWIDGET_H
3 
4 //
5 
6 /**************************************************************************\
7  * Copyright (c) Kongsberg Oil & Gas Technologies AS
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are
12  * met:
13  *
14  * Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  *
17  * Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in the
19  * documentation and/or other materials provided with the distribution.
20  *
21  * Neither the name of the copyright holder nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 \**************************************************************************/
37 
38 #include <Inventor/SbBasic.h>
39 #include <Inventor/Win/SoWinBasic.h>
40 #include <Inventor/Win/SoWinComponent.h>
41 
42 #ifdef __COIN_SOQT__
43 class QEvent;
44 #endif // __COIN_SOQT__
45 #ifdef __COIN_SOXT__
46 /*
47  * GL/glx.h includes X11/Xmd.h which contains typedefs for BOOL and
48  * INT32 that conflict with the definitions in windef.h (which is
49  * included from windows.h, which may be included from
50  * Inventor/system/gl.h). To avoid this conflict, we rename the
51  * typedefs done in X11/Xmd.h to use other names (tempbool and
52  * tempint32), and try to clean up the hack after the header has been
53  * parsed. 2003-06-25 larsa
54  */
55 #ifndef BOOL
56 #define BOOL tempbool
57 #define COIN_DEFINED_BOOL
58 #endif /* !BOOL */
59 #ifndef INT32
60 #define INT32 tempint32
61 #define COIN_DEFINED_INT32
62 #endif /* !INT32 */
63 #include <GL/glx.h>
64 /*
65  * This is the cleanup part of the X11/Xmd.h conflict fix hack set up
66  * above. 2003-06-25 larsa
67  */
68 #ifdef COIN_DEFINED_BOOL
69 #undef BOOL
70 #undef COIN_DEFINED_BOOL
71 #endif /* COIN_DEFINED_BOOL */
72 #ifdef COIN_DEFINED_INT32
73 #undef INT32
74 #undef COIN_DEFINED_INT32
75 #endif /* COIN_DEFINED_INT32 */
76 #endif // __COIN_SOXT__
77 #ifdef __COIN_SOGTK__
78 #include <gtk/gtk.h>
79 #endif // __COIN_SOGTK__
80 
81 // *************************************************************************
82 
83 enum GLModes {
84  SO_GL_RGB = 0x01, SO_GLX_RGB = SO_GL_RGB,
85  SO_GL_DOUBLE = 0x02, SO_GLX_DOUBLE = SO_GL_DOUBLE,
86  SO_GL_ZBUFFER = 0x04, SO_GLX_ZBUFFER = SO_GL_ZBUFFER,
87  SO_GL_OVERLAY = 0x08, SO_GLX_OVERLAY = SO_GL_OVERLAY,
88  SO_GL_STEREO = 0x10, SO_GLX_STEREO = SO_GL_STEREO
89 };
90 
91 // *************************************************************************
92 
93 class SOWIN_DLL_API SoWinGLWidget : public SoWinComponent {
94  SOWIN_OBJECT_ABSTRACT_HEADER(SoWinGLWidget, SoWinComponent);
95 
96 public:
97 
98  void setBorder(const SbBool enable);
99  SbBool isBorder(void) const;
100 
101  virtual void setDoubleBuffer(const SbBool enable);
102  SbBool isDoubleBuffer(void) const;
103 
104  void setDrawToFrontBufferEnable(const SbBool enable);
105  SbBool isDrawToFrontBufferEnable(void) const;
106 
107  void setQuadBufferStereo(const SbBool enable);
108  SbBool isQuadBufferStereo(void) const;
109 
110  void setAccumulationBuffer(const SbBool enable);
111  SbBool getAccumulationBuffer(void) const;
112 
113  void setStencilBuffer(const SbBool enable);
114  SbBool getStencilBuffer(void) const;
115 
116  void setAlphaChannel(const SbBool enable);
117  SbBool getAlphaChannel(void) const;
118 
119  void setOverlayRender(const SbBool onoff);
120  SbBool isOverlayRender(void) const;
121 
122  void setSampleBuffers(const int numsamples);
123  int getSampleBuffers(void) const;
124 
125  void setStealFocus(SbBool enable);
126  SbBool isStealFocus(void) const;
127 
128  HWND getGLWidget(void) const;
129  HWND getNormalWidget(void) const;
130  HWND getOverlayWidget(void) const;
131 
132  SbBool hasOverlayGLArea(void) const;
133  SbBool hasNormalGLArea(void) const;
134 
135  unsigned long getOverlayTransparentPixel(void);
136 
137  // OpenGL query functions.
138  void getPointSizeLimits(SbVec2f & range, float & granularity);
139  void getLineWidthLimits(SbVec2f & range, float & granularity);
140 
141 protected:
142  SoWinGLWidget(HWND const parent = NULL,
143  const char * const name = NULL,
144  const SbBool embed = TRUE,
145  const int glmodes = SO_GL_RGB,
146  const SbBool build = TRUE);
147  ~SoWinGLWidget();
148 
149  virtual void processEvent(MSG* event);
150 
151  HWND buildWidget(HWND parent);
152 
153  virtual void redraw(void) = 0;
154  virtual void redrawOverlay(void);
155 
156  virtual void initGraphic(void);
157  virtual void initOverlayGraphic(void);
158 
159  virtual void sizeChanged(const SbVec2s & size);
160  virtual void widgetChanged(HWND w);
161 
162  void setGLSize(const SbVec2s size);
163  SbVec2s getGLSize(void) const;
164  float getGLAspectRatio(void) const;
165 
166  // old aliases
167  void setGlxSize(const SbVec2s size) { this->setGLSize(size); }
168  SbVec2s getGlxSize(void) const { return this->getGLSize(); }
169  float getGlxAspectRatio(void) const { return this->getGLAspectRatio(); }
170 
171  void setStereoBuffer(SbBool flag);
172  SbBool isStereoBuffer(void) const;
173 
174  SbBool isRGBMode(void);
175 
178 
179  void glLockNormal(void);
180  void glUnlockNormal(void);
181 
182  void glLockOverlay(void);
183  void glUnlockOverlay(void);
184 
185  void glSwapBuffers(void);
186  void glFlushBuffer(void);
187 
188  virtual SbBool glScheduleRedraw(void);
189 
190 private:
191  class SoWinGLWidgetP * pimpl;
192  friend class SoGuiGLWidgetP;
193  friend class SoWinGLWidgetP;
194 
195  // FIXME: get rid of toolkit-specific stuff below. 20020613 mortene.
196 
197 #ifdef __COIN_SOXT__
198 public:
199  GLXContext getNormalContext(void);
200  GLXContext getOverlayContext(void);
201 
202  Window getNormalWindow(void);
203  Window getOverlayWindow(void);
204 
205  int getOverlayColorMapSize(void);
206  int getColorMapSize(void);
207 
208  virtual void setNormalVisual(XVisualInfo * visual);
209  XVisualInfo * getNormalVisual(void);
210  virtual void setOverlayVisual(XVisualInfo * visual);
211  XVisualInfo * getOverlayVisual(void);
212 
213 protected:
214  static void eventHandler(Widget, SoXtGLWidget *, XAnyEvent *, Boolean *);
215 
216  int getDisplayListShareGroup(GLXContext context);
217  Widget getGlxMgrWidget(void);
218 #endif // __COIN_SOXT__
219 
220 #ifdef __COIN_SOGTK__
221 protected:
222  virtual SbBool eventFilter(GtkWidget * object, GdkEvent * event);
223 #endif // __COIN_SOGTK__
224 
225 };
226 
227 // *************************************************************************
228 
229 #endif // ! SOWIN_GLWIDGET_H
SbBool drawToFrontBuffer
Definition: SoWinGLWidget.h:177
SbBool waitForExpose
Definition: SoWinGLWidget.h:176
SbVec2s getGlxSize(void) const
Definition: SoWinGLWidget.h:168
float getGlxAspectRatio(void) const
Definition: SoWinGLWidget.h:169
virtual void sizeChanged(const SbVec2s &size)
Definition: SoWinComponent.cpp:597
The SoWinComponent class is the base class for all GUI components.
Definition: SoWinComponent.h:63
void setGlxSize(const SbVec2s size)
Definition: SoWinGLWidget.h:167
The SoWinGLWidget class manages OpenGL contexts.
Definition: SoWinGLWidget.h:93