Commit cc4f79a7 authored by Tomi Korpipää's avatar Tomi Korpipää
Browse files

Added dynamic canvas creation autotest.


Change-Id: I83080e48f6c985d187ead9f42ef61e22e37a05a8
Reviewed-by: default avatarMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>
Showing with 137 additions and 19 deletions
/****************************************************************************
**
** 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)
}
}
}
......@@ -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) {
......
......@@ -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)
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment