diff --git a/tests/auto/qmltest/canvas3d/tst_render_dynamic.qml b/tests/auto/qmltest/canvas3d/tst_render_dynamic.qml new file mode 100644 index 0000000000000000000000000000000000000000..5fcd71fcea8a5dd557ffa45c3c926d73687ab05e --- /dev/null +++ b/tests/auto/qmltest/canvas3d/tst_render_dynamic.qml @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtCanvas3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtCanvas3D 1.0 +import QtTest 1.0 + +import "tst_render_simple.js" as Content + +Item { + id: top + height: 300 + width: 300 + + property var canvas3d: null + property var activeContent: Content + property bool initOk: false + property bool renderOk: false + + function createCanvas() { + canvas3d = Qt.createQmlObject(" + import QtQuick 2.2 + import QtCanvas3D 1.0 + Canvas3D { + onInitGL: initOk = activeContent.initGL(canvas3d) + onRenderGL: { + renderOk = true + activeContent.renderGL(canvas3d) + } + }", top) + canvas3d.anchors.fill = top + } + + TestCase { + name: "Canvas3D_render_dynamic" + when: windowShown + + function test_render_1_dynamic_creation() { + verify(canvas3d === null) + verify(initOk === false) + verify(renderOk === false) + createCanvas() + verify(canvas3d !== null) + waitForRendering(canvas3d) + tryCompare(top, "initOk", true) + tryCompare(top, "renderOk", true) + } + + function test_render_2_dynamic_deletion() { + verify(canvas3d !== null) + verify(initOk === true) + verify(renderOk === true) + canvas3d.destroy() + waitForRendering(canvas3d) + verify(canvas3d === null) + } + + function test_render_3_dynamic_recreation() { + initOk = false + renderOk = false + createCanvas() + tryCompare(top, "initOk", true) + tryCompare(top, "renderOk", true) + waitForRendering(canvas3d) + verify(canvas3d !== null) + + canvas3d.destroy() + waitForRendering(canvas3d) + verify(canvas3d === null) + + initOk = false + renderOk = false + createCanvas() + waitForRendering(canvas3d) + verify(canvas3d !== null) + tryCompare(top, "initOk", true) + tryCompare(top, "renderOk", true) + } + } +} diff --git a/tests/auto/qmltest/canvas3d/tst_render_simple.js b/tests/auto/qmltest/canvas3d/tst_render_simple.js index f5c152dea7f31c3c8aae3f9865317fcd02999146..a416e546192001e57c5cc4ab47ce92c9f4fbd3a0 100644 --- a/tests/auto/qmltest/canvas3d/tst_render_simple.js +++ b/tests/auto/qmltest/canvas3d/tst_render_simple.js @@ -42,6 +42,7 @@ var vertexShader; var fragmentShader; function initGL(canvas) { + var initOk = true try { gl = canvas.getContext("3d"); buffer = gl.createBuffer(); @@ -55,25 +56,27 @@ function initGL(canvas) { gl.STATIC_DRAW); if (!initShaders()) { - return; - } - - gl.useProgram(shaderProgram); + initOk = false; + } else { + gl.useProgram(shaderProgram); - positionLocation = gl.getAttribLocation(shaderProgram, "a_position"); - gl.enableVertexAttribArray(positionLocation); - gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0); + positionLocation = gl.getAttribLocation(shaderProgram, "a_position"); + gl.enableVertexAttribArray(positionLocation); + gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0); - gl.clearColor(0.0, 0.0, 0.0, 1.0); + gl.clearColor(0.0, 0.0, 0.0, 1.0); - gl.viewport(0, 0, - canvas.width * canvas.devicePixelRatio, - canvas.height * canvas.devicePixelRatio); + gl.viewport(0, 0, + canvas.width * canvas.devicePixelRatio, + canvas.height * canvas.devicePixelRatio); + } } catch(e) { console.log("initGL(): FAILURE!"); console.log(""+e); console.log(""+e.message); + initOk = false; } + return initOk; } function renderGL(canvas) { diff --git a/tests/auto/qmltest/canvas3d/tst_render_simple.qml b/tests/auto/qmltest/canvas3d/tst_render_simple.qml index 34090d1209a897285ce4c5ddfcb74758ad451ff7..7820ad03999e4f7523627bcd04414e28e205d702 100644 --- a/tests/auto/qmltest/canvas3d/tst_render_simple.qml +++ b/tests/auto/qmltest/canvas3d/tst_render_simple.qml @@ -49,12 +49,13 @@ Item { id: render_simple property bool heightChanged: false property bool widthChanged: false - property bool renderingOk: false + property bool initOk: false + property bool renderOk: false anchors.fill: parent - onInitGL: Content.initGL(render_simple) + onInitGL: initOk = Content.initGL(render_simple) onRenderGL: { Content.renderGL(render_simple) - renderingOk = true + renderOk = true } onHeightChanged: heightChanged = true onWidthChanged: widthChanged = true @@ -66,25 +67,26 @@ Item { function test_render_1_simple() { waitForRendering(render_simple) - verify(render_simple.renderingOk === true) + tryCompare(render_simple, "initOk", true) + tryCompare(render_simple, "renderOk", true) } function test_render_2_resize() { render_simple.heightChanged = false render_simple.widthChanged = false - render_simple.renderingOk = false + render_simple.renderOk = false top.height = 200 waitForRendering(render_simple) verify(render_simple.heightChanged === true) verify(render_simple.widthChanged === false) - verify(render_simple.renderingOk === true) + tryCompare(render_simple, "renderOk", true) - render_simple.renderingOk = false + render_simple.renderOk = false top.width = 200 waitForRendering(render_simple) verify(render_simple.heightChanged === true) verify(render_simple.widthChanged === true) - verify(render_simple.renderingOk === true) + tryCompare(render_simple, "renderOk", true) } } }