modify render

This commit is contained in:
jiegeaiai 2025-01-17 02:33:15 +08:00
parent c3bb7a8054
commit 32ed1bf037
14 changed files with 252 additions and 171 deletions

View File

@ -9,7 +9,7 @@ SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets LinguistTools REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools OpenGL REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui Widgets LinguistTools OpenGL REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets LinguistTools DataVisualization Charts Network REQUIRED)
message("qt VERSION " ${QT_VERSION_MAJOR})
@ -146,6 +146,7 @@ target_link_libraries(
${PROJECT_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Charts
Qt${QT_VERSION_MAJOR}::DataVisualization

View File

@ -6,10 +6,16 @@
#include "common/CrashHandler.h"
#include "ui/MainFrame.h"
#include "viewer/OSGEnv.h"
int main(int argc, char* argv[]) {
SpdLogger logger("logs/log.txt", 5);
if (!OSGEnv::init()) {
LOG_ERROR("OSGEnv::init() failed!");
return 1;
}
Application::setAttribute(Qt::AA_EnableHighDpiScaling);
Application app(argc, argv);
@ -24,6 +30,7 @@ int main(int argc, char* argv[]) {
mainWindow.showMaximized();
ret = app.exec();
OSGEnv::destroy();
return ret;
}
#else

View File

@ -479,153 +479,153 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="70"/>
<location filename="../ui/MainWindow.cpp" line="71"/>
<source>model elements</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="76"/>
<location filename="../ui/MainWindow.cpp" line="77"/>
<source>attribte</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="113"/>
<location filename="../ui/MainWindow.cpp" line="115"/>
<source>Wave Curve</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="121"/>
<location filename="../ui/MainWindow.cpp" line="123"/>
<source>Speed Curve</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="130"/>
<location filename="../ui/MainWindow.cpp" line="132"/>
<source>3D Curve</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="142"/>
<location filename="../ui/MainWindow.cpp" line="167"/>
<location filename="../ui/MainWindow.cpp" line="144"/>
<location filename="../ui/MainWindow.cpp" line="169"/>
<source>Target number</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="142"/>
<location filename="../ui/MainWindow.cpp" line="167"/>
<location filename="../ui/MainWindow.cpp" line="144"/>
<location filename="../ui/MainWindow.cpp" line="169"/>
<source>Signal-to-noise ratio</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="143"/>
<location filename="../ui/MainWindow.cpp" line="168"/>
<location filename="../ui/MainWindow.cpp" line="145"/>
<location filename="../ui/MainWindow.cpp" line="170"/>
<source>Azimuth line of sight</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="143"/>
<location filename="../ui/MainWindow.cpp" line="168"/>
<location filename="../ui/MainWindow.cpp" line="145"/>
<location filename="../ui/MainWindow.cpp" line="170"/>
<source>Pitch gaze angle</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="144"/>
<location filename="../ui/MainWindow.cpp" line="169"/>
<location filename="../ui/MainWindow.cpp" line="146"/>
<location filename="../ui/MainWindow.cpp" line="171"/>
<source>azimuth</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="144"/>
<location filename="../ui/MainWindow.cpp" line="169"/>
<location filename="../ui/MainWindow.cpp" line="146"/>
<location filename="../ui/MainWindow.cpp" line="171"/>
<source>Pitch angle</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="145"/>
<location filename="../ui/MainWindow.cpp" line="170"/>
<location filename="../ui/MainWindow.cpp" line="147"/>
<location filename="../ui/MainWindow.cpp" line="172"/>
<source>attribute</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="145"/>
<location filename="../ui/MainWindow.cpp" line="170"/>
<location filename="../ui/MainWindow.cpp" line="147"/>
<location filename="../ui/MainWindow.cpp" line="172"/>
<source>Doppler</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="146"/>
<location filename="../ui/MainWindow.cpp" line="171"/>
<location filename="../ui/MainWindow.cpp" line="148"/>
<location filename="../ui/MainWindow.cpp" line="173"/>
<source>course</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="146"/>
<location filename="../ui/MainWindow.cpp" line="171"/>
<location filename="../ui/MainWindow.cpp" line="148"/>
<location filename="../ui/MainWindow.cpp" line="173"/>
<source>Speed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="147"/>
<location filename="../ui/MainWindow.cpp" line="172"/>
<location filename="../ui/MainWindow.cpp" line="149"/>
<location filename="../ui/MainWindow.cpp" line="174"/>
<source>longitude</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="147"/>
<location filename="../ui/MainWindow.cpp" line="172"/>
<location filename="../ui/MainWindow.cpp" line="149"/>
<location filename="../ui/MainWindow.cpp" line="174"/>
<source>latitude</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="148"/>
<location filename="../ui/MainWindow.cpp" line="173"/>
<location filename="../ui/MainWindow.cpp" line="150"/>
<location filename="../ui/MainWindow.cpp" line="175"/>
<source>distance</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="148"/>
<location filename="../ui/MainWindow.cpp" line="173"/>
<location filename="../ui/MainWindow.cpp" line="150"/>
<location filename="../ui/MainWindow.cpp" line="175"/>
<source>velocity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="149"/>
<location filename="../ui/MainWindow.cpp" line="174"/>
<location filename="../ui/MainWindow.cpp" line="151"/>
<location filename="../ui/MainWindow.cpp" line="176"/>
<source>Radial dimensions</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="149"/>
<location filename="../ui/MainWindow.cpp" line="174"/>
<location filename="../ui/MainWindow.cpp" line="151"/>
<location filename="../ui/MainWindow.cpp" line="176"/>
<source>Target RCS</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="155"/>
<location filename="../ui/MainWindow.cpp" line="157"/>
<source>Report Table</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="180"/>
<location filename="../ui/MainWindow.cpp" line="182"/>
<source>Report</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="189"/>
<location filename="../ui/MainWindow.cpp" line="191"/>
<source>Signal Indicator Lamp</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="196"/>
<location filename="../ui/MainWindow.cpp" line="198"/>
<source>ParamSetting</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="201"/>
<location filename="../ui/MainWindow.cpp" line="203"/>
<source>Matlab File</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/MainWindow.cpp" line="206"/>
<location filename="../ui/MainWindow.cpp" line="208"/>
<source>name: 5year 0412</source>
<translation type="unfinished"></translation>
</message>

View File

@ -14,6 +14,7 @@
#include "DockWidget.h"
#include "viewer/ViewWidget.h"
#include "viewer/OsgOpenGLWindow.h"
#include "viewer/OsgViewer.h"
#include "chartPlot/FitCurveDialog.h"
@ -82,8 +83,9 @@ void MainWindow::InitUI() {
connect(modelBrowser_, &ModelBrowser::WorkSpaceChange, propertyBrowser_, &PropertyBrowser::OnWorkSpaceChange);
connect(modelBrowser_, &ModelBrowser::EntityChange, propertyBrowser_, &PropertyBrowser::OnEntityChange);
qtOsgViewWidget_ = new ViewWidget;
qtOsgViewWidget_->Initialize();
//qtOsgViewWidget_ = new ViewWidget;
qtOsgViewWidget_ = new OsgOpenGLWindow;
//qtOsgViewWidget_->Initialize();
m_mapDockWidget.insert("PropertyBrowser", attribte);
QString wavePath ="", speedPath = "", rdPath = "", matlabParam="";
@ -209,7 +211,7 @@ void MainWindow::InitUI() {
InitDockLayout();
//ui->viewWidget->layout()->addWidget(qtOsgViewWidget_);
qtOsgViewWidget_->LoadDefaultScene();
//qtOsgViewWidget_->LoadDefaultScene();
//OsgViewer::Get().Initialize();
//OsgViewer::Get().OnFrame();
@ -235,7 +237,8 @@ void MainWindow::InitDockLayout() {
tabWidget_->insertTab(i, mainWindow_, strTabName);
if (listDocArea[0].toList().size() > 0) {
mainWindow_->setCentralWidget(qtOsgViewWidget_);
//mainWindow_->setCentralWidget(qtOsgViewWidget_);
mainWindow_->setCentralWidget(qtOsgViewWidget_->AsWidget());
//OsgViewer::Get().Initialize();
//OsgViewer::Get().OnFrame();
} else {

View File

@ -21,9 +21,9 @@ public:
class ModelBrowser* GetModelBrowser() const {
return modelBrowser_;
}
class ViewWidget* GetViewWidget() const {
/*class ViewWidget* GetViewWidget() const {
return qtOsgViewWidget_;
}
}*/
class FitCurveDialog* GetFitCurveDlg() const {
return fitCurveDlg_;
@ -55,7 +55,8 @@ private:
class ModelBrowser* modelBrowser_{ nullptr };
class PropertyBrowser* propertyBrowser_{ nullptr };
class QWebEngineView* webEngineView_{ nullptr };
class ViewWidget* qtOsgViewWidget_{ nullptr };
//class ViewWidget* qtOsgViewWidget_{ nullptr };
class OsgOpenGLWindow* qtOsgViewWidget_{ nullptr };
class FitCurveDialog* fitCurveDlg_{ nullptr };
class FitCurveDialog* fitYLgCurveDlg_{ nullptr };

View File

@ -2,6 +2,7 @@
#include <QOpenGLFrameBufferObjectFormat>
#include <QOpenGLFunctions>
#include <QThread>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QWheelEvent>
@ -107,28 +108,13 @@ namespace {
GraphicsWindowEx::GraphicsWindowEx(int x, int y, int width, int height)
: osgViewer::GraphicsWindowEmbedded(x, y, width, height)
, offScreenSurface_(new QOffscreenSurface)
, offScreenContext_(new QOpenGLContext)
{
: osgViewer::GraphicsWindowEmbedded(x, y, width == 0 ? 1 : width, height == 0 ? 1 : height) {
LOG_INFO("actor, self={}", spdlog::fmt_lib::ptr(this));
}
GraphicsWindowEx::~GraphicsWindowEx() {
LOG_INFO("dctor isSharedContextSet_:{}, self={}", isSharedContextSet_, spdlog::fmt_lib::ptr(this));
if (!isSharedContextSet_) {
return;
}
if (isFrameBufferInitialized_) {
offScreenContext_->makeCurrent(offScreenSurface_.get());
renderFramebuffer_.reset();
sharedFrameBuffer_.reset();
offScreenContext_->doneCurrent();
}
offScreenContext_.reset();
offScreenSurface_.reset();
}
bool GraphicsWindowEx::realizeImplementation() {
@ -152,17 +138,39 @@ bool GraphicsWindowEx::realizeImplementation() {
bool GraphicsWindowEx::makeCurrentImplementation() {
LOG_INFO("makeCurrentImplementation, isRealized_:{}, self={}", isRealized_, spdlog::fmt_lib::ptr(this));
dyt_check(nullptr != offScreenContext_);
InitOffScreenContext();
if (nullptr != offScreenContext_) {
offScreenContext_->makeCurrent(offScreenSurface_.get());
}
InitFrameBuffer();
setDefaultFboId(renderFramebuffer_->handle());
renderFramebuffer_->bind();
return true;
}
void GraphicsWindowEx::closeImplementation() {
if (!isSharedContextSet_) {
return;
}
if (isFrameBufferInitialized_) {
offScreenContext_->makeCurrent(offScreenSurface_.get());
renderFramebuffer_.reset();
sharedFrameBuffer_.reset();
offScreenContext_->doneCurrent();
}
offScreenContext_.reset();
offScreenSurface_.reset();
}
bool GraphicsWindowEx::releaseContextImplementation() {
LOG_INFO("releaseContextImplementation, self={}", spdlog::fmt_lib::ptr(this));
QOpenGLFramebufferObject::bindDefault();
offScreenContext_->doneCurrent();
return true;
}
@ -178,23 +186,18 @@ void GraphicsWindowEx::swapBuffersImplementation() {
}
bool GraphicsWindowEx::SetSharedContext(QOpenGLContext* sharedContext) {
LOG_INFO("Set shared context, {}", isSharedContextSet_);
if (isSharedContextSet_) {
sharedContext_ = sharedContext;
return true;
}
void GraphicsWindowEx::ReizeWindow(int width, int height) {
if (width == _traits->width && height == _traits->height) {
return;
}
offScreenContext_->setFormat(sharedContext->format());
offScreenContext_->setShareContext(sharedContext);
isSharedContextSet_ = offScreenContext_->create();
if (!isSharedContextSet_) {
LOG_ERROR("Failed to create offscreen context");
return false;
}
offScreenSurface_->setFormat(offScreenContext_->format());
offScreenSurface_->create();
return true;
getEventQueue()->windowResize(0, 0, width, height);
resized(0, 0, width, height);
isFrameBufferInitialized_ = false;
}
void GraphicsWindowEx::keyPressEvent(QKeyEvent* event) {
@ -321,6 +324,36 @@ void GraphicsWindowEx::wheelEvent(QWheelEvent* event) {
osgGA::GUIEventAdapter::SCROLL_RIGHT));
}
void GraphicsWindowEx::InitOffScreenContext() {
if (isSharedContextSet_) {
return;
}
if (!offScreenSurface_) {
offScreenSurface_.reset(new QOffscreenSurface);
}
if (!offScreenContext_) {
offScreenContext_.reset(new QOpenGLContext);
}
LOG_INFO("Set shared context");
dyt_check(nullptr != sharedContext_);
offScreenContext_->setFormat(sharedContext_->format());
offScreenContext_->setShareContext(sharedContext_);
isSharedContextSet_ = offScreenContext_->create();
if (!isSharedContextSet_) {
LOG_ERROR("Failed to create offscreen context");
return;
}
offScreenSurface_->setFormat(offScreenContext_->format());
offScreenSurface_->create();
}
void GraphicsWindowEx::InitFrameBuffer() {
if (isFrameBufferInitialized_) {
return;
@ -335,4 +368,3 @@ void GraphicsWindowEx::InitFrameBuffer() {
isFrameBufferInitialized_ = true;
}

View File

@ -1,6 +1,7 @@
#ifndef GRAPHICSWINDOWEX_H
#define GRAPHICSWINDOWEX_H
#include <QObject>
#include <osgViewer/GraphicsWindow>
#include <QOffscreenSurface>
@ -38,7 +39,7 @@ public:
}
bool realizeImplementation() override;
bool makeCurrentImplementation() override;
void closeImplementation() override {}
void closeImplementation() override;
bool releaseContextImplementation() override;
void swapBuffersImplementation() override;
@ -46,10 +47,13 @@ public:
void UpdateWindowScale(float scale) {
windowScale_ = scale;
}
unsigned int GetFrameBufferId() const {
unsigned int GetFrameBufferId() {
isRenderDonwn_ = true;
return frameBufferId_;
}
void ReizeWindow(int width, int height);
public:
void keyPressEvent(class QKeyEvent* event);
void keyReleaseEvent(class QKeyEvent* event);
@ -60,6 +64,7 @@ public:
void wheelEvent(class QWheelEvent* event);
protected:
void InitOffScreenContext();
void InitFrameBuffer();
private:
@ -68,6 +73,8 @@ private:
std::unique_ptr<QOpenGLFramebufferObject> renderFramebuffer_{ nullptr };
std::unique_ptr<QOpenGLFramebufferObject> sharedFrameBuffer_{ nullptr };
QOpenGLContext* sharedContext_{ nullptr };
bool isSharedContextSet_{ false };
bool isRealized_{ false };
bool isFrameBufferInitialized_{ false };

56
src/viewer/OSGEnv.cpp Normal file
View File

@ -0,0 +1,56 @@
#include "viewer/OSGEnv.h"
#include <QSurfaceFormat>
#include <osgDB/Registry>
#include <osgEarth/Capabilities>
#include <osgEarth/Registry>
bool s_gBChecked = false;
bool OSGEnv::init() {
osgEarth::initialize();
const osgEarth::Capabilities& csCapabilities = osgEarth::Registry::instance()->getCapabilities();
s_gBChecked = csCapabilities.supportsGLSL();
if (!s_gBChecked) {
return(s_gBChecked);
}
int nMax, nMin;
sscanf(csCapabilities.getVersion().data(), "%d.%d", &nMax, &nMin);
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
osg::GraphicsContext::Traits traits(osg::DisplaySettings::instance().get());
int nHttpThreads = osg::DisplaySettings::instance()->getNumOfDatabaseThreadsHint();
nHttpThreads = nHttpThreads < 1 ? 1 : nHttpThreads;
osg::DisplaySettings::instance()->setNumOfHttpDatabaseThreadsHint(nHttpThreads);
format.setAlphaBufferSize(traits.alpha);
format.setRedBufferSize(traits.red);
format.setGreenBufferSize(traits.green);
format.setBlueBufferSize(traits.blue);
format.setDepthBufferSize(traits.depth);
format.setStencilBufferSize(traits.stencil);
format.setSamples(traits.samples);
format.setVersion(nMax, nMin);
/// ÅжÏÊÇ·ñÖ§³ÖºËÐÄģʽ
if (csCapabilities.isCoreProfile()) {
format.setProfile(QSurfaceFormat::CoreProfile);
} else {
format.setProfile(QSurfaceFormat::CompatibilityProfile);
}
format.setSwapInterval(traits.vsync ? 1 : 0);
format.setStereo(traits.quadBufferStereo ? 1 : 0);
QSurfaceFormat::setDefaultFormat(format);
osgDB::Registry::instance()->getObjectWrapperManager()->findWrapper("osg::Image");
return true;
}
void OSGEnv::destroy() {
}

7
src/viewer/OSGEnv.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
class OSGEnv {
public:
static bool init();
static void destroy();
};

View File

@ -59,23 +59,20 @@ void OSGRenderer::Init(osg::GraphicsContext* gc) {
getCamera()->setGraphicsContext(gc);
getCamera()->setViewport(new osg::Viewport(0, 0, gc->getTraits()->width, gc->getTraits()->height));
getCamera()->setDrawBuffer(GL_BACK);
getCamera()->setReadBuffer(GL_BACK);
getCamera()->setProjectionMatrixAsPerspective(45, 1.0, 0.01, 100.);
isInited_ = true;
}
void OSGRenderer::Resize(osg::GraphicsContext* gc, int width, int height) {
void OSGRenderer::Resize(GraphicsWindowEx* gc, int width, int height) {
LOG_INFO("OSGRenderer::Resize {}, gc:{}", isInited_, spdlog::fmt_lib::ptr(gc));
if (!gc) {
dyt_check(nullptr != gc);
if (!isInited_) {
return;
}
if (isInited_) {
return;
}
osgViewer::GraphicsWindow* window = dynamic_cast<osgViewer::GraphicsWindow*>(gc);
dyt_check(nullptr != window);
window->getEventQueue()->windowResize(0, 0, width, height);
window->resized(0, 0, width, height);
gc->ReizeWindow(width, height);
}
void OSGRenderer::Render() {

View File

@ -22,6 +22,8 @@
#include <osgViewer/Viewer>
#include "GraphicsWindowEx.h"
namespace {
enum RenderEvent {
INIT = QEvent::Type(QEvent::User + 1),
@ -39,13 +41,13 @@ namespace {
};
struct GraphicsWindowResizeEvent : public QEvent {
GraphicsWindowResizeEvent(osg::GraphicsContext* gc, int width, int height)
GraphicsWindowResizeEvent(GraphicsWindowEx* gc, int width, int height)
: QEvent(QEvent::Type(RESIZE))
, gc_(gc)
, width_(width)
, height_(height) {}
osg::observer_ptr<osg::GraphicsContext> gc_;
osg::observer_ptr<GraphicsWindowEx> gc_;
int width_;
int height_;
};
@ -67,7 +69,7 @@ Q_SIGNALS:
private:
void Init(osg::GraphicsContext* gc);
void Resize(osg::GraphicsContext* gc, int width, int height);
void Resize(GraphicsWindowEx* gc, int width, int height);
void Render();
void Destoy();

View File

@ -47,38 +47,33 @@ static const char* fragmentShaderSource =
OsgOpenGLWindow::OsgOpenGLWindow(QWidget* parent)
: QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, nullptr)
{
: QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, nullptr) {
widget_ = QWidget::createWindowContainer(this);
gw_ = new GraphicsWindowEx(0, 0, width(), height());
renderer_ = new OSGRenderer(this);
connect(renderer_, &OSGRenderer::RenderFlush, this, &OsgOpenGLWindow::OnRenderFlush);
connect(renderer_, &OSGRenderer::RenderFlush, this, &OsgOpenGLWindow::OnRenderFlush, Qt::QueuedConnection);
connect(&timer_, &QTimer::timeout, this, &OsgOpenGLWindow::OnRender);
}
OsgOpenGLWindow::~OsgOpenGLWindow()
{
OsgOpenGLWindow::~OsgOpenGLWindow() {}
osgViewer::Viewer* OsgOpenGLWindow::getOsgViewer() {
return renderer_;
}
osgViewer::Viewer* OsgOpenGLWindow::getOsgViewer()
{
return m_renderer;
}
OpenThreads::ReadWriteMutex* OsgOpenGLWindow::mutex()
{
return &_osgMutex;
}
void OsgOpenGLWindow::initializeGL()
{
void OsgOpenGLWindow::initializeGL() {
//// Initializes OpenGL function resolution for the current context.
//initializeOpenGLFunctions();
//createRenderer();
//emit initialized();
context()->doneCurrent();
QOpenGLContext* ctx = context();
dyt_check(nullptr != ctx);
ctx->doneCurrent();
gw_->SetSharedContext(context());
QApplication::postEvent(renderer_, new RenderBindGraphicsContextEvent(gw_));
setDefaultDisplaySettings();
double pixelRatio = screen()->devicePixelRatio();
gw_->UpdateWindowScale(pixelRatio);
QApplication::postEvent(renderer_, new GraphicsWindowResizeEvent(gw_, width() * pixelRatio, height() * pixelRatio));
@ -90,28 +85,28 @@ void OsgOpenGLWindow::initializeGL()
shaderProgram_ = new QOpenGLShaderProgram(this);
vao_ = new QOpenGLVertexArrayObject(this);
if (!vao_->create()) {
LOG_ERROR( "Failed to create VAO");
LOG_ERROR("Failed to create VAO");
return;
}
if (!shaderProgram_->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource)) {
LOG_ERROR( "Failed to add vertex shader");
LOG_ERROR("Failed to add vertex shader");
return;
}
if (!shaderProgram_->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource)) {
LOG_ERROR( "Failed to add fragment shader");
LOG_ERROR("Failed to add fragment shader");
return;
}
if (!shaderProgram_->link()) {
LOG_ERROR( "Failed to link shader program, {}", shaderProgram_->log().toLocal8Bit().constData());
LOG_ERROR("Failed to link shader program, {}", shaderProgram_->log().toLocal8Bit().constData());
return;
}
timer_.start(1000 / 60);
}
void OsgOpenGLWindow::resizeGL(int w, int h)
{
Q_ASSERT(m_renderer);
void OsgOpenGLWindow::resizeGL(int w, int h) {
double pixelRatio = screen()->devicePixelRatio();
gw_->UpdateWindowScale(pixelRatio);
QApplication::postEvent(renderer_, new GraphicsWindowResizeEvent(gw_, w * pixelRatio, h * pixelRatio));
@ -137,73 +132,59 @@ void OsgOpenGLWindow::paintUnderGL() {
}
}
void OsgOpenGLWindow::keyPressEvent(QKeyEvent* event)
{
void OsgOpenGLWindow::keyPressEvent(QKeyEvent* event) {
Q_ASSERT(gw_);
// forward event to renderer
gw_->keyPressEvent(event);
}
void OsgOpenGLWindow::keyReleaseEvent(QKeyEvent* event)
{
void OsgOpenGLWindow::keyReleaseEvent(QKeyEvent* event) {
Q_ASSERT(gw_);
// forward event to renderer
gw_->keyReleaseEvent(event);
}
void OsgOpenGLWindow::mousePressEvent(QMouseEvent* event)
{
void OsgOpenGLWindow::mousePressEvent(QMouseEvent* event) {
Q_ASSERT(gw_);
// forward event to renderer
gw_->mousePressEvent(event);
}
void OsgOpenGLWindow::mouseReleaseEvent(QMouseEvent* event)
{
void OsgOpenGLWindow::mouseReleaseEvent(QMouseEvent* event) {
Q_ASSERT(gw_);
// forward event to renderer
gw_->mouseReleaseEvent(event);
}
void OsgOpenGLWindow::mouseDoubleClickEvent(QMouseEvent* event)
{
void OsgOpenGLWindow::mouseDoubleClickEvent(QMouseEvent* event) {
Q_ASSERT(gw_);
// forward event to renderer
gw_->mouseDoubleClickEvent(event);
}
void OsgOpenGLWindow::mouseMoveEvent(QMouseEvent* event)
{
void OsgOpenGLWindow::mouseMoveEvent(QMouseEvent* event) {
Q_ASSERT(gw_);
// forward event to renderer
gw_->mouseMoveEvent(event);
}
void OsgOpenGLWindow::wheelEvent(QWheelEvent* event)
{
void OsgOpenGLWindow::wheelEvent(QWheelEvent* event) {
Q_ASSERT(gw_);
// forward event to renderer
gw_->wheelEvent(event);
}
void OsgOpenGLWindow::setDefaultDisplaySettings()
{
void OsgOpenGLWindow::setDefaultDisplaySettings() {
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
ds->setNvOptimusEnablement(1);
ds->setStereo(false);
}
void OsgOpenGLWindow::createRenderer()
{
// call this before creating a View...
setDefaultDisplaySettings();
/*m_renderer = new OSGRenderer(this);
double pixelRatio = screen()->devicePixelRatio();
m_renderer->setupOSG(width(), height(), pixelRatio);*/
}
void OsgOpenGLWindow::OnRenderFlush() {
shaderTextureId_ = gw_->GetFrameBufferId();
updateTexture_ = true;
}
void OsgOpenGLWindow::OnRender() {
requestUpdate();
}

View File

@ -17,7 +17,7 @@
#include <QOpenGLWindow>
#include <QOpenGLFunctions>
#include <QReadWriteLock>
#include <QTimer>
#include <osg/ref_ptr>
@ -32,15 +32,6 @@ namespace osgViewer
class OsgOpenGLWindow : public QOpenGLWindow {
Q_OBJECT
protected:
OSGRenderer* m_renderer {nullptr};
bool _osgWantsToRenderFrame{true};
OpenThreads::ReadWriteMutex _osgMutex;
bool _isFirstFrame {true};
friend class OSGRenderer;
public:
OsgOpenGLWindow(QWidget* parent = nullptr);
~OsgOpenGLWindow() override;
@ -48,8 +39,6 @@ public:
/** Get osgViewer View */
virtual osgViewer::Viewer* getOsgViewer();
//! get mutex
virtual OpenThreads::ReadWriteMutex* mutex();
QWidget* AsWidget()
{
@ -65,8 +54,7 @@ protected:
void resizeGL(int w, int h) override;
void paintUnderGL() override;
//! called before creating renderer
virtual void setDefaultDisplaySettings();
void setDefaultDisplaySettings();
void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
@ -76,10 +64,9 @@ protected:
void mouseMoveEvent(QMouseEvent* event) override;
void wheelEvent(QWheelEvent* event) override;
void createRenderer();
private:
void OnRenderFlush();
void OnRender();
private:
QWidget* widget_{ nullptr };
@ -89,6 +76,7 @@ private:
class QOpenGLVertexArrayObject* vao_{ nullptr };
uint32_t shaderTextureId_{ 0 };
bool updateTexture_{ false };
QTimer timer_;
};
#endif // OSGQOPENGLWINDOW_H

View File

@ -4,7 +4,6 @@
#include <QWidget>
#include "scene/OEScene.h"
#include "viewer/OsgViewWidget.h"
#include "viewer/GraphicsWindowEx.h"