2006-12-20 00:47:15 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Note, elements of GraphicsWindowX11 have used Prodcer/RenderSurface_X11.cpp as both
|
|
|
|
* a guide to use of X11/GLX and copiying directly in the case of setBorder().
|
|
|
|
* These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns.
|
|
|
|
*/
|
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
#ifndef OSGVIEWER_GRAPHICSWINDOWX11
|
|
|
|
#define OSGVIEWER_GRAPHICSWINDOWX11 1
|
|
|
|
|
2006-12-21 20:24:20 +08:00
|
|
|
#include <osgViewer/GraphicsWindow>
|
2006-12-20 00:00:51 +08:00
|
|
|
|
|
|
|
#define GLX_GLXEXT_PROTOTYPES 1
|
2006-12-21 20:24:20 +08:00
|
|
|
|
|
|
|
#include <X11/X.h>
|
2006-12-20 00:00:51 +08:00
|
|
|
#include <GL/glx.h>
|
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
namespace osgViewer
|
|
|
|
{
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
class GraphicsWindowX11 : public osgViewer::GraphicsWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
GraphicsWindowX11(osg::GraphicsContext::Traits* traits):
|
2006-12-25 00:40:19 +08:00
|
|
|
_valid(false),
|
2006-12-20 00:00:51 +08:00
|
|
|
_display(0),
|
2007-02-09 21:51:28 +08:00
|
|
|
_eventDisplay(0),
|
2006-12-20 00:00:51 +08:00
|
|
|
_parent(0),
|
|
|
|
_window(0),
|
|
|
|
_visualInfo(0),
|
|
|
|
_glxContext(0),
|
|
|
|
_defaultCursor(0),
|
|
|
|
_nullCursor(0),
|
|
|
|
_currentCursor(0),
|
|
|
|
_initialized(false),
|
2007-01-05 21:01:08 +08:00
|
|
|
_realized(false),
|
|
|
|
_timeOfLastCheckEvents(-1.0)
|
2006-12-20 00:00:51 +08:00
|
|
|
{
|
|
|
|
_traits = traits;
|
|
|
|
|
2007-03-27 00:28:26 +08:00
|
|
|
init();
|
2006-12-25 00:40:19 +08:00
|
|
|
|
|
|
|
if (valid())
|
|
|
|
{
|
|
|
|
setState( new osg::State );
|
2007-02-15 01:28:33 +08:00
|
|
|
getState()->setGraphicsContext(this);
|
2007-02-15 04:14:45 +08:00
|
|
|
|
|
|
|
if (_traits.valid() && _traits->sharedContext)
|
|
|
|
{
|
|
|
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
|
|
|
incrementContextIDUsageCount( getState()->getContextID() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
getState()->setContextID( osg::GraphicsContext::createNewContextID() );
|
|
|
|
}
|
|
|
|
|
2006-12-25 00:40:19 +08:00
|
|
|
}
|
2006-12-20 00:00:51 +08:00
|
|
|
}
|
|
|
|
|
2006-12-25 00:40:19 +08:00
|
|
|
virtual bool valid() const { return _valid; }
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
/** Realise the GraphicsContext.*/
|
|
|
|
virtual bool realizeImplementation();
|
|
|
|
|
|
|
|
/** Return true if the graphics context has been realised and is ready to use.*/
|
|
|
|
virtual bool isRealizedImplementation() const { return _realized; }
|
|
|
|
|
|
|
|
/** Close the graphics context.*/
|
|
|
|
virtual void closeImplementation();
|
|
|
|
|
|
|
|
/** Make this graphics context current.*/
|
2007-01-09 03:29:59 +08:00
|
|
|
virtual bool makeCurrentImplementation();
|
|
|
|
|
|
|
|
/** Release the graphics context.*/
|
|
|
|
virtual bool releaseContextImplementation();
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
/** Swap the front and back buffers.*/
|
2006-12-20 00:00:51 +08:00
|
|
|
virtual void swapBuffersImplementation();
|
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
/** Check to see if any events have been generated.*/
|
|
|
|
virtual void checkEvents();
|
|
|
|
|
2006-12-21 19:20:42 +08:00
|
|
|
/** Set Window decoration.*/
|
|
|
|
virtual void setWindowDecoration(bool flag);
|
|
|
|
|
|
|
|
/** Get focus.*/
|
|
|
|
virtual void grabFocus();
|
|
|
|
|
|
|
|
/** Get focus on if the pointer is in this window.*/
|
|
|
|
virtual void grabFocusIfPointerInWindow();
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
// Override from GUIActionAdapter
|
|
|
|
virtual void requestWarpPointer(float x,float y);
|
|
|
|
|
2007-01-02 20:50:57 +08:00
|
|
|
/** Switch on/off the cursor.*/
|
|
|
|
virtual void useCursor(bool cursorOn);
|
|
|
|
|
2007-03-16 21:22:05 +08:00
|
|
|
/** WindowData is used to pass in the X11 window handle attached the GraphicsContext::Traits structure. */
|
|
|
|
struct WindowData : public osg::Referenced
|
|
|
|
{
|
|
|
|
WindowData(Window window):
|
|
|
|
_window(window) {}
|
|
|
|
|
|
|
|
Window _window;
|
|
|
|
};
|
|
|
|
|
2007-01-02 20:50:57 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
// X11 specific aces functions
|
|
|
|
|
|
|
|
Display* getDisplay() { return _display; }
|
2007-02-09 21:51:28 +08:00
|
|
|
Display* getEventDisplay() { return _eventDisplay; }
|
2007-01-02 20:50:57 +08:00
|
|
|
Window& getParent() { return _parent; }
|
|
|
|
Window& getWindow() { return _window; }
|
2007-02-15 20:24:04 +08:00
|
|
|
GLXContext& getGLXContext() { return _glxContext; }
|
2007-01-02 20:50:57 +08:00
|
|
|
|
|
|
|
Cursor& getDefaultCursor() { return _defaultCursor; }
|
|
|
|
Cursor& getNullCursor() { return _nullCursor; }
|
|
|
|
Cursor& getCurrentCursor() { return _nullCursor; }
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
protected:
|
|
|
|
|
2007-01-04 00:06:12 +08:00
|
|
|
~GraphicsWindowX11();
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
bool createVisualInfo();
|
2007-03-16 21:22:05 +08:00
|
|
|
|
2007-03-27 00:28:26 +08:00
|
|
|
void init();
|
2006-12-21 05:13:29 +08:00
|
|
|
|
|
|
|
void transformMouseXY(float& x, float& y);
|
|
|
|
void adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned int& modifierMask);
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2006-12-25 00:40:19 +08:00
|
|
|
bool _valid;
|
2006-12-20 00:00:51 +08:00
|
|
|
Display* _display;
|
2007-02-09 21:51:28 +08:00
|
|
|
Display* _eventDisplay;
|
2006-12-20 00:00:51 +08:00
|
|
|
Window _parent;
|
|
|
|
Window _window;
|
|
|
|
XVisualInfo* _visualInfo;
|
|
|
|
GLXContext _glxContext;
|
|
|
|
|
|
|
|
Cursor _defaultCursor;
|
|
|
|
Cursor _nullCursor;
|
|
|
|
Cursor _currentCursor;
|
2007-01-04 07:00:05 +08:00
|
|
|
|
|
|
|
Atom _deleteWindow;
|
2006-12-20 00:00:51 +08:00
|
|
|
|
|
|
|
bool _initialized;
|
|
|
|
bool _realized;
|
2007-01-05 21:01:08 +08:00
|
|
|
|
|
|
|
double _timeOfLastCheckEvents;
|
2006-12-20 00:00:51 +08:00
|
|
|
};
|
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|