changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / WindowSystem / WIN32 / OSGWIN32Window.cpp
blob0f5ed837e5a8db15193ab0eade60129ba156a1ef
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 // Forget everything if we're not doing a windows compile
49 #ifdef WIN32
51 #include "OSGWIN32Window.h"
53 OSG_USING_NAMESPACE
55 // Documentation for this class is emited in the
56 // OSGWIN32WindowBase.cpp file.
57 // To modify it, please change the .fcd file (OSGWIN32Window.fcd) and
58 // regenerate the base file.
60 /*----------------------- constructors & destructors ----------------------*/
62 //! Constructor
64 WIN32Window::WIN32Window(void) :
65 Inherited()
69 //! Copy Constructor
71 WIN32Window::WIN32Window(const WIN32Window &source) :
72 Inherited(source)
76 //! Destructor
78 WIN32Window::~WIN32Window(void)
82 /*----------------------------- class specific ----------------------------*/
84 //! initialize the static features of the class, e.g. action callbacks
86 void WIN32Window::initMethod(InitPhase ePhase)
88 Inherited::initMethod(ePhase);
91 //! react to field changes
93 void WIN32Window::changed(BitVector whichField,
94 UInt32 origin,
95 BitVector details)
97 Inherited::changed(whichField, origin, details);
100 //! output the instance for debug purposes
102 void WIN32Window::dump( UInt32 ,
103 const BitVector ) const
105 SLOG << "Dump WIN32Window NI" << std::endl;
108 /*-------------------------- your_category---------------------------------*/
110 /*! init the window: create the HDC and HGLRC
112 void WIN32Window::init(GLInitFunctor oFunc)
114 setHdc(GetDC(getHwnd()));
116 if(getHglrc() == NULL)
118 setHglrc(wglCreateContext(getHdc()));
120 if(getHglrc() == NULL)
122 std::cerr << "WIN32Window::init: failed: "
123 << GetLastError()
124 << std::endl;
128 Inherited::init(oFunc);
130 if(getHdc() != NULL)
132 ReleaseDC(getHwnd(), getHdc());
134 setHdc(NULL);
138 void WIN32Window::terminate(void)
140 Inherited::doTerminate();
142 if(getHglrc() != NULL)
144 this->doDeactivate();
146 wglDeleteContext(getHglrc());
148 setHglrc(NULL);
153 /*! activate the window: set the HDC and bind the OGL context
155 void WIN32Window::doActivate( void )
157 if(getHdc() == NULL)
158 setHdc(GetDC(getHwnd()));
160 if(!wglMakeCurrent(getHdc(), getHglrc()))
162 std::cerr << "WIN32Window::activate: failed: "
163 << GetLastError()
164 << std::endl;
168 void WIN32Window::doDeactivate ( void )
170 // unbind the context
171 wglMakeCurrent(NULL, NULL);
173 // release the hardware device context
174 if(getHdc() != NULL)
176 ReleaseDC(getHwnd(), getHdc());
177 setHdc(NULL);
181 // swap front and back buffers
182 bool WIN32Window::doSwap(void)
184 if(getHdc() == NULL)
185 setHdc(GetDC(getHwnd()));
187 return SwapBuffers(getHdc()) != 0;
190 bool WIN32Window::hasContext(void)
192 return (this->getHglrc() != NULL);
195 #endif // WIN32