#ifndef GRAPHICSWINDOWEX_H #define GRAPHICSWINDOWEX_H #include #include #include #include #include /// Needed for mixing osg rendering with Qt 2D drawing using QPainter... /// See http://forum.openscenegraph.org/viewtopic.php?t=15627&view=previous class GraphicsWindowEx : public osgViewer::GraphicsWindowEmbedded { public: GraphicsWindowEx(osg::GraphicsContext::Traits* traits); GraphicsWindowEx(int x, int y, int width, int height); ~GraphicsWindowEx() override; virtual bool isSameKindAs(const osg::Object* object) const { return dynamic_cast(object) != 0; } virtual const char* libraryName() const { return ""; } virtual const char* className() const { return "GraphicsWindowEx"; } // dummy implementations, assume that graphics context is *always* current and valid. virtual bool valid() const { return true; } bool isRealizedImplementation() const override { return isRealized_; } bool realizeImplementation() override; bool makeCurrentImplementation() override; void closeImplementation() override; bool releaseContextImplementation() override; void swapBuffersImplementation() override; bool SetSharedContext(QOpenGLContext* sharedContext); void UpdateWindowScale(float scale) { windowScale_ = scale; } unsigned int GetFrameBufferId() { isRenderDonwn_ = true; return frameBufferId_; } void ReizeWindow(int width, int height); public: void keyPressEvent(class QKeyEvent* event); void keyReleaseEvent(class QKeyEvent* event); void mousePressEvent(class QMouseEvent* event); void mouseReleaseEvent(class QMouseEvent* event); void mouseDoubleClickEvent(class QMouseEvent* event); void mouseMoveEvent(class QMouseEvent* event); void wheelEvent(class QWheelEvent* event); protected: void InitOffScreenContext(); void InitFrameBuffer(); private: std::unique_ptr offScreenSurface_{nullptr}; std::unique_ptr offScreenContext_{ nullptr }; std::unique_ptr renderFramebuffer_{ nullptr }; std::unique_ptr sharedFrameBuffer_{ nullptr }; QOpenGLContext* sharedContext_{ nullptr }; bool isSharedContextSet_{ false }; bool isRealized_{ false }; bool isFrameBufferInitialized_{ false }; bool isRenderDonwn_{ false }; unsigned int frameBufferId_{ 0 }; float windowScale_{ 1.0f }; }; #endif // GRAPHICSWINDOWEX_H