X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2FWindowSystemAdapter.hxx;h=b359f8e97f3ff2c4339b4c65ae8bca1f7b02a878;hb=e78c56af7dfb6d8258ada8a5f58e39d7be633dc2;hp=5fe8052781f853151a5e435e68cb2f2c99e5d706;hpb=580ebf637b991bbc5bb6b9632e8e62845d23ea43;p=flightgear.git diff --git a/src/Main/WindowSystemAdapter.hxx b/src/Main/WindowSystemAdapter.hxx index 5fe805278..b359f8e97 100644 --- a/src/Main/WindowSystemAdapter.hxx +++ b/src/Main/WindowSystemAdapter.hxx @@ -22,15 +22,20 @@ #include #include -#include #include +#include #include -// Flexible Camera and window support +namespace osg +{ +class GraphicsContext; +} + +// Flexible window support namespace flightgear { -/** A window opened by default or via rendering properties +/** A window with a graphics context and an integer ID */ class GraphicsWindow : public osg::Referenced { @@ -46,42 +51,23 @@ public: /** The window's internal name. */ std::string name; - enum Flags { - /** The GUI (and 2D cockpit) will be drawn on this window. - */ - GUI = 1 - }; + /** A unique ID for the window. + */ int id; - unsigned flags; -}; - -/** Camera associated with a 3d view. The camera might occupy an - * entire window or share one with other cameras. - */ -class Camera3D : public osg::Referenced -{ -public: - Camera3D(GraphicsWindow* window_, osg::Camera* camera_, const std::string& name_, - unsigned flags_ = 0) : - window(window_), camera(camera_), name(name_), flags(flags_) - { - } - osg::ref_ptr window; - osg::ref_ptr camera; - std::string name; enum Flags { - SHARES_WINDOW = 1, /**< Camera shares window with other cameras*/ - MASTER = 2 /**< Camera has same view as master camera*/ + GUI = 1 /**< The GUI (and 2D cockpit) will be drawn on this window. */ }; + /** Flags for the window. + */ unsigned flags; }; typedef std::vector > WindowVector; -typedef std::vector > Camera3DVector; /** * An operation that is run once with a particular GraphicsContext - * current. + * current. It will probably be deferred and may run in a different + * thread. */ class GraphicsContextOperation : public osg::GraphicsOperation { @@ -90,8 +76,15 @@ public: osg::GraphicsOperation(name, false) { } + /** Don't override this! + */ virtual void operator()(osg::GraphicsContext* gc); + /** The body of the operation. + */ virtual void run(osg::GraphicsContext* gc) = 0; + /** Test if the operation has completed. + * @return true if the run() method has finished. + */ bool isFinished() const { return done != 0; } private: SGAtomic done; @@ -99,7 +92,7 @@ private: /** Adapter from windows system / graphics context management API to * functions used by flightgear. This papers over the difference - * between osgViewer Viewer, which handles multiple windows, graphics + * between osgViewer::Viewer, which handles multiple windows, graphics * threads, etc., and the embedded viewer used with GLUT and SDL. */ class WindowSystemAdapter : public osg::Referenced @@ -107,37 +100,35 @@ class WindowSystemAdapter : public osg::Referenced public: WindowSystemAdapter(); virtual ~WindowSystemAdapter() {} + /** Vector of all the registered windows. + */ WindowVector windows; - Camera3DVector cameras; + /** Register a window, assigning it an ID. + * @param gc graphics context + * @param windowName internal name (not displayed) + * @return a graphics window + */ GraphicsWindow* registerWindow(osg::GraphicsContext* gc, const std::string& windowName); - Camera3D* registerCamera3D(GraphicsWindow* gw, osg::Camera* camera, - const std::string& cameraName); - GraphicsWindow* getGUIWindow(); - int getGUIWindowID(); - osg::GraphicsContext* getGUIGraphicsContext(); /** Initialize the plib pui interface library. This might happen *in another thread and may be deferred. */ - virtual bool puInitialize(); - /** Returns true if pui initialization has finished. + virtual void puInitialize(); + /** Find a window by name. + * @param name the window name + * @return the window or 0 + */ + GraphicsWindow* findWindow(const std::string& name); + /** Get the global WindowSystemAdapter + * @return the adapter */ - template - class FlagTester : public std::unary_function, bool> - { - public: - FlagTester(unsigned flags_) : flags(flags_) {} - bool operator() (const osg::ref_ptr& obj) - { - return (obj->flags & flags) != 0; - } - unsigned flags; - }; static WindowSystemAdapter* getWSA() { return _wsa.get(); } + /** Set the global adapter + * @param wsa the adapter + */ static void setWSA(WindowSystemAdapter* wsa) { _wsa = wsa; } protected: int _nextWindowID; - int _nextCameraID; osg::ref_ptr _puInitOp; bool _isPuInitialized; static osg::ref_ptr _wsa; @@ -146,5 +137,29 @@ protected: static void puGetWindowSize(int* width, int* height); }; + +/** + * Class for testing if flags are set in an object with a flags member. + */ +template +class FlagTester : public std::unary_function, bool> +{ +public: + /** Initialize with flags to test for. + * @param flags logical or of flags to test. + */ + FlagTester(unsigned flags_) : flags(flags_) {} + /** test operator + * @param obj An object with a flags member + * @return true if flags member of obj contains any of the flags + * (bitwise and with flags is nonzero). + */ + bool operator() (const osg::ref_ptr& obj) + { + return (obj->flags & flags) != 0; + } + unsigned flags; +}; + } #endif