Skip to content

Commit

Permalink
Fix the qt demo on windows. (#1955)
Browse files Browse the repository at this point in the history
  • Loading branch information
domchen authored Dec 5, 2023
1 parent 443d2d6 commit 70a919d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
58 changes: 34 additions & 24 deletions qt/src/PAGView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,29 @@ PAGView::~PAGView() {
delete pagPlayer;
}

void PAGView::onCreateDrawable(QOpenGLContext* context) {
if (drawable == nullptr) {
drawable = GPUDrawable::MakeFrom(this, context);
drawable->moveToThread(renderThread);
}
}

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))

void PAGView::geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) {
if (newGeometry == oldGeometry) {
return;
}
QQuickItem::geometryChange(newGeometry, oldGeometry);
onSizeChanged();
}

void PAGView::handleWindowChanged(QQuickWindow* window) {
if (drawable != nullptr || window == nullptr) {
return;
}
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
auto openglContext = reinterpret_cast<QOpenGLContext*>(window->rendererInterface()->getResource(
window, QSGRendererInterface::OpenGLContextResource));
#else
auto openglContext = window->openglContext();
#endif
if (openglContext != nullptr) {
onCreateDrawable(openglContext);
} else {
Expand All @@ -90,40 +103,37 @@ void PAGView::handleWindowChanged(QQuickWindow* window) {

void PAGView::handleOpenglContextCreated() {
disconnect(window(), SIGNAL(sceneGraphInitialized()), this, SLOT(handleOpenglContextCreated()));
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
auto openglContext = reinterpret_cast<QOpenGLContext*>(window()->rendererInterface()->getResource(
window(), QSGRendererInterface::OpenGLContextResource));
#else
auto openglContext = window()->openglContext();
#endif
onCreateDrawable(openglContext);
}

void PAGView::onCreateDrawable(QOpenGLContext* context) {
if (drawable == nullptr) {
drawable = GPUDrawable::MakeFrom(this, context);
drawable->moveToThread(renderThread);
}
}

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#else

void PAGView::geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) {
void PAGView::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
if (newGeometry == oldGeometry) {
return;
}
QQuickItem::geometryChange(newGeometry, oldGeometry);
QQuickItem::geometryChanged(newGeometry, oldGeometry);
onSizeChanged();
}

#else

void PAGView::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
if (newGeometry == oldGeometry) {
void PAGView::handleWindowChanged(QQuickWindow* window) {
if (drawable != nullptr || window == nullptr) {
return;
}
QQuickItem::geometryChanged(newGeometry, oldGeometry);
onSizeChanged();
if (window->openglContext() != nullptr) {
onCreateDrawable(window->openglContext());
} else {
connect(window, SIGNAL(openglContextCreated(QOpenGLContext*)), this,
SLOT(handleOpenglContextCreated(QOpenGLContext*)));
}
}

void PAGView::handleOpenglContextCreated(QOpenGLContext* context) {
disconnect(window(), SIGNAL(openglContextCreated(QOpenGLContext*)), this,
SLOT(handleOpenglContextCreated(QOpenGLContext*)));
onCreateDrawable(context);
}

#endif
Expand Down
5 changes: 5 additions & 0 deletions qt/src/PAGView.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ class PAGView : public QQuickItem {
Q_SLOT
void handleWindowChanged(QQuickWindow* window);

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
Q_SLOT
void handleOpenglContextCreated();
#else
Q_SLOT
void handleOpenglContextCreated(QOpenGLContext* context);
#endif

friend class RenderThread;
};
Expand Down
5 changes: 2 additions & 3 deletions qt/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
#include "qobject.h"

int main(int argc, char* argv[]) {
PAGViewer app(argc, argv);
QApplication::setApplicationName("PAGViewer");
QApplication::setOrganizationName("pag.art");
QApplication::setWindowIcon(QIcon(":/images/window-icon.png"));

QSurfaceFormat defaultFormat = QSurfaceFormat();
defaultFormat.setRenderableType(QSurfaceFormat::RenderableType::OpenGL);
defaultFormat.setVersion(3, 2);
Expand All @@ -45,6 +42,8 @@ int main(int argc, char* argv[]) {
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif

PAGViewer app(argc, argv);
QApplication::setWindowIcon(QIcon(":/images/window-icon.png"));
qmlRegisterType<pag::PAGView>("PAG", 1, 0, "PAGView");
auto rootPath = QApplication::applicationDirPath();
rootPath = QFileInfo(rootPath + "/../../").absolutePath();
Expand Down

0 comments on commit 70a919d

Please # to comment.