| 1 | // Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QApplication> |
| 5 | #include <QtQml/QQmlContext> |
| 6 | #include <QtQuick/QQuickView> |
| 7 | #include <Qt3DRender/QAbstractTexture> |
| 8 | #include <QWindow> |
| 9 | #include <QTimer> |
| 10 | |
| 11 | #include <QQuickView> |
| 12 | #include "videoplayer.h" |
| 13 | |
| 14 | |
| 15 | template<typename Obj> |
| 16 | QHash<int, QString> enumToNameMap(const char *enumName) |
| 17 | { |
| 18 | const QMetaObject metaObj = Obj::staticMetaObject; |
| 19 | const int indexOfEnum = metaObj.indexOfEnumerator(enumName); |
| 20 | const QMetaEnum metaEnum = metaObj.enumerator(indexOfEnum); |
| 21 | const int keysCount = metaEnum.keyCount(); |
| 22 | |
| 23 | QHash<int, QString> v; |
| 24 | v.reserve(keysCount); |
| 25 | for (int i = 0; i < keysCount; ++i) |
| 26 | v[metaEnum.value(i)] = metaEnum.key(i); |
| 27 | return v; |
| 28 | } |
| 29 | |
| 30 | |
| 31 | class EnumNameMapper : public QObject |
| 32 | { |
| 33 | Q_OBJECT |
| 34 | |
| 35 | public: |
| 36 | Q_INVOKABLE QString statusName(int v) const { return m_statusMap.value(v); } |
| 37 | Q_INVOKABLE QString formatName(int v) const { return m_formatMap.value(v); } |
| 38 | Q_INVOKABLE QString targetName(int v) const { return m_targetMap.value(v); } |
| 39 | |
| 40 | private: |
| 41 | const QHash<int, QString> m_statusMap = enumToNameMap<Qt3DRender::QAbstractTexture>("Status"); |
| 42 | const QHash<int, QString> m_formatMap = enumToNameMap<Qt3DRender::QAbstractTexture>("TextureFormat"); |
| 43 | const QHash<int, QString> m_targetMap = enumToNameMap<Qt3DRender::QAbstractTexture>("Target"); |
| 44 | }; |
| 45 | |
| 46 | int main(int argc, char* argv[]) |
| 47 | { |
| 48 | QSurfaceFormat format = QSurfaceFormat::defaultFormat(); |
| 49 | format.setMajorVersion(4); |
| 50 | format.setMinorVersion(5); |
| 51 | format.setDepthBufferSize(16); |
| 52 | format.setStencilBufferSize(8); |
| 53 | format.setProfile(QSurfaceFormat::CoreProfile); |
| 54 | format.setRenderableType(QSurfaceFormat::OpenGL); |
| 55 | QSurfaceFormat::setDefaultFormat(format); |
| 56 | |
| 57 | |
| 58 | // Make the OpenGLWidget's shared context be qt_gl_global_share_context |
| 59 | QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); |
| 60 | QApplication app(argc, argv); |
| 61 | |
| 62 | // Multimedia player |
| 63 | TextureWidget textureWidget; |
| 64 | VideoPlayer *videoPlayer = new VideoPlayer(&textureWidget); |
| 65 | |
| 66 | textureWidget.resize(800, 600); |
| 67 | textureWidget.show(); |
| 68 | |
| 69 | // Qt3D QtQuick Scene (uses qt_global_share_context by default) |
| 70 | QQuickView view; |
| 71 | QQmlContext *ctx = view.rootContext(); |
| 72 | EnumNameMapper mapper; |
| 73 | ctx->setContextProperty(QStringLiteral("_nameMapper"), &mapper); |
| 74 | ctx->setContextProperty(QStringLiteral("_textureWidget"), &textureWidget); |
| 75 | |
| 76 | view.resize(800, 600); |
| 77 | view.setSource(QUrl("qrc:/main.qml")); |
| 78 | view.show(); |
| 79 | |
| 80 | return app.exec(); |
| 81 | } |
| 82 | |
| 83 | #include "main.moc" |