DYTSrouce/src/viewer/GraphicsWindowEx.h
2025-01-16 00:13:05 +08:00

82 lines
2.4 KiB
C++

#ifndef GRAPHICSWINDOWEX_H
#define GRAPHICSWINDOWEX_H
#include <osgViewer/GraphicsWindow>
#include <QOffscreenSurface>
#include <QOpenGLContext>
#include <QOpenGLFramebufferObject>
/// 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(int x, int y, int width, int height);
~GraphicsWindowEx() override;
virtual bool isSameKindAs(const osg::Object* object) const
{
return dynamic_cast<const GraphicsWindowEx*>(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() const {
return frameBufferId_;
}
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 InitFrameBuffer();
private:
std::unique_ptr<QOffscreenSurface> offScreenSurface_{nullptr};
std::unique_ptr<QOpenGLContext> offScreenContext_{ nullptr };
std::unique_ptr<QOpenGLFramebufferObject> renderFramebuffer_{ nullptr };
std::unique_ptr<QOpenGLFramebufferObject> sharedFrameBuffer_{ nullptr };
bool isSharedContextSet_{ false };
bool isRealized_{ false };
bool isFrameBufferInitialized_{ false };
bool isRenderDonwn_{ false };
unsigned int frameBufferId_{ 0 };
float windowScale_{ 1.0f };
};
#endif // GRAPHICSWINDOWEX_H