aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/scenegraph/openglunderqml
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quick/scenegraph/openglunderqml')
-rw-r--r--examples/quick/scenegraph/openglunderqml/CMakeLists.txt31
-rw-r--r--examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc2
-rw-r--r--examples/quick/scenegraph/openglunderqml/squircle.cpp30
-rw-r--r--examples/quick/scenegraph/openglunderqml/squircle.h2
4 files changed, 35 insertions, 30 deletions
diff --git a/examples/quick/scenegraph/openglunderqml/CMakeLists.txt b/examples/quick/scenegraph/openglunderqml/CMakeLists.txt
index cd64bb6172..8a95221811 100644
--- a/examples/quick/scenegraph/openglunderqml/CMakeLists.txt
+++ b/examples/quick/scenegraph/openglunderqml/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(openglunderqml LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quick/scenegraph/openglunderqml")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
qt_standard_project_setup()
@@ -26,10 +20,10 @@ set_target_properties(openglunderqml PROPERTIES
)
target_link_libraries(openglunderqml PRIVATE
- Qt::Core
- Qt::Gui
- Qt::Qml
- Qt::Quick
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Qml
+ Qt6::Quick
)
qt_add_qml_module(openglunderqml
@@ -40,7 +34,16 @@ qt_add_qml_module(openglunderqml
)
install(TARGETS openglunderqml
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET openglunderqml
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
index 317c824d06..aba95b471a 100644
--- a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
+++ b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
@@ -4,7 +4,9 @@
/*!
\example scenegraph/openglunderqml
\title Scene Graph - OpenGL Under QML
+ \examplecategory {Graphics}
\ingroup qtquickexamples
+ \examplecategory {Mobile}
\brief Shows how to render OpenGL under a Qt Quick scene.
\image openglunderqml-example.jpg
diff --git a/examples/quick/scenegraph/openglunderqml/squircle.cpp b/examples/quick/scenegraph/openglunderqml/squircle.cpp
index 13f3075a28..98a004ee80 100644
--- a/examples/quick/scenegraph/openglunderqml/squircle.cpp
+++ b/examples/quick/scenegraph/openglunderqml/squircle.cpp
@@ -94,6 +94,15 @@ void SquircleRenderer::init()
initializeOpenGLFunctions();
+ const float values[] = { -1, -1, 1, -1, -1, 1, 1, 1 };
+
+ m_vbo.create();
+ m_vbo.bind();
+ m_vbo.allocate(values, sizeof(values));
+
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), nullptr);
+
m_program = new QOpenGLShaderProgram();
m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex,
"attribute highp vec4 vertices;"
@@ -125,23 +134,12 @@ void SquircleRenderer::paint()
// OpenGL directly.
m_window->beginExternalCommands();
+ m_vbo.bind();
m_program->bind();
+ m_program->setUniformValue("t", (float)m_t);
- m_program->enableAttributeArray(0);
-
- float values[] = {
- -1, -1,
- 1, -1,
- -1, 1,
- 1, 1
- };
-
- // This example relies on (deprecated) client-side pointers for the vertex
- // input. Therefore, we have to make sure no vertex buffer is bound.
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- m_program->setAttributeArray(0, GL_FLOAT, values, 2);
- m_program->setUniformValue("t", (float) m_t);
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), nullptr);
glViewport(0, 0, m_viewportSize.width(), m_viewportSize.height());
@@ -152,7 +150,7 @@ void SquircleRenderer::paint()
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- m_program->disableAttributeArray(0);
+ glDisableVertexAttribArray(0);
m_program->release();
m_window->endExternalCommands();
diff --git a/examples/quick/scenegraph/openglunderqml/squircle.h b/examples/quick/scenegraph/openglunderqml/squircle.h
index 2112d658b0..e59e7882c8 100644
--- a/examples/quick/scenegraph/openglunderqml/squircle.h
+++ b/examples/quick/scenegraph/openglunderqml/squircle.h
@@ -8,6 +8,7 @@
#include <QtQuick/QQuickWindow>
#include <QOpenGLShaderProgram>
#include <QOpenGLFunctions>
+#include <QOpenGLBuffer>
@@ -31,6 +32,7 @@ private:
qreal m_t = 0.0;
QOpenGLShaderProgram *m_program = nullptr;
QQuickWindow *m_window = nullptr;
+ QOpenGLBuffer m_vbo;
};
//! [1]