OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GraphicsWindow.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSGVIEWER_GRAPHICWINDOW
15 #define OSGVIEWER_GRAPHICWINDOW 1
16 
17 #include <osg/GraphicsContext>
18 #include <osg/Notify>
19 
20 #include <osgGA/EventQueue>
21 #include <osgGA/GUIActionAdapter>
22 
23 #include <osgViewer/Export>
24 
25 
26 extern "C"
27 {
29 }
30 
31 namespace osgViewer {
32 
33 class View;
34 
35 
43 {
44  public:
45 
46  GraphicsWindow() { _eventQueue = new osgGA::EventQueue; _eventQueue->setGraphicsContext(this); }
47 
48  virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindow*>(object)!=0; }
49  virtual const char* libraryName() const { return "osgViewer"; }
50  virtual const char* className() const { return "GraphicsWindow"; }
51 
52  void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
53  osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
54  const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
55 
57  virtual bool checkEvents() { return !(_eventQueue->empty()); }
58 
60  void setWindowRectangle(int x, int y, int width, int height)
61  {
62  if (setWindowRectangleImplementation(x ,y ,width, height) && _traits.valid())
63  {
64  resized(x,y,width,height);
65  }
66  }
67 
69  virtual bool setWindowRectangleImplementation(int /*x*/, int /*y*/, int /*width*/, int /*height*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowRectangleImplementation(..) not implemented."<<std::endl; return false; }
70 
72  virtual void getWindowRectangle(int& x, int& y, int& width, int& height) { if (_traits.valid()) { x = _traits->x; y = _traits->y; width = _traits->width; height = _traits->height; } }
73 
75  void setWindowDecoration(bool flag)
76  {
77  if (setWindowDecorationImplementation(flag) && _traits.valid())
78  {
79  _traits->windowDecoration = flag;
80  }
81  }
82 
84  virtual bool setWindowDecorationImplementation(bool /*flag*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowDecorationImplementation(..) not implemented."<<std::endl; return false; }
85 
86 
88  virtual bool getWindowDecoration() const { return _traits.valid() ? _traits->windowDecoration : false; }
89 
91  virtual void grabFocus() { osg::notify(osg::NOTICE)<<"GraphicsWindow::grabFocus(..) not implemented."<<std::endl; }
92 
94  virtual void grabFocusIfPointerInWindow() { osg::notify(osg::NOTICE)<<"GraphicsWindow::grabFocusIfPointerInWindow(..) not implemented."<<std::endl; }
95 
97  virtual void raiseWindow() { osg::notify(osg::NOTICE)<<"GraphicsWindow::raiseWindow(..) not implemented."<<std::endl; }
98 
100  enum MouseCursor {
123  BottomLeftCorner
124  };
125 
127  virtual void setWindowName(const std::string& /*name*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowName(..) not implemented."<<std::endl; }
128 
130  virtual std::string getWindowName() { return _traits.valid() ? _traits->windowName : ""; }
131 
133  virtual void useCursor(bool cursorOn) { setCursor(cursorOn ? InheritCursor : NoCursor); }
134 
136  virtual void setCursor(MouseCursor /*mouseCursor*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setCursor(..) not implemented."<<std::endl; }
137 
139  //virtual MouseCursor createCursor(const char *data, const char *mask, unsigned w, unsigned h, unsigned hotx, unsigned hoty) { osg::notify(osg::NOTICE)<<"GraphicsWindow::createCursor(..) not implemented."<<std::endl; }
140 
142  virtual void setSyncToVBlank(bool on)
143  {
144  osg::notify(osg::NOTICE) << "GraphicsWindow::setSyncToVBlank(" << on << ") not implemented." << std::endl;
145  }
146 
147  bool getSyncToVBlank() const { return _traits.valid() ? _traits->vsync : true; }
148 
150  virtual void setSwapGroup(bool on, GLuint group, GLuint barrier)
151  {
152  osg::notify(osg::NOTICE) << "GraphicsWindow::setSwapGroup(" << on << " " << group << " " << barrier << ") not implemented." << std::endl;
153  }
154 
155  void getSwapGroup(bool& on, GLuint& group, GLuint& barrier) const { on = _traits->swapGroupEnabled; group = _traits->swapGroup; barrier = _traits->swapBarrier; }
156 
157  public:
158 
160  virtual bool valid() const { osg::notify(osg::NOTICE)<<"GraphicsWindow::valid() not implemented."<<std::endl; return false; }
161 
164  virtual bool realizeImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::realizeImplementation() not implemented."<<std::endl; return false; }
165 
168  virtual bool isRealizedImplementation() const { osg::notify(osg::NOTICE)<<"GraphicsWindow::isRealizedImplementation() not implemented."<<std::endl; return false; }
169 
172  virtual void closeImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::closeImplementation() not implemented."<<std::endl; }
173 
176  virtual bool makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; return false;}
177 
180  virtual bool makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; return false;}
181 
183  virtual bool releaseContextImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::releaseContextImplementation(..) not implemented."<<std::endl; return false; }
184 
187  virtual void bindPBufferToTextureImplementation(GLenum /*buffer*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::bindPBufferToTextureImplementation(..) not implemented."<<std::endl; }
188 
191  virtual void swapBuffersImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow:: swapBuffersImplementation() not implemented."<<std::endl; }
192 
193  public:
194 
195  typedef std::list<osgViewer::View*> Views;
198  void getViews(Views& views);
199 
200  // Override from GUIActionAdapter
201  virtual void requestRedraw();
202 
203  // Override from GUIActionAdapter
204  virtual void requestContinuousUpdate(bool /*needed*/=true) {}
205 
206  // Override from GUIActionAdapter
207  virtual void requestWarpPointer(float /*x*/,float /*y*/) {}
208 
209 
210  protected:
211 
213 
214 };
215 
216 
218 {
219  public:
220 
222  {
223  _traits = traits;
224 
225  init();
226 
227  }
228 
229  GraphicsWindowEmbedded(int x, int y, int width, int height)
230  {
231  _traits = new GraphicsContext::Traits;
232  _traits->x = x;
233  _traits->y = y;
234  _traits->width = width;
235  _traits->height = height;
236 
237  init();
238  }
239 
240  virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowEmbedded*>(object)!=0; }
241  virtual const char* libraryName() const { return "osgViewer"; }
242  virtual const char* className() const { return "GraphicsWindowEmbedded"; }
243 
244  void init()
245  {
246  if (valid())
247  {
248  setState( new osg::State );
249  getState()->setGraphicsContext(this);
250 
251  if (_traits.valid() && _traits->sharedContext.valid())
252  {
253  getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
254  incrementContextIDUsageCount( getState()->getContextID() );
255  }
256  else
257  {
259  }
260  }
261  }
262 
263  // dummy implementations, assume that graphics context is *always* current and valid.
264  virtual bool valid() const { return true; }
265  virtual bool realizeImplementation() { return true; }
266  virtual bool isRealizedImplementation() const { return true; }
267  virtual void closeImplementation() {}
268  virtual bool makeCurrentImplementation() { return true; }
269  virtual bool releaseContextImplementation() { return true; }
270  virtual void swapBuffersImplementation() {}
271  virtual void grabFocus() {}
272  virtual void grabFocusIfPointerInWindow() {}
273  virtual void raiseWindow() {}
274 };
275 
277 {
279 };
280 
281 #define USE_GRAPICSWINDOW_IMPLEMENTATION(ext) \
282  extern "C" void graphicswindow_##ext(void); \
283  static osgViewer::GraphicsWindowFunctionProxy graphicswindowproxy_##ext(graphicswindow_##ext);
284 
285 #if defined(_WIN32)
286  #define USE_GRAPHICSWINDOW() USE_GRAPICSWINDOW_IMPLEMENTATION(Win32)
287 #elif defined(__APPLE__)
288  #define USE_GRAPHICSWINDOW() USE_GRAPICSWINDOW_IMPLEMENTATION(Carbon)
289 #else
290  #define USE_GRAPHICSWINDOW() USE_GRAPICSWINDOW_IMPLEMENTATION(X11)
291 #endif
292 
293 }
294 
295 #endif
void setState(State *state)
virtual const char * libraryName() const
static void incrementContextIDUsageCount(unsigned int contextID)
virtual void grabFocusIfPointerInWindow()
virtual bool setWindowDecorationImplementation(bool)
virtual void setSwapGroup(bool on, GLuint group, GLuint barrier)
virtual void setSyncToVBlank(bool on)
virtual void setWindowName(const std::string &)
virtual bool realizeImplementation()
virtual const char * className() const
#define OSGVIEWER_EXPORT
Definition: Export.h:40
std::list< osgViewer::View * > Views
virtual void swapBuffersImplementation()
virtual bool makeCurrentImplementation()
void setGraphicsContext(osg::GraphicsContext *context)
Definition: EventQueue.h:72
virtual const char * libraryName() const
ref_ptr< Traits > _traits
osgGA::EventQueue * getEventQueue()
virtual bool isRealizedImplementation() const
GraphicsWindowFunctionProxy(CGraphicsWindowFunction function)
void(* CGraphicsWindowFunction)(void)
virtual void raiseWindow()
void setEventQueue(osgGA::EventQueue *eventQueue)
virtual void requestContinuousUpdate(bool=true)
virtual void requestWarpPointer(float, float)
virtual void setCursor(MouseCursor)
GLint GLenum GLsizei width
Definition: GLU.h:71
void setGraphicsContext(GraphicsContext *context)
Definition: State.h:124
osg::ref_ptr< osgGA::EventQueue > _eventQueue
void setWindowDecoration(bool flag)
typedef void(GL_APIENTRY *GLTexImage3DProc)(GLenum target
GraphicsWindowEmbedded(osg::GraphicsContext::Traits *traits=0)
Object()
Definition: Object.h:65
virtual std::string getWindowName()
static unsigned int createNewContextID()
virtual const char * className() const
virtual void useCursor(bool cursorOn)
void getSwapGroup(bool &on, GLuint &group, GLuint &barrier) const
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71
virtual bool checkEvents()
virtual void getWindowRectangle(int &x, int &y, int &width, int &height)
GraphicsWindowEmbedded(int x, int y, int width, int height)
void setWindowRectangle(int x, int y, int width, int height)
virtual bool getWindowDecoration() const
OSG_EXPORT std::ostream & notify(const NotifySeverity severity)
void setContextID(unsigned int contextID)
Definition: State.h:148
const osgGA::EventQueue * getEventQueue() const
virtual bool isRealizedImplementation() const
virtual void bindPBufferToTextureImplementation(GLenum)
virtual bool makeContextCurrentImplementation(GraphicsContext *)
virtual bool setWindowRectangleImplementation(int, int, int, int)
virtual bool valid() const
virtual bool releaseContextImplementation()
virtual void closeImplementation()
virtual bool isSameKindAs(const Object *object) const
virtual bool isSameKindAs(const Object *object) const