diff --git a/3rdparty/js-test-pre.js b/3rdparty/js-test-pre.js deleted file mode 100644 index 2127176d47510203774f3bcddb44e0bc6907db1b..0000000000000000000000000000000000000000 --- a/3rdparty/js-test-pre.js +++ /dev/null @@ -1,271 +0,0 @@ -/* -** Copyright (c) 2012 The Khronos Group Inc. -** -** Permission is hereby granted, free of charge, to any person obtaining a -** copy of this software and/or associated documentation files (the -** "Materials"), to deal in the Materials without restriction, including -** without limitation the rights to use, copy, modify, merge, publish, -** distribute, sublicense, and/or sell copies of the Materials, and to -** permit persons to whom the Materials are furnished to do so, subject to -** the following conditions: -** -** The above copyright notice and this permission notice shall be included -** in all copies or substantial portions of the Materials. -** -** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. -*/ - -function areArraysEqual(_a, _b) -{ - try { - if (_a.length !== _b.length) - return false; - for (var i = 0; i < _a.length; i++) - if (_a[i] !== _b[i]) - return false; - } catch (ex) { - return false; - } - return true; -} -function isMinusZero(n) -{ - // the only way to tell 0 from -0 in JS is the fact that 1/-0 is - // -Infinity instead of Infinity - return n === 0 && 1/n < 0; -} -function isResultCorrect(_actual, _expected) -{ - if (_expected === 0) - return _actual === _expected && (1/_actual) === (1/_expected); - if (_actual === _expected) - return true; - if (typeof(_expected) == "number" && isNaN(_expected)) - return typeof(_actual) == "number" && isNaN(_actual); - if (Object.prototype.toString.call(_expected) == Object.prototype.toString.call([])) - return areArraysEqual(_actual, _expected); - return false; -} -function stringify(v) -{ - if (v === 0 && 1/v < 0) - return "-0"; - else return "" + v; -} -function evalAndLog(_a) -{ - if (typeof _a != "string") - debug("WARN: tryAndLog() expects a string argument"); - // Log first in case things go horribly wrong or this causes a sync event. - debug(_a); - var _av; - try { - _av = eval(_a); - } catch (e) { - return false;//testFailed(_a + " threw exception " + e); - } - return _av; -} -function shouldBe(_a, _b) -{ - if (typeof _a != "string" || typeof _b != "string") - debug("WARN: shouldBe() expects string arguments"); - var exception; - var _av; - try { - _av = eval(_a); - } catch (e) { - exception = e; - } - var _bv = eval(_b); - if (exception) { - console.log(_a + " should be " + _bv + ". Threw exception " + exception); - return false;//testFailed(_a + " should be " + _bv + ". Threw exception " + exception); - } else if (isResultCorrect(_av, _bv)) { - return true;//testPassed(_a + " is " + _b); - } else if (typeof(_av) == typeof(_bv)) { - console.log(_a + " should be " + _bv + ". Was " + stringify(_av) + "."); - return false;//testFailed(_a + " should be " + _bv + ". Was " + stringify(_av) + "."); - } else { - console.log(_a + " should be " + _bv + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ")."); - return false;//testFailed(_a + " should be " + _bv + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ")."); - } -} -function shouldBeTrue(_a) { return shouldBe(_a, "true"); } -function shouldBeFalse(_a) { return shouldBe(_a, "false"); } -function shouldBeNaN(_a) { return shouldBe(_a, "NaN"); } -function shouldBeNull(_a) { return shouldBe(_a, "null"); } -function shouldBeEqualToString(a, b) -{ - var unevaledString = '"' + b.replace(/"/g, "\"") + '"'; - return shouldBe(a, unevaledString); -} -function shouldEvaluateTo(actual, expected) { - // A general-purpose comparator. 'actual' should be a string to be - // evaluated, as for shouldBe(). 'expected' may be any type and will be - // used without being eval'ed. - var retval = true; - if (expected == null) { - // Do this before the object test, since null is of type 'object'. - retval = shouldBeNull(actual); - if (!retval) return false; - } else if (typeof expected == "undefined") { - retval = shouldBeUndefined(actual); - if (!retval) return false; - } else if (typeof expected == "function") { - // All this fuss is to avoid the string-arg warning from shouldBe(). - try { - actualValue = eval(actual); - } catch (e) { - return false;//testFailed("Evaluating " + actual + ": Threw exception " + e); - } - retval = shouldBe("'" + actualValue.toString().replace(/\n/g, "") + "'", - "'" + expected.toString().replace(/\n/g, "") + "'"); - if (!retval) return false; - } else if (typeof expected == "object") { - retval = shouldBeTrue(actual + " == '" + expected + "'"); - if (!retval) return false; - } else if (typeof expected == "string") { - retval = shouldBe(actual, expected); - if (!retval) return false; - } else if (typeof expected == "boolean") { - retval = shouldBe("typeof " + actual, "'boolean'"); - if (!retval) return false; - if (expected) { - retval = shouldBeTrue(actual); - if (!retval) return false; - } else { - retval = shouldBeFalse(actual); - if (!retval) return false; - } - } else if (typeof expected == "number") { - retval = shouldBe(actual, stringify(expected)); - if (!retval) return false; - } else { - debug(expected + " is unknown type " + typeof expected); - retval = shouldBeTrue(actual, "'" +expected.toString() + "'"); - if (!retval) return false; - } - return retval; -} -function shouldBeNonZero(_a) -{ - var exception; - var _av; - try { - _av = eval(_a); - } catch (e) { - exception = e; - } - if (exception) - return false;//testFailed(_a + " should be non-zero. Threw exception " + exception); - else if (_av != 0) - return true;//testPassed(_a + " is non-zero."); - else - return false;//testFailed(_a + " should be non-zero. Was " + _av); -} -function shouldBeNonNull(_a) -{ - var exception; - var _av; - try { - _av = eval(_a); - } catch (e) { - exception = e; - } - if (exception) - return false;//testFailed(_a + " should be non-null. Threw exception " + exception); - else if (_av != null) - return true;//testPassed(_a + " is non-null."); - else - return false;//testFailed(_a + " should be non-null. Was " + _av); -} -function shouldBeUndefined(_a) -{ - var exception; - var _av; - try { - _av = eval(_a); - } catch (e) { - exception = e; - } - if (exception) - return false;//testFailed(_a + " should be undefined. Threw exception " + exception); - else if (typeof _av == "undefined") - return true;//testPassed(_a + " is undefined."); - else - return false;//testFailed(_a + " should be undefined. Was " + _av); -} -function shouldBeDefined(_a) -{ - var exception; - var _av; - try { - _av = eval(_a); - } catch (e) { - exception = e; - } - if (exception) - return false;//testFailed(_a + " should be defined. Threw exception " + exception); - else if (_av !== undefined) - return true;//testPassed(_a + " is defined."); - else - return false;//testFailed(_a + " should be defined. Was " + _av); -} -function shouldBeGreaterThanOrEqual(_a, _b) { - if (typeof _a != "string" || typeof _b != "string") - console.log("WARN: shouldBeGreaterThanOrEqual expects string arguments"); - var exception; - var _av; - try { - _av = eval(_a); - } catch (e) { - exception = e; - } - var _bv = eval(_b); - if (exception) { - console.log(_a + " should be >= " + _b + ". Threw exception " + exception); - return false;//testFailed(_a + " should be >= " + _b + ". Threw exception " + exception); - } else if (typeof _av == "undefined" || _av < _bv) { - console.log(_a + " should be >= " + _b + ". Was " + _av + " (of type " + typeof _av + ")."); - return false;//testFailed(_a + " should be >= " + _b + ". Was " + _av + " (of type " + typeof _av + ")."); - } else { - return true;//testPassed(_a + " is >= " + _b); - } -} -function shouldThrow(_a, _e) -{ - var exception; - var _av; - try { - _av = eval(_a); - } catch (e) { - exception = e; - } - var _ev; - if (_e) - _ev = eval(_e); - if (exception) { - if (typeof _e == "undefined" || exception == _ev) - return true;//testPassed(_a + " threw exception " + exception + "."); - else - return false;//testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Threw exception " + exception + "."); - } else if (typeof _av == "undefined") - return false;//testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was undefined."); - else - return false;//testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was " + _av + "."); -} -function assertMsg(assertion, msg) { - if (assertion) { - return true;//testPassed(msg); - } else { - console.log(msg); - return false;//testFailed(msg); - } -} diff --git a/3rdparty/ThreeJSLoader.js b/examples/3rdparty/ThreeJSLoader.js similarity index 100% rename from 3rdparty/ThreeJSLoader.js rename to examples/3rdparty/ThreeJSLoader.js diff --git a/3rdparty/gl-matrix.js b/examples/3rdparty/gl-matrix.js similarity index 100% rename from 3rdparty/gl-matrix.js rename to examples/3rdparty/gl-matrix.js diff --git a/examples/canvas3d/framebuffer/doc/src/framebuffer.qdoc b/examples/canvas3d/framebuffer/doc/src/framebuffer.qdoc index 4d24253cd7d58c6a8487cea77638865446c27671..91cf8589ccec161574f3e82c538801511e337881 100644 --- a/examples/canvas3d/framebuffer/doc/src/framebuffer.qdoc +++ b/examples/canvas3d/framebuffer/doc/src/framebuffer.qdoc @@ -41,17 +41,20 @@ \ingroup qtcanvas3d-examples \brief Render into a framebuffer and use it as a texture - The Framebuffer Example shows how to render into a framebuffer, create a texture of it, and - apply the texture to an object in normal on-screen rendering. + The Framebuffer Example shows how to render into a framebuffer, create a + texture of it, and apply the texture to an object in normal on-screen + rendering. - The example has a moving and rotating cube, which has another textured cube drawn into it via - the framebuffer object. The cube in the frambuffer can be rotated using the Qt Quick sliders. + The example has a moving and rotating cube, which has another textured + cube drawn into it via the framebuffer object. The cube in the framebuffer + can be rotated using \l [QML] {Slider}s from \l {Qt Quick Controls}. \image framebuffer-example.png \section1 Preparing the Framebuffer - We'll first define the variables we need for the render-to-texture framebuffer: + We first define the variables we need for the render-to-texture + framebuffer: \snippet framebuffer/qml/framebuffer/framebuffer.js 0 @@ -65,20 +68,21 @@ \snippet framebuffer/qml/framebuffer/framebuffer.js 2 - Then we'll need to bind the texture as a color attachment, create and bind a render buffer, and - bind the depth attachment: + Then we need to bind the texture as a color attachment, create and bind + a render buffer, and bind the depth attachment: \snippet framebuffer/qml/framebuffer/framebuffer.js 3 \section1 Rendering into the Framebuffer - In \c renderGL function, we'll first need to draw the scene into the framebuffer. We'll start - by binding the framebuffer object and setting a viewport: + In \c renderGL function, we first need to draw the scene into the + framebuffer. We start by binding the framebuffer object and setting a + viewport: \snippet framebuffer/qml/framebuffer/framebuffer.js 4 - Then, we'll need to bind the loaded texture we want to use in rendering into the framebuffer - object: + Then, we need to bind the loaded texture we want to use in rendering + into the framebuffer object: \snippet framebuffer/qml/framebuffer/framebuffer.js 5 @@ -88,16 +92,17 @@ \section1 Using the Framebuffer as a Texture - First we'll bind the render-to-texture right after drawing, and generate mipmaps: + First, we bind the render-to-texture right after drawing, and generate + mipmaps: \snippet framebuffer/qml/framebuffer/framebuffer.js 7 - Then we need to bind the default framebuffer (= screen), and set up viewport: + Then we need to bind the default framebuffer (screen), and set up the + viewport: \snippet framebuffer/qml/framebuffer/framebuffer.js 8 - And finally draw the on-screen view: + And finally, we draw the on-screen view: \snippet framebuffer/qml/framebuffer/framebuffer.js 9 - */ diff --git a/examples/canvas3d/framebuffer/framebuffer.qrc b/examples/canvas3d/framebuffer/framebuffer.qrc index c685d6e10b9b7e769483e369fc1384e007058a87..af7a213cf62339533bccbbf14fb5ba3970fecc1b 100644 --- a/examples/canvas3d/framebuffer/framebuffer.qrc +++ b/examples/canvas3d/framebuffer/framebuffer.qrc @@ -1,6 +1,6 @@ <RCC> <qresource prefix="/"> - <file>../../../3rdparty/gl-matrix.js</file> + <file>../../3rdparty/gl-matrix.js</file> <file>qml/framebuffer/main.qml</file> <file>qml/framebuffer/qtlogo.png</file> <file>qml/framebuffer/framebuffer.js</file> diff --git a/examples/canvas3d/framebuffer/qml/framebuffer/framebuffer.js b/examples/canvas3d/framebuffer/qml/framebuffer/framebuffer.js index 8d192ea1aac54a12dfa82cd806121f55b76c2f47..598014fdaee21918a1c9dd635764e407ecce3985 100644 --- a/examples/canvas3d/framebuffer/qml/framebuffer/framebuffer.js +++ b/examples/canvas3d/framebuffer/qml/framebuffer/framebuffer.js @@ -34,7 +34,7 @@ ** ****************************************************************************/ -Qt.include("../../../3rdparty/gl-matrix.js") +Qt.include("../../3rdparty/gl-matrix.js") // // Draws a cube that has the Qt logo as decal texture on each face in to a texture. diff --git a/examples/canvas3d/framebuffer/qml/framebuffer/main.qml b/examples/canvas3d/framebuffer/qml/framebuffer/main.qml index 1964ba53a2976a08fb130b08d842039e35e51923..b70d644718bfb5328e446a8207add5546071c265 100644 --- a/examples/canvas3d/framebuffer/qml/framebuffer/main.qml +++ b/examples/canvas3d/framebuffer/qml/framebuffer/main.qml @@ -68,17 +68,7 @@ Item { GLCode.renderGL(canvas3d); } - // If width or height or pixel ratio changes - // we need to react to that in the rendering code - onWidthChanged: { - GLCode.onCanvasResize(canvas3d); - } - - onHeightChanged: { - GLCode.onCanvasResize(canvas3d); - } - - onDevicePixelRatioChanged: { + onResizeGL: { GLCode.onCanvasResize(canvas3d); } diff --git a/examples/canvas3d/interaction/doc/src/interaction.qdoc b/examples/canvas3d/interaction/doc/src/interaction.qdoc index b239fb4787a65cb02e86f2c05457450dfef9a2f2..76cf3513ffb008851d0eed2d54f0767a0a4b73b2 100644 --- a/examples/canvas3d/interaction/doc/src/interaction.qdoc +++ b/examples/canvas3d/interaction/doc/src/interaction.qdoc @@ -41,46 +41,51 @@ \ingroup qtcanvas3d-examples \brief Interact with an object in canvas using Qt Quick Controls - The Interaction Example concentrates on the interaction between Qt Quick Controls and the objects - displayed in Canvas3D. The other thing this example demonstrates is drawing the same object - in three different ways. + The Interaction Example concentrates on the interaction between + \l {Qt Quick Controls} and the objects displayed in Canvas3D. This + also demonstrates drawing the same object in three different ways. \image interaction-example.png \section1 The Controls - First, we'll need to import Qt Quick Controls and Layouts: + First, we need to import Qt Quick Controls and Layouts: \snippet interaction/qml/interaction/main.qml 0 - Then, we'll add a \c RowLayout to the main component to easily add the controls side-by-side: + Then, we add a RowLayout to the main component to easily add the + controls side-by-side: \snippet interaction/qml/interaction/main.qml 1 - And then we'll add three sliders to the layout. Here's the one for controlling x axis rotation: + And then we add three sliders to the layout. Here's the one for + controlling x axis rotation: \snippet interaction/qml/interaction/main.qml 2 \section1 Interaction - First we need to define some properties in the Canvas3D for the rotations: + First we need to define some properties in the Canvas3D for the + rotations: \snippet interaction/qml/interaction/main.qml 3 - The \c onValueChanged functions in the \c{Slider}s are connected to the properties in Canvas3D. - Here's the connection in x rotation slider as an example: + The \c onValueChanged signal handlers of the \l[QML]{Slider} components + are connected to the above properties. Here's the connection in x rotation + slider as an example: \snippet interaction/qml/interaction/main.qml 4 - Then, on the JavaScript side, we just use the Canvas3D properties directly as the values when - setting the modelview matrix rotations: + Then, on the JavaScript side, we just use the Canvas3D properties directly + when setting the modelview matrix rotations: \snippet interaction/qml/interaction/interaction.js 0 - \section1 Drawing in 3 ways + \section1 Drawing in Three Ways - The actual drawing is done in the same way as everywhere else we are drawing the same object - multiple times, only in this case we use different drawing mode for each: + The actual drawing is done in the same way as everywhere else we are + drawing the same object multiple times. Only in this case, we use a + different drawing mode for each: \snippet interaction/qml/interaction/interaction.js 1 \dots 0 diff --git a/examples/canvas3d/interaction/interaction.qrc b/examples/canvas3d/interaction/interaction.qrc index 9e7b3425a67df370767c25e88ed521320fe002e5..674f0ada3b3415568256dbd7b3f28645596e631f 100644 --- a/examples/canvas3d/interaction/interaction.qrc +++ b/examples/canvas3d/interaction/interaction.qrc @@ -1,7 +1,7 @@ <RCC> <qresource prefix="/"> - <file>../../../3rdparty/gl-matrix.js</file> - <file>../../../3rdparty/ThreeJSLoader.js</file> + <file>../../3rdparty/gl-matrix.js</file> + <file>../../3rdparty/ThreeJSLoader.js</file> <file>qml/interaction/barrel.jpg</file> <file>qml/interaction/barrel.json</file> <file>qml/interaction/interaction.js</file> diff --git a/examples/canvas3d/interaction/qml/interaction/interaction.js b/examples/canvas3d/interaction/qml/interaction/interaction.js index a0411690e21381d58a4aa045f3368cbe0075e28c..8f1a2ac0648ec5e9aceddafbddc759240fd7f92b 100644 --- a/examples/canvas3d/interaction/qml/interaction/interaction.js +++ b/examples/canvas3d/interaction/qml/interaction/interaction.js @@ -34,8 +34,8 @@ ** ****************************************************************************/ -Qt.include("../../../3rdparty/gl-matrix.js") -Qt.include("../../../3rdparty/ThreeJSLoader.js") +Qt.include("../../3rdparty/gl-matrix.js") +Qt.include("../../3rdparty/ThreeJSLoader.js") var gl; diff --git a/examples/canvas3d/interaction/qml/interaction/main.qml b/examples/canvas3d/interaction/qml/interaction/main.qml index 1decbd03a5e8eef11caa2ad22de01ea93a0cff76..643ccf8366325abb456ea6b1c8953878533f82e1 100644 --- a/examples/canvas3d/interaction/qml/interaction/main.qml +++ b/examples/canvas3d/interaction/qml/interaction/main.qml @@ -69,17 +69,7 @@ Item { GLCode.renderGL(canvas3d); } - // If width or height or pixel ratio changes - // we need to react to that in the rendering code - onWidthChanged: { - GLCode.onCanvasResize(canvas3d); - } - - onHeightChanged: { - GLCode.onCanvasResize(canvas3d); - } - - onDevicePixelRatioChanged: { + onResizeGL: { GLCode.onCanvasResize(canvas3d); } } diff --git a/examples/canvas3d/jsonmodels/doc/src/jsonmodels.qdoc b/examples/canvas3d/jsonmodels/doc/src/jsonmodels.qdoc index c70ea2bff5ab9cbbfff5b522ac47a60dd101c54a..bff22dda6f63de743c1b2c264dc8032099a4ed96 100644 --- a/examples/canvas3d/jsonmodels/doc/src/jsonmodels.qdoc +++ b/examples/canvas3d/jsonmodels/doc/src/jsonmodels.qdoc @@ -41,26 +41,27 @@ \ingroup qtcanvas3d-examples \brief Load and display several JSON models - The JSON Models Example simply demonstrates loading and displaying more than one JSON model - and more than one texture. A simple mouse input handling has also been added, to allow rotating - the scene and zooming into it. - - The example optionally incorporates some Qt Quick Enterprise Controls, which you can switch on - by commenting out the \c{#define NO_ENTERPRISE} line in \c{main.cpp}. The controls - are used to toggle some optional animations and draw options, as well as displaying camera + The JSON Models Example demonstrates loading and displaying more than + one JSON model and more than one texture. It also implements simple + mouse input handling to allow rotating the scene and zooming into it. + + The example optionally incorporates some Qt Quick Enterprise Controls, + which you can switch on by commenting out the \c{#define NO_ENTERPRISE} + line in \l{jsonmodels/main.cpp}{main.cpp}. The controls are used to toggle + some optional animations and draw options, as well as displaying camera rotations and distance. \image jsonmodels-example.png \section1 JSON Model Loader - First we'll include a JSON model parser, which handles parsing the json models into our internal - models: + First we include a JSON model parser, which handles parsing the JSON + models into our internal models: \snippet jsonmodels/jsonmodels.js 0 - The \c{ThreeJSLoader.js} includes a reimplementation of the json parser in \c{three.js}, but - we will not go into the implementation details on that. + The \c{ThreeJSLoader.js} includes a reimplementation of the JSON parser + in \c{three.js}, but we will not go into its implementation details. \section1 Loading the Models @@ -85,8 +86,9 @@ \section1 Loading the Textures - First we create the TextureImage objects for each of the images we are going to load and register - handlers for the \c imageLoaded and \c imageLoadingFailed signals. In the \c imageLoaded signal + First we create the TextureImage objects for each of the images we are + going to load and register handlers for the \c imageLoaded and + \c imageLoadingFailed signals. In the \c imageLoaded signal handlers we create the OpenGL textures: \snippet jsonmodels/jsonmodels.js 5 @@ -99,30 +101,32 @@ \snippet jsonmodels/jsonmodels.qml 0 \dots - Then we'll add some functionality on it. But first we need to add properties to the canvas - with initial values set: + Before adding some functionality on it, we need to add properties to the + canvas with initial values set: \snippet jsonmodels/jsonmodels.qml 1 - After that, let's do rotation on mouse movement when the left button is pressed: + After that, we add rotation on mouse movement when the left mouse button + is pressed: \snippet jsonmodels/jsonmodels.qml 2 - We need to keep the previous x and y to avoid rotation jumping when the mouse button is released - and repressed. These are the properties for them: + We need to keep the previous x and y values to avoid rotation jumping + when the mouse button is released and pressed again. We store them in + these properties: \snippet jsonmodels/jsonmodels.qml 3 - Then we'll add zooming by mouse wheel: + Then we add zooming by mouse wheel: \snippet jsonmodels/jsonmodels.qml 4 - These are then used in the JavaScript side for eye/camera movement calculations: + These properties are then used in the JavaScript side when calculating + eye/camera movement: \snippet jsonmodels/jsonmodels.js 7 - We want to convert the rotation values into movement, and we do it like this: + Converting the rotation values into movement is done as follows: \snippet jsonmodels/jsonmodels.js 8 - - */ +*/ diff --git a/examples/canvas3d/jsonmodels/jsonmodels.qml b/examples/canvas3d/jsonmodels/jsonmodels.qml index 1991baf2f27a25babec124eb032d516e3b4af89f..b6599c20d857cde7266f36c31853805841c51b1a 100644 --- a/examples/canvas3d/jsonmodels/jsonmodels.qml +++ b/examples/canvas3d/jsonmodels/jsonmodels.qml @@ -84,17 +84,7 @@ Window { GLCode.renderGL(canvas3d); } - // If width or height or pixel ratio changes - // we need to react to that in the rendering code - onWidthChanged: { - GLCode.onCanvasResize(canvas3d); - } - - onHeightChanged: { - GLCode.onCanvasResize(canvas3d); - } - - onDevicePixelRatioChanged: { + onResizeGL: { GLCode.onCanvasResize(canvas3d); } diff --git a/examples/canvas3d/jsonmodels/jsonmodelsbasic.qml b/examples/canvas3d/jsonmodels/jsonmodelsbasic.qml index 6dadbde65789900d193fbbb914b7dbe8745f864d..79a895f4eb8c22af62bcf712cd26737e25996a20 100644 --- a/examples/canvas3d/jsonmodels/jsonmodelsbasic.qml +++ b/examples/canvas3d/jsonmodels/jsonmodelsbasic.qml @@ -78,17 +78,7 @@ Window { GLCode.renderGL(canvas3d); } - // If width or height or pixel ratio changes - // we need to react to that in the rendering code - onWidthChanged: { - GLCode.onCanvasResize(canvas3d); - } - - onHeightChanged: { - GLCode.onCanvasResize(canvas3d); - } - - onDevicePixelRatioChanged: { + onResizeGL: { GLCode.onCanvasResize(canvas3d); } diff --git a/examples/canvas3d/jsonmodels/qml.qrc b/examples/canvas3d/jsonmodels/qml.qrc index a048c3dc5cd8edb75135ec6ea1c596038f3167f5..89ef89f65a3550127e2ac8baa20f49d6085b3d7a 100644 --- a/examples/canvas3d/jsonmodels/qml.qrc +++ b/examples/canvas3d/jsonmodels/qml.qrc @@ -1,7 +1,7 @@ <RCC> <qresource prefix="/"> - <file alias="gl-matrix.js">../../../3rdparty/gl-matrix.js</file> - <file alias="ThreeJSLoader.js">../../../3rdparty/ThreeJSLoader.js</file> + <file alias="gl-matrix.js">../../3rdparty/gl-matrix.js</file> + <file alias="ThreeJSLoader.js">../../3rdparty/ThreeJSLoader.js</file> <file>gold.json</file> <file>woodbox.json</file> <file>bush.json</file> diff --git a/examples/canvas3d/textureandlight/doc/src/textureandlight.qdoc b/examples/canvas3d/textureandlight/doc/src/textureandlight.qdoc index c6f7747667602960cc54457c07cf61628f27ef07..f92dd249ba30d9d29578842232e14d50f61b5dab 100644 --- a/examples/canvas3d/textureandlight/doc/src/textureandlight.qdoc +++ b/examples/canvas3d/textureandlight/doc/src/textureandlight.qdoc @@ -41,122 +41,129 @@ \ingroup qtcanvas3d-examples \brief A simple cube with texturing and lighting - The Lit and Textured Cube example that goes through basics of how to use QtCanvas3D. + The Lit and Textured Cube example goes through the basics of using + Qt Canvas 3D. \image textureandlight-example.png - \section1 QtQuick Side + \section1 Qt Quick Implementation \section2 Creating Canvas3D - We'll add a Canvas3D component into the main component: + In \l{textureandlight/qml/textureandlight/main.qml}{main.qml}, we add a + Canvas3D under the root \c Item: \snippet textureandlight/qml/textureandlight/main.qml 0 \dots - Inside it, we catch the \c initGL and \c renderGL signals to forward the initialization - and rendering calls to the js object: + Inside it, we catch the \c initGL and \c renderGL signals to forward the + initialization and rendering calls to the js object: \snippet textureandlight/qml/textureandlight/main.qml 1 - \section2 Importing the JavaScript file + \section2 Importing the JavaScript File + We import the JavaScript file in the QML: \snippet textureandlight/qml/textureandlight/main.qml 4 - In the \c initGL function of the JavaScript, we initialize the OpenGL state. We also create the - TextureImage and register handlers for image load success and fail signals. In the case of - load success the OpenGL texture is created and the loaded image is used to fill the texture - with pixel data. + In the \c initGL function of the JavaScript, we initialize the OpenGL + state. We also create the TextureImage and register handlers for image + load success and fail signals. If the load succeeds, the OpenGL texture + is created and filled with pixel data from the loaded image. - \section1 The JavaScript File + \section1 JavaScript Implementation \section2 Matrix Library - First we'll include a fast matrix library. Using this makes it a lot easier to - handle all the 3D mathematics like for example the matrix transformations: + In \l {textureandlight/qml/textureandlight/textureandlight.js} + {textureandlight.js}, we first include a fast matrix library. Using this + makes it a lot easier to handle 3D math operations such as matrix + transformations: \snippet textureandlight/qml/textureandlight/textureandlight.js 0 - \section1 initGL function + \section2 initGL Function - Let's take a closer look at the \c initGL function. It is called by Canvas3D once the render - node is ready. + Let's take a closer look at the \c initGL function. It is called by + Canvas3D once the render node is ready. - First of all, we'll need to get Context3D from our Canvas3D. We want a context that supports - depth buffer and antialising: + First of all, we need to get a Context3D from our Canvas3D. We want + a context that supports depth buffer and antialising: \snippet textureandlight/qml/textureandlight/textureandlight.js 1 - Then we'll initialize the OpenGL state for the context: + Then we initialize the OpenGL state for the context: \snippet textureandlight/qml/textureandlight/textureandlight.js 2 - Next, let's take a look into shader initialization in \c initShaders function, which we call - in the \c{initGL}. First of all we'll define the vertex shader: + Next, let's take a look into shader initialization in the + \c initShaders function, which we call in \c{initGL}. First we define + the vertex shader: \snippet textureandlight/qml/textureandlight/textureandlight.js 3 - We'll follow that up by defining fragment shader: + We follow that up by defining a fragment shader: \snippet textureandlight/qml/textureandlight/textureandlight.js 4 - Then we'll need to create the shader program (Program3D), attach the shaders to it, and then - link and use the program: + Then we need to create the shader program (Program3D), attach the shaders + to it, and then link and use the program: \snippet textureandlight/qml/textureandlight/textureandlight.js 5 - And finally look up and store the vertex attributes and uniform locations: + And finally, look up and store the vertex attributes and uniform locations: \snippet textureandlight/qml/textureandlight/textureandlight.js 6 - After initializing the shader program, we'll set up the vertex buffer in \c initBuffers - function. Let's look at the vertex index buffer creation as an example: + After initializing the shader program, we set up the vertex buffer in + \c initBuffers function. Let's look at the vertex index buffer creation + as an example: \snippet textureandlight/qml/textureandlight/textureandlight.js 7 - As can be seen, first we create the buffer, then bind it and finally insert the data into it. - We won't take a look at the other buffers, as they are all handled in a similar fashion. + Above, first we create the buffer, then bind it and finally insert the + data into it. Other buffers are all handled in a similar fashion. - After that, as the final step in \c{initGL}, we'll create a texture image from - TextureImageFactory. And we register handlers for \c imageLoaded and \c imageLoadingFailed - signals. Once the texture image is successfully loaded, we create the actual texture: + As the final step in \c{initGL}, we create a texture image from + TextureImageFactory, and register handlers for \c imageLoaded and + \c imageLoadingFailed signals. Once the texture image is successfully + loaded, we create the actual texture: \snippet textureandlight/qml/textureandlight/textureandlight.js 8 - \section2 renderGL function + \section2 renderGL Function - \c renderGL is called by Canvas3D whenever it is ready to receive a new frame. Let's go through - the steps that are done in each render cycle. + \c renderGL is called by Canvas3D whenever it is ready to receive a new + frame. Let's go through the steps that are done in each render cycle. - First we check if canvas has been resized or if pixel ratio has changed, and update the - projection matrix if necessary: + First we check if canvas has been resized or if pixel ratio has changed, + and update the projection matrix if necessary: \snippet textureandlight/qml/textureandlight/textureandlight.js 9 - Then we'll clear the render area using the clear color set in \c{initGL}: + Then we clear the render area using the clear color set in \c{initGL}: \snippet textureandlight/qml/textureandlight/textureandlight.js 10 - Next we'll reset the model view matrix and apply translation and rotations: + Next we reset the model view matrix and apply translation and rotations: \snippet textureandlight/qml/textureandlight/textureandlight.js 11 - As we have a lit cube, we'll invert and transpose the model view matrix to be used for lighting - calculations: + As we have a lit cube, we invert and transpose the model view matrix to + be used for lighting calculations: \snippet textureandlight/qml/textureandlight/textureandlight.js 12 - And finally we'll draw the cube: + And finally we draw the cube: \snippet textureandlight/qml/textureandlight/textureandlight.js 13 \section1 Logging - QtCanvas3D uses the Qt's categorized logging, this example enables all QtCanvas3D log output - with the code shown below. For more on Canvas3D's logging features refer to - \l {QtCanvas3D Logging}. + Qt Canvas 3D uses Qt's categorized logging feature. This example enables + all Qt Canvas 3D log output with the code shown below. For more on + Canvas3D's logging features refer to \l {Qt Canvas 3D Logging}. \snippet textureandlight/main.cpp 0 - - */ +*/ diff --git a/examples/canvas3d/textureandlight/main.cpp b/examples/canvas3d/textureandlight/main.cpp index b990dffdb506c66ccea96e23c5d0ee09ff914930..53262ace50d24257746f41ba95e00441eac11a34 100644 --- a/examples/canvas3d/textureandlight/main.cpp +++ b/examples/canvas3d/textureandlight/main.cpp @@ -43,12 +43,12 @@ int main(int argc, char *argv[]) { //! [0] - // Turns on all logging of Canvas3D - QString loggingFilter = QString("qt.canvas3d.info.debug=true\n"); - loggingFilter += QStringLiteral("qt.canvas3d.rendering.debug=true\n") - + QStringLiteral("qt.canvas3d.rendering.warning=true\n") - + QStringLiteral("qt.canvas3d.glerrors.debug=true"); - QLoggingCategory::setFilterRules(loggingFilter); + // Uncomment to turn on all the logging categories of Canvas3D +// QString loggingFilter = QString("qt.canvas3d.info.debug=true\n"); +// loggingFilter += QStringLiteral("qt.canvas3d.rendering.debug=true\n") +// + QStringLiteral("qt.canvas3d.rendering.warning=true\n") +// + QStringLiteral("qt.canvas3d.glerrors.debug=true"); +// QLoggingCategory::setFilterRules(loggingFilter); //! [0] QGuiApplication app(argc, argv); diff --git a/examples/canvas3d/textureandlight/qml/textureandlight/main.qml b/examples/canvas3d/textureandlight/qml/textureandlight/main.qml index ba1aeb5f7e3f06764eab74caf75566379477f586..644ed59ae2848364c1e4ded950b0a9581e0bd30d 100644 --- a/examples/canvas3d/textureandlight/qml/textureandlight/main.qml +++ b/examples/canvas3d/textureandlight/qml/textureandlight/main.qml @@ -70,17 +70,7 @@ Item { } //! [1] - // If width or height or pixel ratio changes - // we need to react to that in the rendering code - onWidthChanged: { - GLCode.onCanvasResize(canvas3d); - } - - onHeightChanged: { - GLCode.onCanvasResize(canvas3d); - } - - onDevicePixelRatioChanged: { + onResizeGL: { GLCode.onCanvasResize(canvas3d); } diff --git a/examples/canvas3d/textureandlight/textureandlight.qrc b/examples/canvas3d/textureandlight/textureandlight.qrc index 1db29d8630c7eb4e95b971b1849bf79328da9961..56b2fa779ce10c2bef13d42bb226885d460a41ca 100644 --- a/examples/canvas3d/textureandlight/textureandlight.qrc +++ b/examples/canvas3d/textureandlight/textureandlight.qrc @@ -3,6 +3,6 @@ <file>qml/textureandlight/main.qml</file> <file>qml/textureandlight/textureandlight.js</file> <file>qml/textureandlight/qtlogo.png</file> - <file alias="gl-matrix.js">../../../3rdparty/gl-matrix.js</file> + <file alias="gl-matrix.js">../../3rdparty/gl-matrix.js</file> </qresource> </RCC> diff --git a/src/imports/imports.pro b/src/imports/imports.pro new file mode 100644 index 0000000000000000000000000000000000000000..5b3db11fb125d3c4cd74e4546065e822b3e85234 --- /dev/null +++ b/src/imports/imports.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs + +qtHaveModule(quick):contains(QT_CONFIG, opengl) { + SUBDIRS += qtcanvas3d +} diff --git a/src/abstractobject3d.cpp b/src/imports/qtcanvas3d/abstractobject3d.cpp similarity index 100% rename from src/abstractobject3d.cpp rename to src/imports/qtcanvas3d/abstractobject3d.cpp diff --git a/src/abstractobject3d_p.h b/src/imports/qtcanvas3d/abstractobject3d_p.h similarity index 100% rename from src/abstractobject3d_p.h rename to src/imports/qtcanvas3d/abstractobject3d_p.h diff --git a/src/activeinfo3d.cpp b/src/imports/qtcanvas3d/activeinfo3d.cpp similarity index 96% rename from src/activeinfo3d.cpp rename to src/imports/qtcanvas3d/activeinfo3d.cpp index 812039ffd0d59ef018aa20b40a0bab6cde5a3fa3..bbffb45b3cbbd1e79d442c6c06c444ee315753c5 100644 --- a/src/activeinfo3d.cpp +++ b/src/imports/qtcanvas3d/activeinfo3d.cpp @@ -42,13 +42,13 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! * \qmltype ActiveInfo3D * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Active attribute or uniform information. * * The ActiveInfo3D interface represents the information returned from the getActiveAttrib and * getActiveUniform calls. * - * \sa Context3D, Canvas3D, {QtCanvas3D QML Types} + * \sa Context3D, Canvas3D */ CanvasActiveInfo::CanvasActiveInfo(int size, CanvasContext::glEnums type, diff --git a/src/activeinfo3d_p.h b/src/imports/qtcanvas3d/activeinfo3d_p.h similarity index 100% rename from src/activeinfo3d_p.h rename to src/imports/qtcanvas3d/activeinfo3d_p.h diff --git a/src/arrayutils.cpp b/src/imports/qtcanvas3d/arrayutils.cpp similarity index 100% rename from src/arrayutils.cpp rename to src/imports/qtcanvas3d/arrayutils.cpp diff --git a/src/arrayutils_p.h b/src/imports/qtcanvas3d/arrayutils_p.h similarity index 100% rename from src/arrayutils_p.h rename to src/imports/qtcanvas3d/arrayutils_p.h diff --git a/src/buffer3d.cpp b/src/imports/qtcanvas3d/buffer3d.cpp similarity index 99% rename from src/buffer3d.cpp rename to src/imports/qtcanvas3d/buffer3d.cpp index 92eab0ab86e85dbbbc2b23d22807118a712ff2c0..9e005781137650b3c7646e99a1fd73e7ebb809b3 100644 --- a/src/buffer3d.cpp +++ b/src/imports/qtcanvas3d/buffer3d.cpp @@ -45,7 +45,7 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! * \qmltype Buffer3D * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Contains an OpenGL buffer. * * An uncreatable QML type that contains an OpenGL buffer. You can get it by calling diff --git a/src/buffer3d_p.h b/src/imports/qtcanvas3d/buffer3d_p.h similarity index 100% rename from src/buffer3d_p.h rename to src/imports/qtcanvas3d/buffer3d_p.h diff --git a/src/canvas3d.cpp b/src/imports/qtcanvas3d/canvas3d.cpp similarity index 89% rename from src/canvas3d.cpp rename to src/imports/qtcanvas3d/canvas3d.cpp index 1e105db67a9608623863b9969bb59b81bd6f1ee7..289b00f09ee8beaea37d9be38d7aec503bd2f088 100644 --- a/src/canvas3d.cpp +++ b/src/imports/qtcanvas3d/canvas3d.cpp @@ -57,7 +57,7 @@ Q_LOGGING_CATEGORY(canvas3dglerrors, "qt.canvas3d.glerrors") /*! * \qmltype Canvas3D * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Canvas that provides a 3D rendering context. * * The Canvas3D is a QML element that, when placed in your Qt Quick 2 scene, allows you to @@ -72,7 +72,7 @@ Q_LOGGING_CATEGORY(canvas3dglerrors, "qt.canvas3d.glerrors") * submit 3D rendering calls to draw whatever 3D content you want to be displayed. * \endlist * - * \sa Context3D, {QtCanvas3D QML Types} + * \sa Context3D */ /*! @@ -80,6 +80,7 @@ Q_LOGGING_CATEGORY(canvas3dglerrors, "qt.canvas3d.glerrors") */ Canvas::Canvas(QQuickItem *parent): QQuickItem(parent), + m_isNeedRenderQueued(false), m_renderNodeReady(false), m_mainThread(QThread::currentThread()), m_contextThread(0), @@ -87,6 +88,7 @@ Canvas::Canvas(QQuickItem *parent): m_isFirstRender(true), m_fboSize(0, 0), m_initializedSize(1, 1), + m_maxSize(128,128), m_glContext(0), m_glContextQt(0), m_glContextShare(0), @@ -100,10 +102,13 @@ Canvas::Canvas(QQuickItem *parent): m_antialiasFbo(0), m_renderFbo(0), m_displayFbo(0), + m_oldDisplayFbo(0), m_offscreenSurface(0) { connect(this, &QQuickItem::windowChanged, this, &Canvas::handleWindowChanged); connect(this, &Canvas::needRender, this, &Canvas::renderNext, Qt::QueuedConnection); + connect(this, &QQuickItem::widthChanged, this, &Canvas::emitResizeGL, Qt::DirectConnection); + connect(this, &QQuickItem::heightChanged, this, &Canvas::emitResizeGL, Qt::DirectConnection); setAntialiasing(false); // Set contents to false in case we are in qml designer to make component look nice @@ -167,18 +172,6 @@ void Canvas::shutDown() m_glContextShare = 0; } -/*! - * \qmlsignal Canvas3D::needRender() - * This signal, if emitted, causes a re-rendering cycle to happen. Usually this is needed - * if a value that affects the look of the 3D scene has changed, but no other mechanism - * triggers the re-render cycle. - */ - -/*! - * \qmlsignal Canvas3D::textureReady(int id, size size, float devicePixelRatio) - * Emitted when a new texture is ready to inform the render node. - */ - /*! * \qmlproperty float Canvas3D::devicePixelRatio * Specifies the ratio between logical pixels (used by the Qt Quick) and actual physical @@ -249,7 +242,6 @@ QJSValue Canvas::getContext(const QString &type, const QVariantMap &options) m_contextAttribs.setDepth(true); // Ensure ignored attributes are left to their default state - m_contextAttribs.setAlpha(false); m_contextAttribs.setPremultipliedAlpha(false); m_contextAttribs.setPreserveDrawingBuffer(false); m_contextAttribs.setPreferLowPowerToHighPerformance(false); @@ -345,6 +337,12 @@ QJSValue Canvas::getContext(const QString &type, const QVariantMap &options) // Initialize OpenGL functions using the created GL context initializeOpenGLFunctions(); + // Get the maximum drawable size + GLint viewportDims[2]; + glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewportDims); + m_maxSize.setWidth(viewportDims[0]); + m_maxSize.setHeight(viewportDims[1]); + // Set the size and create FBOs setPixelSize(m_initializedSize); @@ -369,8 +367,8 @@ QJSValue Canvas::getContext(const QString &type, const QVariantMap &options) /*! * \qmlproperty size Canvas3D::pixelSize - * Specifies the size of the render target surface in pixels. If between logical pixels - * (used by the Qt Quick) and actual physical on-screen pixels (used by the 3D rendering). + * Specifies the size of the render target surface in physical on-screen pixels used by + * the 3D rendering. */ /*! * \internal @@ -389,12 +387,29 @@ void Canvas::setPixelSize(QSize pixelSize) << "(pixelSize:" << pixelSize << ")"; + if (pixelSize.width() > m_maxSize.width()) { + qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ + << "():" + << "Maximum pixel width exceeded limiting to " + << m_maxSize.width(); + pixelSize.setWidth(m_maxSize.width()); + } + + if (pixelSize.height() > m_maxSize.height()) { + qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ + << "():" + << "Maximum pixel height exceeded limiting to " + << m_maxSize.height(); + pixelSize.setHeight(m_maxSize.height()); + } + if (m_fboSize == pixelSize && m_renderFbo != 0) return; m_fboSize = pixelSize; createFBOs(); emit pixelSizeChanged(pixelSize); + emitNeedRender(); } /*! @@ -425,9 +440,9 @@ void Canvas::createFBOs() glGetIntegerv(GL_TEXTURE_BINDING_2D, &texBinding2D); glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor); - // Store existing FBOs, don't delete before we've created the new ones - // so that we get fresh texture and FBO id's for the newly created objects. - QOpenGLFramebufferObject *displayFBO = m_displayFbo; + // Store existing display FBO, don't delete before next updatePaintNode call + // Store existing render and antialias FBO's for a moment so we get new id's for new ones + m_oldDisplayFbo = m_displayFbo; QOpenGLFramebufferObject *renderFbo = m_renderFbo; QOpenGLFramebufferObject *antialiasFbo = m_antialiasFbo; @@ -478,7 +493,6 @@ void Canvas::createFBOs() } // FBO ids and texture id's have been generated, we can now free the existing ones. - delete displayFBO; delete renderFbo; delete antialiasFbo; @@ -488,7 +502,7 @@ void Canvas::createFBOs() if (m_context3D) { bindCurrentRenderTarget(); - emit needRender(); + emitNeedRender(); } } @@ -501,7 +515,7 @@ void Canvas::handleWindowChanged(QQuickWindow *window) if (!window) return; - emit needRender(); + emitNeedRender(); } /*! @@ -517,7 +531,7 @@ void Canvas::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometr m_cachedGeometry = newGeometry; - emit needRender(); + emitNeedRender(); } /*! @@ -530,7 +544,7 @@ void Canvas::itemChange(ItemChange change, const ItemChangeData &value) << ")"; QQuickItem::itemChange(change, value); - emit needRender(); + emitNeedRender(); } /*! @@ -557,6 +571,7 @@ void Canvas::updateWindowParameters() if (pixelRatio != m_devicePixelRatio) { m_devicePixelRatio = pixelRatio; emit devicePixelRatioChanged(pixelRatio); + emitResizeGL(); win->update(); } } @@ -595,8 +610,8 @@ QSGNode *Canvas::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) << " size:" << m_initializedSize << " devicePixelRatio:" << m_devicePixelRatio; if (m_runningInDesigner - || m_initializedSize.width() <= 0 - || m_initializedSize.height() <= 0 + || m_initializedSize.width() < 0 + || m_initializedSize.height() < 0 || !window()) { delete oldNode; qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ @@ -653,17 +668,17 @@ QSGNode *Canvas::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) Qt::DirectConnection); connect(node, &CanvasRenderNode::textureInUse, - this, &Canvas::renderNext, + this, &Canvas::emitNeedRender, Qt::QueuedConnection); // Get the production of FBO textures started.. - emit needRender(); + emitNeedRender(); update(); } node->setRect(boundingRect()); - emit needRender(); + emitNeedRender(); m_renderNodeReady = true; @@ -715,6 +730,8 @@ void Canvas::renderNext() { qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ << "()"; + m_isNeedRenderQueued = false; + updateWindowParameters(); // Don't try to do anything before the render node has been created @@ -815,6 +832,10 @@ void Canvas::renderNext() << m_displayFbo->texture() << " from FBO:" << m_displayFbo->handle(); + // FBO ids and texture id's have been generated, we can now free the old display FBO + delete m_oldDisplayFbo; + m_oldDisplayFbo = 0; + // Rebind default FBO QOpenGLFramebufferObject::bindDefault(); @@ -822,5 +843,43 @@ void Canvas::renderNext() emit textureReady(m_displayFbo->texture(), m_fboSize, m_devicePixelRatio); } +/*! + * \internal + */ +void Canvas::emitResizeGL() +{ + qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ << "()"; + + // Wait until render node has been created + if (!m_renderNodeReady) { + qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ + << " Render node not ready, returning"; + return; + } + + if (m_glContext) { + qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ + << " Emit resizeGL() signal"; + emit resizeGL(int(width()), int(height()), m_devicePixelRatio); + } +} + +/*! + * \internal + */ +void Canvas::emitNeedRender() +{ + qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ << "()"; + + if (m_isNeedRenderQueued) { + qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ + << " needRender already queued, returning"; + return; + } + + m_isNeedRenderQueued = true; + emit needRender(); +} + QT_CANVAS3D_END_NAMESPACE QT_END_NAMESPACE diff --git a/src/canvas3d_p.h b/src/imports/qtcanvas3d/canvas3d_p.h similarity index 96% rename from src/canvas3d_p.h rename to src/imports/qtcanvas3d/canvas3d_p.h index e2b82dc31749e614906c807fa6fafa54a06794d7..c5dbb4087113ec2858655308b8cf35d4eb551b39 100644 --- a/src/canvas3d_p.h +++ b/src/imports/qtcanvas3d/canvas3d_p.h @@ -104,17 +104,19 @@ public slots: void ready(); void shutDown(); void renderNext(); + void emitResizeGL(); + void emitNeedRender(); signals: void needRender(); void devicePixelRatioChanged(float ratio); - void animatedChanged(bool animated); void contextChanged(CanvasContext *context); void fpsChanged(uint fps); void pixelSizeChanged(QSize pixelSize); void initGL(); void renderGL(); + void resizeGL(int width, int height, float devicePixelRatio); void textureReady(int id, const QSize &size, float devicePixelRatio); @@ -127,6 +129,7 @@ private: void setupAntialiasing(); void updateWindowParameters(); + bool m_isNeedRenderQueued; bool m_renderNodeReady; QThread *m_mainThread; QThread *m_contextThread; @@ -135,6 +138,7 @@ private: bool m_isFirstRender; QSize m_fboSize; QSize m_initializedSize; + QSize m_maxSize; QOpenGLContext *m_glContext; QOpenGLContext *m_glContextQt; @@ -156,6 +160,7 @@ private: QOpenGLFramebufferObject *m_displayFbo; QOpenGLFramebufferObjectFormat m_fboFormat; QOpenGLFramebufferObjectFormat m_antialiasFboFormat; + QOpenGLFramebufferObject *m_oldDisplayFbo; QOffscreenSurface *m_offscreenSurface; }; diff --git a/src/canvas3dcommon_p.h b/src/imports/qtcanvas3d/canvas3dcommon_p.h similarity index 100% rename from src/canvas3dcommon_p.h rename to src/imports/qtcanvas3d/canvas3dcommon_p.h diff --git a/src/canvasglstatedump.cpp b/src/imports/qtcanvas3d/canvasglstatedump.cpp similarity index 99% rename from src/canvasglstatedump.cpp rename to src/imports/qtcanvas3d/canvasglstatedump.cpp index b4d9fb13cc34844817437ec70c9bb12b8cf3adde..7847c06708b1ba6bf27d3c1fe770528733ed9f29 100644 --- a/src/canvasglstatedump.cpp +++ b/src/imports/qtcanvas3d/canvasglstatedump.cpp @@ -48,7 +48,7 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! \qmltype GLStateDumpExt \since QtCanvas3D 1.0 - \ingroup qtcanvas3d-qml-types + \inqmlmodule QtCanvas3D \brief Provides means to print current GL driver state info. An uncreatable QML type that provides an extension API that can be used dump current OpenGL @@ -217,7 +217,6 @@ QString CanvasGLStateDump::getGLStateDump(CanvasGLStateDump::stateDumpEnums opti glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &boundElementArrayBuffer); glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &arrayBufferBinding); - #if !defined(QT_OPENGL_ES_2) if (!m_isOpenGLES2) { stateDumpStr.append("GL_DRAW_FRAMEBUFFER_BINDING....."); diff --git a/src/canvasglstatedump_p.h b/src/imports/qtcanvas3d/canvasglstatedump_p.h similarity index 100% rename from src/canvasglstatedump_p.h rename to src/imports/qtcanvas3d/canvasglstatedump_p.h diff --git a/src/canvasrendernode.cpp b/src/imports/qtcanvas3d/canvasrendernode.cpp similarity index 100% rename from src/canvasrendernode.cpp rename to src/imports/qtcanvas3d/canvasrendernode.cpp diff --git a/src/canvasrendernode_p.h b/src/imports/qtcanvas3d/canvasrendernode_p.h similarity index 100% rename from src/canvasrendernode_p.h rename to src/imports/qtcanvas3d/canvasrendernode_p.h diff --git a/src/imports/qtcanvas3d/compressedtexturepvrtc.cpp b/src/imports/qtcanvas3d/compressedtexturepvrtc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b687f22e505d3c3708391f183f097164d73d7698 --- /dev/null +++ b/src/imports/qtcanvas3d/compressedtexturepvrtc.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "compressedtexturepvrtc_p.h" + +QT_BEGIN_NAMESPACE +QT_CANVAS3D_BEGIN_NAMESPACE + +CompressedTexturePVRTC::CompressedTexturePVRTC(QObject *parent) : QObject(parent) +{ + +} + +CompressedTexturePVRTC::~CompressedTexturePVRTC() +{ + +} + +QT_CANVAS3D_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/imports/qtcanvas3d/compressedtexturepvrtc_p.h b/src/imports/qtcanvas3d/compressedtexturepvrtc_p.h new file mode 100644 index 0000000000000000000000000000000000000000..d44e72ebeae49bb6196d7142e9765a060badcbee --- /dev/null +++ b/src/imports/qtcanvas3d/compressedtexturepvrtc_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtCanvas3D API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef COMPRESSEDTEXTUREPVRTC_H +#define COMPRESSEDTEXTUREPVRTC_H + +#include "canvas3dcommon_p.h" +#include "context3d_p.h" + +#include <QObject> + +QT_BEGIN_NAMESPACE +QT_CANVAS3D_BEGIN_NAMESPACE + +class CompressedTexturePVRTC : public QObject +{ + Q_OBJECT + + Q_DISABLE_COPY(CompressedTexturePVRTC) + + Q_PROPERTY(QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGB_PVRTC_4BPPV1_IMG READ COMPRESSED_RGB_PVRTC_4BPPV1_IMG_read); + Q_PROPERTY(QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGB_PVRTC_2BPPV1_IMG READ COMPRESSED_RGB_PVRTC_2BPPV1_IMG_read); + Q_PROPERTY(QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGBA_PVRTC_4BPPV1_IMG READ COMPRESSED_RGBA_PVRTC_4BPPV1_IMG_read); + Q_PROPERTY(QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGBA_PVRTC_2BPPV1_IMG READ COMPRESSED_RGBA_PVRTC_2BPPV1_IMG_read); + +public: + explicit CompressedTexturePVRTC(QObject *parent = 0); + ~CompressedTexturePVRTC(); + + inline QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGB_PVRTC_4BPPV1_IMG_read() { + return QtCanvas3D::CanvasContext::COMPRESSED_RGB_PVRTC_4BPPV1_IMG; + } + + inline QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGB_PVRTC_2BPPV1_IMG_read() { + return QtCanvas3D::CanvasContext::COMPRESSED_RGB_PVRTC_2BPPV1_IMG; + } + + inline QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGBA_PVRTC_4BPPV1_IMG_read() { + return QtCanvas3D::CanvasContext::COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; + } + + inline QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGBA_PVRTC_2BPPV1_IMG_read() { + return QtCanvas3D::CanvasContext::COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; + } +}; + +QT_CANVAS3D_END_NAMESPACE +QT_END_NAMESPACE + +#endif // COMPRESSEDTEXTUREPVRTC_H diff --git a/src/imports/qtcanvas3d/compressedtextures3tc.cpp b/src/imports/qtcanvas3d/compressedtextures3tc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db63a1b3266725bc2a72b673864ff00f4fb6f6ef --- /dev/null +++ b/src/imports/qtcanvas3d/compressedtextures3tc.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "compressedtextures3tc_p.h" + +QT_BEGIN_NAMESPACE +QT_CANVAS3D_BEGIN_NAMESPACE + +CompressedTextureS3TC::CompressedTextureS3TC(QObject *parent) : QObject(parent) +{ +} + +CompressedTextureS3TC::~CompressedTextureS3TC() +{ +} + +QT_CANVAS3D_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/imports/qtcanvas3d/compressedtextures3tc_p.h b/src/imports/qtcanvas3d/compressedtextures3tc_p.h new file mode 100644 index 0000000000000000000000000000000000000000..86a9833bd2d1a11120a78ae9ea17434ab57cae53 --- /dev/null +++ b/src/imports/qtcanvas3d/compressedtextures3tc_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtCanvas3D API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef COMPRESSEDTEXTURES3TC_H +#define COMPRESSEDTEXTURES3TC_H + +#include "canvas3dcommon_p.h" +#include "context3d_p.h" + +#include <QObject> + +QT_BEGIN_NAMESPACE +QT_CANVAS3D_BEGIN_NAMESPACE + +class CompressedTextureS3TC : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(CompressedTextureS3TC) + + Q_PROPERTY(QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGB_S3TC_DXT1_EXT READ COMPRESSED_RGB_S3TC_DXT1_EXT_read); + Q_PROPERTY(QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGBA_S3TC_DXT1_EXT READ COMPRESSED_RGBA_S3TC_DXT1_EXT_read); + Q_PROPERTY(QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGBA_S3TC_DXT3_EXT READ COMPRESSED_RGBA_S3TC_DXT3_EXT_read); + Q_PROPERTY(QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGBA_S3TC_DXT5_EXT READ COMPRESSED_RGBA_S3TC_DXT5_EXT_read); + +public: + explicit CompressedTextureS3TC(QObject *parent = 0); + ~CompressedTextureS3TC(); + + inline QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGB_S3TC_DXT1_EXT_read() { + return QtCanvas3D::CanvasContext::COMPRESSED_RGB_S3TC_DXT1_EXT; + } + + inline QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGBA_S3TC_DXT1_EXT_read() { + return QtCanvas3D::CanvasContext::COMPRESSED_RGBA_S3TC_DXT1_EXT; + } + + inline QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGBA_S3TC_DXT3_EXT_read() { + return QtCanvas3D::CanvasContext::COMPRESSED_RGBA_S3TC_DXT3_EXT; + } + + inline QtCanvas3D::CanvasContext::glEnums COMPRESSED_RGBA_S3TC_DXT5_EXT_read() { + return QtCanvas3D::CanvasContext::COMPRESSED_RGBA_S3TC_DXT5_EXT; + } +}; + +QT_CANVAS3D_END_NAMESPACE +QT_END_NAMESPACE + +#endif // COMPRESSEDTEXTURES3TC_H diff --git a/src/context3d.cpp b/src/imports/qtcanvas3d/context3d.cpp similarity index 95% rename from src/context3d.cpp rename to src/imports/qtcanvas3d/context3d.cpp index 35c93251ba58cdc768c94fe7173558ab891eb108..fe2d572be4d630783f76ea11ad750f0c477b7cf2 100644 --- a/src/context3d.cpp +++ b/src/imports/qtcanvas3d/context3d.cpp @@ -50,8 +50,11 @@ #include "shaderprecisionformat_p.h" #include "enumtostringmap_p.h" #include "canvas3dcommon_p.h" +#include "compressedtextures3tc_p.h" +#include "compressedtexturepvrtc_p.h" #include <QtGui/QOpenGLShader> +#include <QtOpenGLExtensions/QOpenGLExtensions> #include <QtQml/private/qv4typedarray_p.h> #include <QtQml/private/qv4arraybuffer_p.h> #include <QtQml/private/qjsvalue_p.h> @@ -63,7 +66,7 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! * \qmltype Context3D * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Provides the 3D rendering API and context. * * An uncreatable QML type that provides a WebGL-like API that can be used to draw 3D graphics to @@ -98,7 +101,9 @@ CanvasContext::CanvasContext(QOpenGLContext *context, QSurface *surface, QQmlEng m_maxVertexAttribs(0), m_isOpenGLES2(isES2), m_stateDumpExt(0), - m_standardDerivatives(0) + m_standardDerivatives(0), + m_compressedTextureS3TC(0), + m_compressedTexturePVRTC(0) { m_extensions = m_context->extensions(); @@ -168,7 +173,7 @@ uint CanvasContext::drawingBufferWidth() { uint width = 0; if (m_canvas) - width = m_canvas->width(); + width = m_canvas->pixelSize().width() / m_devicePixelRatio; qCDebug(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ << "(): " << width; @@ -184,7 +189,7 @@ uint CanvasContext::drawingBufferHeight() { uint height = 0; if (m_canvas) - height = m_canvas->height(); + height = m_canvas->pixelSize().height() / m_devicePixelRatio; qCDebug(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ << "(): " << height; @@ -204,7 +209,7 @@ QString CanvasContext::glEnumToString(glEnums value) const */ void CanvasContext::logAllGLErrors(const QString &funcName) { - if (!((QLoggingCategory &) canvas3dglerrors()).isDebugEnabled()) + if (!canvas3dglerrors().isDebugEnabled()) return; GLenum err; @@ -430,7 +435,8 @@ void CanvasContext::deleteTexture(QJSValue texture3D) } else { m_error |= CANVAS_INVALID_VALUE; qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID texture handle:" << texture3D.toString(); + << ":INVALID texture handle:" + << texture3D.toString(); } } @@ -518,51 +524,65 @@ void CanvasContext::bindTexture(glEnums target, QJSValue texture3D) logAllGLErrors(__FUNCTION__); } -/*! - * \qmlmethod void Context3D::generateMipmap(glEnums target) - * Generates a complete set of mipmaps for a texture object of the currently active texture unit. - * \a target defines the texture target to which the texture object is bound whose mipmaps will be - * generated. Must be either \c{Context3D.TEXTURE_2D} or \c{Context3D.TEXTURE_CUBE_MAP}. - */ /*! * \internal */ -void CanvasContext::generateMipmap(glEnums target) +bool CanvasContext::isValidTextureBound(glEnums target, const QString &funcName) { - qCDebug(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << "(target:" << glEnumToString(target) - << ")"; - if (target == TEXTURE_2D) { if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:No current TEXTURE_2D bound"; + qCWarning(canvas3drendering).nospace() << "Context3D::" << funcName + << ":INVALID_OPERATION:" + << "No current TEXTURE_2D bound"; m_error |= CANVAS_INVALID_OPERATION; + return false; } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ + qCWarning(canvas3drendering).nospace() << "Context3D::" << funcName << ":INVALID_OPERATION:" << "Currently bound TEXTURE_2D is deleted"; m_error |= CANVAS_INVALID_OPERATION; - } else { - glGenerateMipmap(target); - logAllGLErrors(__FUNCTION__); + return false; } } else if (target == TEXTURE_CUBE_MAP) { if (!m_currentTextureCubeMap) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ + qCWarning(canvas3drendering).nospace() << "Context3D::" << funcName << ":INVALID_OPERATION:" << "No current TEXTURE_CUBE_MAP bound"; m_error |= CANVAS_INVALID_OPERATION; + return false; } else if (!m_currentTextureCubeMap->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ + qCWarning(canvas3drendering).nospace() << "Context3D::" << funcName << ":INVALID_OPERATION:" << "Currently bound TEXTURE_CUBE_MAP is deleted"; m_error |= CANVAS_INVALID_OPERATION; - } else { - glGenerateMipmap(target); - logAllGLErrors(__FUNCTION__); + return false; } } + + return true; +} + +/*! + * \qmlmethod void Context3D::generateMipmap(glEnums target) + * Generates a complete set of mipmaps for a texture object of the currently active texture unit. + * \a target defines the texture target to which the texture object is bound whose mipmaps will be + * generated. Must be either \c{Context3D.TEXTURE_2D} or \c{Context3D.TEXTURE_CUBE_MAP}. + */ +/*! + * \internal + */ +void CanvasContext::generateMipmap(glEnums target) +{ + qCDebug(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ + << "(target:" << glEnumToString(target) + << ")"; + + if (!isValidTextureBound(target, __FUNCTION__)) + return; + + glGenerateMipmap(target); + + logAllGLErrors(__FUNCTION__); } /*! @@ -626,41 +646,16 @@ void CanvasContext::compressedTexImage2D(glEnums target, int level, glEnums inte << ", pixels:" << pixels.toString() << ")"; - if (target == TEXTURE_2D) { - if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "No current TEXTURE_2D bound"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "Currently bound TEXTURE_2D is deleted"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } - } else if (target == TEXTURE_CUBE_MAP) { - if (!m_currentTextureCubeMap) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "No current TEXTURE_CUBE_MAP bound"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } else if (!m_currentTextureCubeMap->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "Currently bound TEXTURE_CUBE_MAP is deleted"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } - } + if (!isValidTextureBound(target, __FUNCTION__)) + return; QV4::Scope scope(m_v4engine); QV4::Scoped<QV4::TypedArray> typedArray(scope, QJSValuePrivate::convertedToValue(m_v4engine, pixels)); if (typedArray) { + // Driver implementation will handle checking of texture + // properties for specific compression methods glCompressedTexImage2D(target, level, internalformat, @@ -702,41 +697,16 @@ void CanvasContext::compressedTexSubImage2D(glEnums target, int level, << ", pixels:" << pixels.toString() << ")"; - if (target == TEXTURE_2D) { - if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "No current TEXTURE_2D bound"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "Currently bound TEXTURE_2D is deleted"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } - } else if (target == TEXTURE_CUBE_MAP) { - if (!m_currentTextureCubeMap) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "No current TEXTURE_CUBE_MAP bound"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } else if (!m_currentTextureCubeMap->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "Currently bound TEXTURE_CUBE_MAP is deleted"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } - } + if (!isValidTextureBound(target, __FUNCTION__)) + return; QV4::Scope scope(m_v4engine); QV4::Scoped<QV4::TypedArray> typedArray(scope, QJSValuePrivate::convertedToValue(m_v4engine, pixels)); if (typedArray) { + // Driver implementation will handle checking of texture + // properties for specific compression methods glCompressedTexSubImage2D(target, level, xoffset, yoffset, @@ -794,20 +764,11 @@ void CanvasContext::copyTexImage2D(glEnums target, int level, glEnums internalfo << ", border:" << border << ")"; - if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "No current texture bound"; - m_error |= CANVAS_INVALID_OPERATION; - } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "Currently bound texture is deleted"; - m_error |= CANVAS_INVALID_OPERATION; - } else { - glCopyTexImage2D(target, level, internalformat, x, y, width, height, border); - logAllGLErrors(__FUNCTION__); - } + if (!isValidTextureBound(target, __FUNCTION__)) + return; + + glCopyTexImage2D(target, level, internalformat, x, y, width, height, border); + logAllGLErrors(__FUNCTION__); } /*! @@ -848,20 +809,11 @@ void CanvasContext::copyTexSubImage2D(glEnums target, int level, << ", height:" << height << ")"; - if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "No current texture bound"; - m_error |= CANVAS_INVALID_OPERATION; - } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "Currently bound texture is deleted"; - m_error |= CANVAS_INVALID_OPERATION; - } else { - copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); - logAllGLErrors(__FUNCTION__); - } + if (!isValidTextureBound(target, __FUNCTION__)) + return; + + copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); + logAllGLErrors(__FUNCTION__); } /*! @@ -910,20 +862,8 @@ void CanvasContext::texImage2D(glEnums target, int level, glEnums internalformat << ", type:" << glEnumToString(type) << ", pixels:" << pixels.toString() << ")"; - if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" - << __FUNCTION__ - << ":INVALID_OPERATION:" - << "No current texture bound"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "Currently bound texture is deleted"; - m_error |= CANVAS_INVALID_OPERATION; + if (!isValidTextureBound(target, __FUNCTION__)) return; - } int bytesPerPixel = 0; uchar *srcData = 0; @@ -1098,18 +1038,9 @@ void CanvasContext::texSubImage2D(glEnums target, int level, << ", type:" << glEnumToString(type) << ", pixels:" << pixels.toString() << ")"; - if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:No current texture bound"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "Currently bound texture is deleted"; - m_error |= CANVAS_INVALID_OPERATION; + + if (!isValidTextureBound(target, __FUNCTION__)) return; - } if (pixels.isNull()) { qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ @@ -1276,19 +1207,8 @@ void CanvasContext::texImage2D(glEnums target, int level, glEnums internalformat << ", texImage:" << texImage.toString() << ")"; - if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "No current texture bound"; - m_error |= CANVAS_INVALID_OPERATION; + if (!isValidTextureBound(target, __FUNCTION__)) return; - } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "Currently bound texture is deleted"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } CanvasTextureImage *image = getAsTextureImage(texImage); if (!image) { @@ -1383,18 +1303,8 @@ void CanvasContext::texSubImage2D(glEnums target, int level, << ", texImage:" << texImage.toString() << ")"; - if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:No current texture bound"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "Currently bound texture is deleted"; - m_error |= CANVAS_INVALID_OPERATION; + if (!isValidTextureBound(target, __FUNCTION__)) return; - } CanvasTextureImage *image = getAsTextureImage(texImage); if (!image) { @@ -1458,18 +1368,8 @@ void CanvasContext::texParameterf(glEnums target, glEnums pname, float param) << ", param:" << param << ")"; - if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:No current texture bound"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << " Currently bound texture is deleted"; - m_error |= CANVAS_INVALID_OPERATION; + if (!isValidTextureBound(target, __FUNCTION__)) return; - } glTexParameterf(GLenum(target), GLenum(pname), GLfloat(param)); logAllGLErrors(__FUNCTION__); @@ -1495,18 +1395,9 @@ void CanvasContext::texParameteri(glEnums target, glEnums pname, int param) << ", pname:" << glEnumToString(pname) << ", param:" << glEnumToString(glEnums(param)) << ")"; - if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:No current texture bound"; - m_error |= CANVAS_INVALID_OPERATION; - return; - } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << " Currently bound texture is deleted"; - m_error |= CANVAS_INVALID_OPERATION; + + if (!isValidTextureBound(target, __FUNCTION__)) return; - } glTexParameteri(GLenum(target), GLenum(pname), GLint(param)); logAllGLErrors(__FUNCTION__); @@ -1536,6 +1427,9 @@ int CanvasContext::getSufficientSize(glEnums internalFormat, int width, int heig break; } + width = (width > 0) ? width : 0; + height = (height > 0) ? height : 0; + return width * height * bytesPerPixel; } @@ -1613,14 +1507,7 @@ CanvasContext::glEnums CanvasContext::checkFramebufferStatus(glEnums target) return FRAMEBUFFER_UNSUPPORTED; } - if (m_currentFramebuffer) { - return glEnums(glCheckFramebufferStatus(GL_FRAMEBUFFER)); - } else { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ": INVALID_OPERATION no current framebuffer bound"; - m_error |= CANVAS_INVALID_OPERATION; - return FRAMEBUFFER_UNSUPPORTED; - } + return glEnums(glCheckFramebufferStatus(GL_FRAMEBUFFER)); } /*! @@ -1640,20 +1527,21 @@ void CanvasContext::framebufferRenderbuffer(glEnums target, glEnums attachment, qCDebug(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ << "(target:" << glEnumToString(target) << "attachment:" << glEnumToString(attachment) - << "renderbuffertarget:" << glEnumToString(renderbuffertarget) + << "renderbuffertarget:" + << glEnumToString(renderbuffertarget) << ", renderbuffer3D:" << renderbuffer3D.toString() << ")"; if (target != FRAMEBUFFER) { qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ": INVALID_ENUM bind target, must be FRAMEBUFFER"; + << ": INVALID_ENUM:bind target, must be FRAMEBUFFER"; m_error |= CANVAS_INVALID_ENUM; return; } if (!m_currentFramebuffer) { qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << "(): INVALID_OPERATION no framebuffer bound"; + << "(): INVALID_OPERATION:no framebuffer bound"; m_error |= CANVAS_INVALID_OPERATION; return; } @@ -1663,7 +1551,7 @@ void CanvasContext::framebufferRenderbuffer(glEnums target, glEnums attachment, && attachment != STENCIL_ATTACHMENT && attachment != DEPTH_STENCIL_ATTACHMENT) { qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << "(): INVALID_OPERATION attachment must be one of " + << "(): INVALID_OPERATION:attachment must be one of " << "COLOR_ATTACHMENT0, DEPTH_ATTACHMENT, " << "STENCIL_ATTACHMENT or DEPTH_STENCIL_ATTACHMENT"; m_error |= CANVAS_INVALID_OPERATION; @@ -3682,7 +3570,7 @@ int CanvasContext::getShaderParameter(QJSValue shader3D, glEnums pname) return (isCompiled ? GL_TRUE : GL_FALSE); } default: { - qCWarning(canvas3drendering).nospace() << "getShaderParameter() : UNSUPPORTED parameter name " + qCWarning(canvas3drendering).nospace() << "getShaderParameter():UNSUPPORTED parameter name " << glEnumToString(pname); return 0; } @@ -3727,7 +3615,7 @@ QJSValue CanvasContext::getUniformLocation(QJSValue program3D, const QString &na << ", name:" << name << "):-1"; qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << "WARNING: Invalid Program3D reference " << program; + << "WARNING:Invalid Program3D reference " << program; return 0; } @@ -4146,14 +4034,16 @@ void CanvasContext::vertexAttribPointer(int indx, int size, glEnums type, if (offset % 4 != 0) { qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ << ":INVALID_OPERATION:" - << "offset with FLOAT type must be multiple of 4"; + << "offset with FLOAT type " + << "must be multiple of 4"; m_error |= CANVAS_INVALID_OPERATION; return; } if (stride % 4 != 0) { qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ << ":INVALID_OPERATION:" - << "stride with FLOAT type must be multiple of 4"; + << "stride with FLOAT type must " + << "be multiple of 4"; m_error |= CANVAS_INVALID_OPERATION; return; } @@ -4864,17 +4754,21 @@ QJSValue CanvasContext::getShaderInfoLog(QJSValue shader3D) const /*! * \internal */ -QString CanvasContext::getProgramInfoLog(QJSValue program3D) const +QJSValue CanvasContext::getProgramInfoLog(QJSValue program3D) const { qCDebug(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ << "(program3D:" << program3D.toString() << ")"; CanvasProgram *program = getAsProgram3D(program3D); - if (!program) - return QString(); + if (!program) { + qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ + << "WARNING: invalid program handle:" + << program3D.toString(); + return m_engine->newObject(); + } - return program->log(); + return QJSValue(program->log()); } /*! @@ -4985,7 +4879,7 @@ void CanvasContext::useProgram(QJSValue program3D) */ void CanvasContext::clear(glEnums flags) { - if (!((QLoggingCategory &) canvas3drendering()).isDebugEnabled()) { + if (!canvas3drendering().isDebugEnabled()) { QString flagStr; if (flags && COLOR_BUFFER_BIT != 0) flagStr.append(" COLOR_BUFFER_BIT "); @@ -5738,17 +5632,7 @@ QVariant CanvasContext::getTexParameter(glEnums target, glEnums pname) << ")"; GLint parameter = 0; - if (!m_currentTexture2D) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:" - << "No current texture bound"; - m_error |= CANVAS_INVALID_OPERATION; - } else if (!m_currentTexture2D->isAlive()) { - qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ - << ":INVALID_OPERATION:Currently" - << " bound texture is deleted"; - m_error |= CANVAS_INVALID_OPERATION; - } else { + if (isValidTextureBound(target, __FUNCTION__)) { switch (pname) { case TEXTURE_MAG_FILTER: // Intentional flow through @@ -6151,6 +6035,12 @@ QVariantList CanvasContext::getSupportedExtensions() list.append(QVariant::fromValue(QStringLiteral("OES_standard_derivatives"))); } + if (m_extensions.contains("GL_EXT_texture_compression_s3tc")) + list.append(QVariant::fromValue(QStringLiteral("WEBGL_compressed_texture_s3tc"))); + + if (m_extensions.contains("IMG_texture_compression_pvrtc")) + list.append(QVariant::fromValue(QStringLiteral("WEBGL_compressed_texture_pvrtc"))); + return list; } @@ -6197,10 +6087,21 @@ QVariant CanvasContext::getExtension(const QString &name) if (!m_stateDumpExt) m_stateDumpExt = new CanvasGLStateDump(m_context, this); return QVariant::fromValue(m_stateDumpExt); - } else if (upperCaseName == QStringLiteral("OES_STANDARD_DERIVATIVES")) { + } else if (upperCaseName == QStringLiteral("OES_STANDARD_DERIVATIVES") && + m_extensions.contains("OES_standard_derivatives")) { if (!m_standardDerivatives) m_standardDerivatives = new QObject(this); return QVariant::fromValue(m_standardDerivatives); + } else if (upperCaseName == QStringLiteral("WEBGL_COMPRESSED_TEXTURE_S3TC") && + m_extensions.contains("GL_EXT_texture_compression_s3tc")) { + if (!m_compressedTextureS3TC) + m_compressedTextureS3TC = new CompressedTextureS3TC(this); + return QVariant::fromValue(m_compressedTextureS3TC); + } else if (upperCaseName == QStringLiteral("WEBGL_COMPRESSED_TEXTURE_PVRTC") && + m_extensions.contains("IMG_texture_compression_pvrtc")) { + if (!m_compressedTexturePVRTC) + m_compressedTexturePVRTC = new CompressedTexturePVRTC(this); + return QVariant::fromValue(m_compressedTexturePVRTC); } return QVariant(QVariant::Int); diff --git a/src/context3d_p.h b/src/imports/qtcanvas3d/context3d_p.h similarity index 98% rename from src/context3d_p.h rename to src/imports/qtcanvas3d/context3d_p.h index 9b2364ce4921d1ad237a2f6af58cb0f9edff8723..486b3bfde4f4919af6b8ff8e01b877f2eb775d0c 100644 --- a/src/context3d_p.h +++ b/src/imports/qtcanvas3d/context3d_p.h @@ -70,7 +70,7 @@ QT_BEGIN_NAMESPACE QT_CANVAS3D_BEGIN_NAMESPACE -#define ENUM_AS_PROPERTY(A) Q_PROPERTY(QtCanvas3D::CanvasContext::glEnums A READ A ## _read); inline QtCanvas3D::CanvasContext::glEnums A ## _read() { return CanvasContext::A; } +#define ENUM_AS_PROPERTY(A) Q_PROPERTY(QtCanvas3D::CanvasContext::glEnums A READ A ## _read); inline QtCanvas3D::CanvasContext::glEnums A ## _read() { return QtCanvas3D::CanvasContext::A; } class Canvas; class CanvasActiveInfo; @@ -84,7 +84,8 @@ class CanvasUniformLocation; class CanvasTextureImage; class CanvasShaderPrecisionFormat; class EnumToStringMap; - +class CompressedTextureS3TC; +class CompressedTexturePVRTC; class QT_CANVAS3D_EXPORT CanvasContext : public CanvasAbstractObject, protected QOpenGLFunctions { @@ -527,7 +528,19 @@ public: /* WEBGL_debug_renderer_info */ UNMASKED_VENDOR_WEBGL = 0x9245, - UNMASKED_RENDERER_WEBGL = 0x9246 + UNMASKED_RENDERER_WEBGL = 0x9246, + + /* S3TC */ + COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0, + COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1, + COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2, + COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3, + + /* PVRTC */ + COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00, + COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01, + COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02, + COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03 }; /* ClearBufferMask */ @@ -1071,7 +1084,7 @@ public: const QString &name); Q_INVOKABLE int getAttribLocation(QJSValue program, const QString &name); Q_INVOKABLE void bindAttribLocation(QJSValue program, int index, const QString &name); - Q_INVOKABLE QString getProgramInfoLog(QJSValue program) const; + Q_INVOKABLE QJSValue getProgramInfoLog(QJSValue program) const; Q_INVOKABLE bool isProgram(QJSValue anyObject) const; Q_INVOKABLE void deleteProgram(QJSValue program); @@ -1214,6 +1227,8 @@ private: bool isOfType(const QJSValue &value, const QString &classname) const; + bool isValidTextureBound(glEnums target, const QString &funcName); + typedef enum { CANVAS_NO_ERRORS = 0, CANVAS_INVALID_ENUM = 1 << 0, @@ -1264,6 +1279,8 @@ private: // EXTENSIONS CanvasGLStateDump *m_stateDumpExt; QObject *m_standardDerivatives; + CompressedTextureS3TC *m_compressedTextureS3TC; + CompressedTexturePVRTC *m_compressedTexturePVRTC; }; QT_CANVAS3D_END_NAMESPACE diff --git a/src/contextattributes.cpp b/src/imports/qtcanvas3d/contextattributes.cpp similarity index 99% rename from src/contextattributes.cpp rename to src/imports/qtcanvas3d/contextattributes.cpp index 3769a2356a89d3a3ac4df204e3a241e4e0195005..e03c8cc3684b3bf53ed8db42b1b8a43da38d3329 100644 --- a/src/contextattributes.cpp +++ b/src/imports/qtcanvas3d/contextattributes.cpp @@ -45,7 +45,7 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! * \qmltype ContextAttributes * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Attribute set for Context3D * * ContextAttributes is an attribute set that can be given as parameter on first call to @@ -53,7 +53,7 @@ QT_CANVAS3D_BEGIN_NAMESPACE * method call. It can also be requested from the Context3D later on to verify what exact * attributes are in fact enabled/disabled in the created context. * - * \sa Context3D, Canvas3D, {QtCanvas3D QML Types} + * \sa Context3D, Canvas3D */ /*! diff --git a/src/contextattributes_p.h b/src/imports/qtcanvas3d/contextattributes_p.h similarity index 100% rename from src/contextattributes_p.h rename to src/imports/qtcanvas3d/contextattributes_p.h diff --git a/src/designer/default/Canvas3D.qml b/src/imports/qtcanvas3d/designer/default/Canvas3D.qml similarity index 100% rename from src/designer/default/Canvas3D.qml rename to src/imports/qtcanvas3d/designer/default/Canvas3D.qml diff --git a/src/designer/designer.pri b/src/imports/qtcanvas3d/designer/designer.pri similarity index 100% rename from src/designer/designer.pri rename to src/imports/qtcanvas3d/designer/designer.pri diff --git a/src/designer/images/canvas3d-icon.png b/src/imports/qtcanvas3d/designer/images/canvas3d-icon.png similarity index 100% rename from src/designer/images/canvas3d-icon.png rename to src/imports/qtcanvas3d/designer/images/canvas3d-icon.png diff --git a/src/designer/images/canvas3d-icon16.png b/src/imports/qtcanvas3d/designer/images/canvas3d-icon16.png similarity index 100% rename from src/designer/images/canvas3d-icon16.png rename to src/imports/qtcanvas3d/designer/images/canvas3d-icon16.png diff --git a/src/designer/qtcanvas3d.metainfo b/src/imports/qtcanvas3d/designer/qtcanvas3d.metainfo similarity index 100% rename from src/designer/qtcanvas3d.metainfo rename to src/imports/qtcanvas3d/designer/qtcanvas3d.metainfo diff --git a/src/doc/qtcanvas3d.qdocconf b/src/imports/qtcanvas3d/doc/qtcanvas3d.qdocconf similarity index 66% rename from src/doc/qtcanvas3d.qdocconf rename to src/imports/qtcanvas3d/doc/qtcanvas3d.qdocconf index 3851fb96023f626c84131541c6d7a903a4bf5029..7e8942c8ddf7ae371a9a9182cf1aefadf1ecc78c 100644 --- a/src/doc/qtcanvas3d.qdocconf +++ b/src/imports/qtcanvas3d/doc/qtcanvas3d.qdocconf @@ -4,7 +4,7 @@ project = QtCanvas3D description = QtCanvas3D Reference Documentation version = 1.0.0 -exampledirs = ../../examples/canvas3d \ +exampledirs = ../../../../examples/canvas3d \ snippets imagedirs += images @@ -13,37 +13,34 @@ sourcedirs += .. examplesinstallpath = canvas3d -indexes += $QT_INSTALL_DOCS/qtcore/qtcore.index \ - $QT_INSTALL_DOCS/qtgui/qtgui.index \ - $QT_INSTALL_DOCS/qtqml/qtqml.index \ - $QT_INSTALL_DOCS/qtquick/qtquick.index \ - $QT_INSTALL_DOCS/qtmultimedia/qtmultimedia.index +depends = qtcore qtgui qtqml qtquick qtquickcontrols qtquicklayouts qtdoc qtmultimedia qhp.projects = QtCanvas3D qhp.QtCanvas3D.file = qtcanvas3d.qhp qhp.QtCanvas3D.namespace = org.qt-project.qtcanvas3d.100 qhp.QtCanvas3D.virtualFolder = qtcanvas3d -qhp.QtCanvas3D.indexTitle = QML 3D Canvas +qhp.QtCanvas3D.indexTitle = Qt Canvas 3D qhp.QtCanvas3D.indexRoot = + qhp.QtCanvas3D.filterAttributes = qtcanvas3d 1.0.0 qtrefdoc qhp.QtCanvas3D.customFilters.Qt.name = QtCanvas3D 1.0.0 qhp.QtCanvas3D.customFilters.Qt.filterAttributes = qtcanvas3d 1.0.0 qhp.QtCanvas3D.subprojects = gettingstarted examples types qhp.QtCanvas3D.subprojects.gettingstarted.title = Getting Started -qhp.QtCanvas3D.subprojects.gettingstarted.indexTitle = QtCanvas3D Getting Started +qhp.QtCanvas3D.subprojects.gettingstarted.indexTitle = Qt Canvas 3D Getting Started qhp.QtCanvas3D.subprojects.gettingstarted.selectors = fake:page qhp.QtCanvas3D.subprojects.gettingstarted.sortPages = true qhp.QtCanvas3D.subprojects.examples.title = Examples -qhp.QtCanvas3D.subprojects.examples.indexTitle = QtCanvas3D Examples +qhp.QtCanvas3D.subprojects.examples.indexTitle = Qt Canvas 3D Examples qhp.QtCanvas3D.subprojects.examples.selectors = fake:example qhp.QtCanvas3D.subprojects.examples.sortPages = true qhp.QtCanvas3D.subprojects.types.title = QML Types -qhp.QtCanvas3D.subprojects.types.indexTitle = QtCanvas3D QML Types +qhp.QtCanvas3D.subprojects.types.indexTitle = Qt Canvas 3D QML Types qhp.QtCanvas3D.subprojects.types.selectors = qmlclass qhp.QtCanvas3D.subprojects.types.sortPages = true -navigation.landingpage = QtCanvas3D -navigation.qmltypespage = QtCanvas3D QML Types -navigation.examplespage = QtCanvas3D Examples +navigation.landingpage = Qt Canvas 3D +navigation.qmltypespage = Qt Canvas 3D QML Types +navigation.examplespage = Qt Canvas 3D Examples diff --git a/src/doc/snippets/doc_src_qtcanvas3d.cpp b/src/imports/qtcanvas3d/doc/snippets/doc_src_qtcanvas3d.cpp similarity index 100% rename from src/doc/snippets/doc_src_qtcanvas3d.cpp rename to src/imports/qtcanvas3d/doc/snippets/doc_src_qtcanvas3d.cpp diff --git a/src/doc/snippets/doc_src_qtcanvas3d.pro b/src/imports/qtcanvas3d/doc/snippets/doc_src_qtcanvas3d.pro similarity index 100% rename from src/doc/snippets/doc_src_qtcanvas3d.pro rename to src/imports/qtcanvas3d/doc/snippets/doc_src_qtcanvas3d.pro diff --git a/src/doc/src/qtcanvas3d-index.qdoc b/src/imports/qtcanvas3d/doc/src/qtcanvas3d-index.qdoc similarity index 76% rename from src/doc/src/qtcanvas3d-index.qdoc rename to src/imports/qtcanvas3d/doc/src/qtcanvas3d-index.qdoc index 8a77acf8724e2740cba8c2a8edce93b8cae1bf5d..85205703c6f8397d9336100f71aa8f31822880ec 100644 --- a/src/doc/src/qtcanvas3d-index.qdoc +++ b/src/imports/qtcanvas3d/doc/src/qtcanvas3d-index.qdoc @@ -35,35 +35,36 @@ ****************************************************************************/ /*! - \title QtCanvas3D + \title Qt Canvas 3D \page qtcanvas3d-index.html \brief Provides functionality for 3D drawing inside Qt Quick 2. - QtCanvas3D module provides a way to make OpenGL-like 3D drawing calls from Qt Quick JavaScript. + Qt Canvas 3D module provides a way to make OpenGL-like 3D drawing calls + from Qt Quick JavaScript. \section1 Features \list - \li Uses OpenGL or OpenGL ES2 for rendering. - \li Qt Quick 2 support + \li Uses OpenGL or OpenGL ES 2 for rendering. + \li Qt Quick 2 support. \endlist \section1 Getting Started - To import QtCanvas3D QML types, add the following import statement to your \c .qml - file: + To import Qt Canvas 3D QML types, add the following import statement to + your \c .qml file: \snippet doc_src_qtcanvas3d.cpp 0 - See the \l{QtCanvas3D Getting Started}{Getting started} page for further information on - how to use QtCanvas3D in your application. + See the \l{Qt Canvas 3D Getting Started}{Getting Started} page for further + information on how to use Qt Canvas 3D in your application. \section1 References \list - \li \l{QtCanvas3D QML Types} - \li \l{QtCanvas3D Examples} - \li \l {QtCanvas3D Logging} + \li \l{Qt Canvas 3D Getting Started} + \li \l{Qt Canvas 3D QML Types} + \li \l{Qt Canvas 3D Examples} + \li \l{Qt Canvas 3D Logging} \endlist - */ diff --git a/src/doc/src/qtcanvas3d.qdoc b/src/imports/qtcanvas3d/doc/src/qtcanvas3d.qdoc similarity index 57% rename from src/doc/src/qtcanvas3d.qdoc rename to src/imports/qtcanvas3d/doc/src/qtcanvas3d.qdoc index 61bd4b31298fb134233170d0f44ffe9b46edda68..643fa981b4a4cc7d34652bcad0eb75d172622f7a 100644 --- a/src/doc/src/qtcanvas3d.qdoc +++ b/src/imports/qtcanvas3d/doc/src/qtcanvas3d.qdoc @@ -36,40 +36,34 @@ /*! \qmlmodule QtCanvas3D 1.0 - \title QtCanvas3D QML Types + \title Qt Canvas 3D QML Types \ingroup qmlmodules - \brief QML types for the QtCanvas3D API. + \brief QML types for the Qt Canvas 3D API. - The QtCanvas3D functionality can be accessed via these QML types. - - \section1 QML Types - - \annotatedlist qtcanvas3d-qml-types + The Qt Canvas 3D functionality can be accessed via these QML types. */ /*! \group qtcanvas3d-examples \ingroup all-examples - \title QtCanvas3D Examples - - \brief Examples for the QtCanvas3D. + \title Qt Canvas 3D Examples - For some code examples, see one of the QtCanvas3D examples: - - \section1 Examples + \brief Examples for the Qt Canvas 3D module. */ /*! - \group qtcanvas3d-getting-started - \title QtCanvas3D Getting Started + \page qtcanvas3d-getting-started.html + \title Qt Canvas 3D Getting Started + + \section1 Building Qt Canvas 3D - \section1 Building QtCanvas3D + To build the Qt Canvas 3D module from source code, set up a command prompt + with an environment for building Qt applications, navigate to the + directory containing \c {qtcanvas3d.pro}, and configure the project with + qmake: - To build the QtCanvas3D module from source code, set up a command prompt - with an environment for building Qt applications, navigate to the directory containing - \c {qtcanvas3d.pro}, and configure the project with qmake: - \code + \badcode qmake \endcode @@ -87,94 +81,104 @@ \li OSX \li make \endtable - The above generates the default makefiles for your configuration, which is typically - the release build if you are using precompiled binary Qt distribution. To build both debug - and release, or one specifically, use one of the following qmake lines instead. + The above generates the default makefiles for your configuration, which is + typically the release build if you are using precompiled binary Qt + distribution. To build both debug and release, or one specifically, use + one of the following qmake lines instead. For debug builds: - \code + \badcode qmake CONFIG+=debug make \endcode or - \code + \badcode qmake CONFIG+=debug_and_release make debug \endcode For release builds: - \code + \badcode qmake CONFIG+=release make \endcode or - \code + \badcode qmake CONFIG+=debug_and_release make release \endcode For both builds (Windows/Mac only): - \code + \badcode qmake CONFIG+="debug_and_release build_all" make \endcode After building, install the module to your Qt directory: - \code + \badcode make install \endcode If you want to uninstall the module: - \code + \badcode make uninstall \endcode - To build a statically linked version of the QtCanvas3D module, give the following - commands: + To build a statically linked version of the QtCanvas3D module, give the + following commands: - \code + \badcode qmake CONFIG+=static make make install \endcode - \section1 Running examples + \section1 Running the Examples - QtCanvas3D examples are found under the \c examples subdirectory. To build and run a - single example, in this case \c{interaction}, navigate to the example directory and enter the + Examples for Qt Canvas 3D are found under the \c examples/canvas3d + subdirectory. To build and run a single example, in this case + \c{interaction}, navigate to the example directory and enter the following commands: - \code + \badcode qmake make ./interaction \endcode - \note On some platforms, such as Windows, the executable can be generated under debug or - release folders, depending on your build. + \note On some platforms, such as Windows, the executable can be generated + under \c debug or \c release folders, depending on your build. \section1 A Basic Example - For a simple Canvas3D example see the \l {Lit and Textured Cube Example}. + For a simple Canvas3D example, see the \l {Lit and Textured Cube Example}. - For all the QtCanvas3D examples, check out \l {QtCanvas3D Examples} + For all examples, check out \l {Qt Canvas 3D Examples}. */ /*! - \group qtcanvas3d-logging - \title QtCanvas3D Logging - - \brief The logging features in QtCanvas3D. - - Logging in QtCanvas3D uses the Qt categorized logging. The following categories are supported: - - \list - \li "qt.canvas3d.info.debug" Logs on high level information about the OpenGL driver. - \li "qt.canvas3d.rendering.debug" Logs all the method calls in QtCanvas3D. - \li "qt.canvas3d.rendering.warning" Logs all warnings on from QtCanvas3D internal verifications - that happen before a OpenGL method call is made to the actual graphics driver. - \li "qt.canvas3d.glerrors.debug" Logs all the OpenGL driver level errors. This entails calling - \c{glGetError()} after each OpenGL driver call and this will cause a negative performance - hit. Please use only when necessary to find root causes of rendering errors. - \endlist + \page qtcanvas3d-logging.html + \title Qt Canvas 3D Logging + + \brief The logging features in Qt Canvas 3D. + + Qt Canvas 3D makes use of Qt's \l {QLoggingCategory}{categorized logging}. + The following categories are supported: + + \table + \header \li Category \li Description + \row \li \c qt.canvas3d.info.debug + \li Logs on high level information about the OpenGL driver. + \row \li \c qt.canvas3d.rendering.debug + \li Logs all the method calls in Qt Canvas 3D. + \row \li \c qt.canvas3d.rendering.warning + \li Logs all warnings on from Qt Canvas 3D internal verifications + that happen before a OpenGL method call is made to the actual + graphics driver. + \row \li \c qt.canvas3d.glerrors.debug + \li Logs all the OpenGL driver level errors. This entails calling + \c{glGetError()} after each OpenGL driver call and this will + cause a negative performance hit. Please use only when necessary + to find root causes of rendering errors. + \endtable */ diff --git a/src/enumtostringmap.cpp b/src/imports/qtcanvas3d/enumtostringmap.cpp similarity index 100% rename from src/enumtostringmap.cpp rename to src/imports/qtcanvas3d/enumtostringmap.cpp diff --git a/src/enumtostringmap_p.h b/src/imports/qtcanvas3d/enumtostringmap_p.h similarity index 100% rename from src/enumtostringmap_p.h rename to src/imports/qtcanvas3d/enumtostringmap_p.h diff --git a/src/framebuffer3d.cpp b/src/imports/qtcanvas3d/framebuffer3d.cpp similarity index 98% rename from src/framebuffer3d.cpp rename to src/imports/qtcanvas3d/framebuffer3d.cpp index 742ea9a4040b01ff42090f93186373bc0c72d975..c2a67a7ea2d1d18e380fe2660cfed670784d4f39 100644 --- a/src/framebuffer3d.cpp +++ b/src/imports/qtcanvas3d/framebuffer3d.cpp @@ -42,7 +42,7 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! * \qmltype FrameBuffer3D * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Contains an OpenGL framebuffer. * * An uncreatable QML type that contains an OpenGL framebuffer object. You can get it by calling diff --git a/src/framebuffer3d_p.h b/src/imports/qtcanvas3d/framebuffer3d_p.h similarity index 100% rename from src/framebuffer3d_p.h rename to src/imports/qtcanvas3d/framebuffer3d_p.h diff --git a/src/plugins.qmltypes b/src/imports/qtcanvas3d/plugins.qmltypes similarity index 98% rename from src/plugins.qmltypes rename to src/imports/qtcanvas3d/plugins.qmltypes index 81f0ad4f327e0908e3ee82ea563f84a0e0e53fcc..30a8cac1b4c5ed2dd260266b72fb44bd883f6d77 100644 --- a/src/plugins.qmltypes +++ b/src/imports/qtcanvas3d/plugins.qmltypes @@ -16,6 +16,7 @@ Module { Property { name: "context"; type: "CanvasContext"; isReadonly: true; isPointer: true } Property { name: "devicePixelRatio"; type: "float"; isReadonly: true } Property { name: "fps"; type: "uint"; isReadonly: true } + Property { name: "pixelSize"; type: "QSize" } Signal { name: "needRender" } Signal { name: "devicePixelRatioChanged" @@ -25,14 +26,6 @@ Module { name: "animatedChanged" Parameter { name: "animated"; type: "bool" } } - Signal { - name: "logAllCallsChanged" - Parameter { name: "logCalls"; type: "bool" } - } - Signal { - name: "logAllErrorsChanged" - Parameter { name: "logErrors"; type: "bool" } - } Signal { name: "contextChanged" Parameter { name: "context"; type: "CanvasContext"; isPointer: true } @@ -41,8 +34,18 @@ Module { name: "fpsChanged" Parameter { name: "fps"; type: "uint" } } + Signal { + name: "pixelSizeChanged" + Parameter { name: "pixelSize"; type: "QSize" } + } Signal { name: "initGL" } Signal { name: "renderGL" } + Signal { + name: "resizeGL" + Parameter { name: "width"; type: "int" } + Parameter { name: "height"; type: "int" } + Parameter { name: "devicePixelRatio"; type: "float" } + } Signal { name: "textureReady" Parameter { name: "id"; type: "int" } @@ -52,6 +55,8 @@ Module { Method { name: "ready" } Method { name: "shutDown" } Method { name: "renderNext" } + Method { name: "emitResizeGL" } + Method { name: "emitNeedRender" } Method { name: "getContext" type: "QJSValue" @@ -412,7 +417,15 @@ Module { "UNPACK_COLORSPACE_CONVERSION_WEBGL": 37443, "BROWSER_DEFAULT_WEBGL": 37444, "UNMASKED_VENDOR_WEBGL": 37445, - "UNMASKED_RENDERER_WEBGL": 37446 + "UNMASKED_RENDERER_WEBGL": 37446, + "COMPRESSED_RGB_S3TC_DXT1_EXT": 33776, + "COMPRESSED_RGBA_S3TC_DXT1_EXT": 33777, + "COMPRESSED_RGBA_S3TC_DXT3_EXT": 33778, + "COMPRESSED_RGBA_S3TC_DXT5_EXT": 33779, + "COMPRESSED_RGB_PVRTC_4BPPV1_IMG": 35840, + "COMPRESSED_RGB_PVRTC_2BPPV1_IMG": 35841, + "COMPRESSED_RGBA_PVRTC_4BPPV1_IMG": 35842, + "COMPRESSED_RGBA_PVRTC_2BPPV1_IMG": 35843 } } Property { name: "canvas"; type: "Canvas"; isReadonly: true; isPointer: true } @@ -1663,7 +1676,7 @@ Module { } Method { name: "getProgramInfoLog" - type: "string" + type: "QJSValue" Parameter { name: "program"; type: "QJSValue" } } Method { diff --git a/src/program3d.cpp b/src/imports/qtcanvas3d/program3d.cpp similarity index 99% rename from src/program3d.cpp rename to src/imports/qtcanvas3d/program3d.cpp index 6ab8ecb3592073b085ead8863313a5a7747a2ee1..2472ddc3102209ff4e1e14c6a6b86975b85e3103 100644 --- a/src/program3d.cpp +++ b/src/imports/qtcanvas3d/program3d.cpp @@ -42,7 +42,7 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! * \qmltype Program3D * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Contains a shader program. * * An uncreatable QML type that contains a compiled shader program. You can get it by calling diff --git a/src/program3d_p.h b/src/imports/qtcanvas3d/program3d_p.h similarity index 100% rename from src/program3d_p.h rename to src/imports/qtcanvas3d/program3d_p.h diff --git a/src/qcanvas3d_plugin.cpp b/src/imports/qtcanvas3d/qcanvas3d_plugin.cpp similarity index 100% rename from src/qcanvas3d_plugin.cpp rename to src/imports/qtcanvas3d/qcanvas3d_plugin.cpp diff --git a/src/qcanvas3d_plugin.h b/src/imports/qtcanvas3d/qcanvas3d_plugin.h similarity index 100% rename from src/qcanvas3d_plugin.h rename to src/imports/qtcanvas3d/qcanvas3d_plugin.h diff --git a/src/qmldir b/src/imports/qtcanvas3d/qmldir similarity index 100% rename from src/qmldir rename to src/imports/qtcanvas3d/qmldir diff --git a/src/imports/qtcanvas3d/qtcanvas3d.pro b/src/imports/qtcanvas3d/qtcanvas3d.pro new file mode 100644 index 0000000000000000000000000000000000000000..2ff4155ad651872a70cd4be626e5b08b6b21089b --- /dev/null +++ b/src/imports/qtcanvas3d/qtcanvas3d.pro @@ -0,0 +1,64 @@ +QT += openglextensions qml quick qml-private core-private +DEFINES += QTCANVAS3D_LIBRARY +TARGETPATH = QtCanvas3D +IMPORT_VERSION = $$MODULE_VERSION + +include($$PWD/designer/designer.pri) + +QMAKE_DOCS = $$PWD/doc/qtcanvas3d.qdocconf + +SOURCES += arrayutils.cpp \ + qcanvas3d_plugin.cpp \ + enumtostringmap.cpp \ + abstractobject3d.cpp \ + canvas3d.cpp \ + buffer3d.cpp \ + canvasrendernode.cpp \ + context3d.cpp \ + contextattributes.cpp \ + framebuffer3d.cpp \ + program3d.cpp \ + renderbuffer3d.cpp \ + shader3d.cpp \ + shaderprecisionformat.cpp \ + teximage3d.cpp \ + texture3d.cpp \ + uniformlocation.cpp \ + activeinfo3d.cpp \ + canvasglstatedump.cpp \ + compressedtextures3tc.cpp \ + compressedtexturepvrtc.cpp + +HEADERS += arrayutils_p.h \ + qcanvas3d_plugin.h \ + enumtostringmap_p.h \ + abstractobject3d_p.h \ + canvas3d_p.h \ + buffer3d_p.h \ + canvas3dcommon_p.h \ + canvasrendernode_p.h \ + context3d_p.h \ + contextattributes_p.h \ + framebuffer3d_p.h \ + program3d_p.h \ + renderbuffer3d_p.h \ + shader3d_p.h \ + shaderprecisionformat_p.h \ + teximage3d_p.h \ + texture3d_p.h \ + uniformlocation_p.h \ + activeinfo3d_p.h \ + canvasglstatedump_p.h \ + compressedtextures3tc_p.h \ + compressedtexturepvrtc_p.h + +OTHER_FILES = qmldir \ + doc/* \ + doc/src/* \ + doc/images/* \ + doc/snippets/* \ + designer/default/* + +CONFIG += no_cxx_module + +load(qml_plugin) diff --git a/src/renderbuffer3d.cpp b/src/imports/qtcanvas3d/renderbuffer3d.cpp similarity index 98% rename from src/renderbuffer3d.cpp rename to src/imports/qtcanvas3d/renderbuffer3d.cpp index 8a4cb6db407fe4c86d10b17f75753e704bc355a6..ceac4f239eaeae9a0197b3f50c1b4f1fb53938e3 100644 --- a/src/renderbuffer3d.cpp +++ b/src/imports/qtcanvas3d/renderbuffer3d.cpp @@ -42,7 +42,7 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! * \qmltype RenderBuffer3D * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Contains an OpenGL renderbuffer. * * An uncreatable QML type that contains an OpenGL renderbuffer. You can get it by calling diff --git a/src/renderbuffer3d_p.h b/src/imports/qtcanvas3d/renderbuffer3d_p.h similarity index 100% rename from src/renderbuffer3d_p.h rename to src/imports/qtcanvas3d/renderbuffer3d_p.h diff --git a/src/shader3d.cpp b/src/imports/qtcanvas3d/shader3d.cpp similarity index 98% rename from src/shader3d.cpp rename to src/imports/qtcanvas3d/shader3d.cpp index afc8026a47172631de9737a020073bf3c342d6c9..39ff3c06dc99efa9bfad029025a08bdd2f1cac10 100644 --- a/src/shader3d.cpp +++ b/src/imports/qtcanvas3d/shader3d.cpp @@ -42,7 +42,7 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! * \qmltype Shader3D * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Contains a shader. * * An uncreatable QML type that contains a shader. You can get it by calling diff --git a/src/shader3d_p.h b/src/imports/qtcanvas3d/shader3d_p.h similarity index 100% rename from src/shader3d_p.h rename to src/imports/qtcanvas3d/shader3d_p.h diff --git a/src/shaderprecisionformat.cpp b/src/imports/qtcanvas3d/shaderprecisionformat.cpp similarity index 97% rename from src/shaderprecisionformat.cpp rename to src/imports/qtcanvas3d/shaderprecisionformat.cpp index b328ff0980e9fcdca360f12da1fc293c4e784d88..5c320121d49c4a59d16f2afdace75413c408721c 100644 --- a/src/shaderprecisionformat.cpp +++ b/src/imports/qtcanvas3d/shaderprecisionformat.cpp @@ -42,13 +42,13 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! * \qmltype ShaderPrecisionFormat * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Contains the shader precision format attributes. * * An uncreatable QML type that contains the information returned from the * \l{Context3D::getShaderPrecisionFormat()} call. * - * \sa Context3D, {QtCanvas3D QML Types} + * \sa Context3D */ /*! diff --git a/src/shaderprecisionformat_p.h b/src/imports/qtcanvas3d/shaderprecisionformat_p.h similarity index 100% rename from src/shaderprecisionformat_p.h rename to src/imports/qtcanvas3d/shaderprecisionformat_p.h diff --git a/src/teximage3d.cpp b/src/imports/qtcanvas3d/teximage3d.cpp similarity index 99% rename from src/teximage3d.cpp rename to src/imports/qtcanvas3d/teximage3d.cpp index 04c6c19dc48ff12574c55073ee45c6f668a1fc58..69ddc8001b670c838917db0a796c6d97c8264979 100644 --- a/src/teximage3d.cpp +++ b/src/imports/qtcanvas3d/teximage3d.cpp @@ -45,6 +45,7 @@ QT_BEGIN_NAMESPACE QT_CANVAS3D_BEGIN_NAMESPACE static QMap<QQmlEngine *,CanvasTextureImageFactory *>m_qmlEngineToImageFactoryMap; +static ulong m_texId = 0; class StaticFactoryMapDeleter { @@ -80,7 +81,7 @@ CanvasTextureImageFactory::~CanvasTextureImageFactory() /*! * \qmltype TextureImageFactory * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Create TextureImage elements. * * This static QML type is used for creating TextureImage instances by calling the @@ -164,7 +165,7 @@ QJSValue CanvasTextureImageFactory::newTexImage() /*! * \qmltype TextureImage * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Contains a texture image. * * An uncreatable QML type that contains a texture image created by calling @@ -260,7 +261,7 @@ void CanvasTextureImage::setSrc(const QUrl &url) */ ulong CanvasTextureImage::id() { - return ulong(this); + return m_texId++; } /*! diff --git a/src/teximage3d_p.h b/src/imports/qtcanvas3d/teximage3d_p.h similarity index 100% rename from src/teximage3d_p.h rename to src/imports/qtcanvas3d/teximage3d_p.h diff --git a/src/texture3d.cpp b/src/imports/qtcanvas3d/texture3d.cpp similarity index 99% rename from src/texture3d.cpp rename to src/imports/qtcanvas3d/texture3d.cpp index 0f7f52345e1f7e9215c1b33c0bf2f2e60b536110..3b09d4b98c7dc4f7a16ca2578b49bfc2524922ed 100644 --- a/src/texture3d.cpp +++ b/src/imports/qtcanvas3d/texture3d.cpp @@ -42,7 +42,7 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! * \qmltype Texture3D * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Contains an OpenGL texture. * * An uncreatable QML type that contains an OpenGL texture. You can get it by calling diff --git a/src/texture3d_p.h b/src/imports/qtcanvas3d/texture3d_p.h similarity index 100% rename from src/texture3d_p.h rename to src/imports/qtcanvas3d/texture3d_p.h diff --git a/src/uniformlocation.cpp b/src/imports/qtcanvas3d/uniformlocation.cpp similarity index 98% rename from src/uniformlocation.cpp rename to src/imports/qtcanvas3d/uniformlocation.cpp index 6c3a8f3ae62879dc25f647daee0fe0d20c2f399d..2d1fc2c93999666f514a0e97444009e49eb5c2b7 100644 --- a/src/uniformlocation.cpp +++ b/src/imports/qtcanvas3d/uniformlocation.cpp @@ -42,7 +42,7 @@ QT_CANVAS3D_BEGIN_NAMESPACE /*! * \qmltype UniformLocation * \since QtCanvas3D 1.0 - * \ingroup qtcanvas3d-qml-types + * \inqmlmodule QtCanvas3D * \brief Contains uniform location id. * * An uncreatable QML type that contains an uniform location id. You can get it by calling diff --git a/src/uniformlocation_p.h b/src/imports/qtcanvas3d/uniformlocation_p.h similarity index 100% rename from src/uniformlocation_p.h rename to src/imports/qtcanvas3d/uniformlocation_p.h diff --git a/src/src.pro b/src/src.pro index a809324ccca8914d0548bd7130903a8d6e965f5f..f13683be19ee49901c873fe3c6851324274a919a 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,77 +1,4 @@ -load(qt_parts) +TEMPLATE = subdirs +CONFIG += ordered -TEMPLATE = lib -TARGET = qtcanvas3d -QT += qml quick qml-private core-private -DEFINES += QTCANVAS3D_LIBRARY -TARGETPATH = QtCanvas3D -IMPORT_VERSION = $$MODULE_VERSION - -# Only build qml plugin static if Qt itself is also built static -!contains(QT_CONFIG, static): CONFIG -= static staticlib - -include($$PWD/designer/designer.pri) - -QMAKE_DOCS = $$PWD/doc/qtcanvas3d.qdocconf - -SOURCES += arrayutils.cpp \ - qcanvas3d_plugin.cpp \ - enumtostringmap.cpp \ - abstractobject3d.cpp \ - canvas3d.cpp \ - buffer3d.cpp \ - canvasrendernode.cpp \ - context3d.cpp \ - contextattributes.cpp \ - framebuffer3d.cpp \ - program3d.cpp \ - renderbuffer3d.cpp \ - shader3d.cpp \ - shaderprecisionformat.cpp \ - teximage3d.cpp \ - texture3d.cpp \ - uniformlocation.cpp \ - activeinfo3d.cpp \ - canvasglstatedump.cpp - -HEADERS += arrayutils_p.h \ - qcanvas3d_plugin.h \ - enumtostringmap_p.h \ - abstractobject3d_p.h \ - canvas3d_p.h \ - buffer3d_p.h \ - canvas3dcommon_p.h \ - canvasrendernode_p.h \ - context3d_p.h \ - contextattributes_p.h \ - framebuffer3d_p.h \ - program3d_p.h \ - renderbuffer3d_p.h \ - shader3d_p.h \ - shaderprecisionformat_p.h \ - teximage3d_p.h \ - texture3d_p.h \ - uniformlocation_p.h \ - activeinfo3d_p.h \ - canvasglstatedump_p.h - -OTHER_FILES = qmldir \ - doc/* \ - doc/src/* \ - doc/images/* \ - doc/snippets/* \ - plugins.qmltypes \ - designer/* \ - designer/default/* - -CONFIG += no_cxx_module - -load(qml_plugin) - -!android:!ios { - copy_qmldir.target = $$DESTDIR/qmldir - copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir - copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" - QMAKE_EXTRA_TARGETS += copy_qmldir - PRE_TARGETDEPS += $$copy_qmldir.target -} +SUBDIRS += imports diff --git a/tests/auto/qmltest/canvas3d/tst_conformance_typedarrays.js b/tests/auto/qmltest/canvas3d/tst_conformance_typedarrays.js deleted file mode 100644 index d5afae3337f44bab7a58f9332ea91405e2720b3e..0000000000000000000000000000000000000000 --- a/tests/auto/qmltest/canvas3d/tst_conformance_typedarrays.js +++ /dev/null @@ -1,1444 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -Qt.include("../../../../3rdparty/js-test-pre.js") - -var gl; - -function initGL(canvas, antialias, depth) { - gl = canvas.getContext("depth-aa", {depth:depth, antialias:antialias}); -} - -function context() { - return gl; -} - -// WebGL Conformance tests - -/* -** Copyright (c) 2012 The Khronos Group Inc. -** -** Permission is hereby granted, free of charge, to any person obtaining a -** copy of this software and/or associated documentation files (the -** "Materials"), to deal in the Materials without restriction, including -** without limitation the rights to use, copy, modify, merge, publish, -** distribute, sublicense, and/or sell copies of the Materials, and to -** permit persons to whom the Materials are furnished to do so, subject to -** the following conditions: -** -** The above copyright notice and this permission notice shall be included -** in all copies or substantial portions of the Materials. -** -** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. -*/ -function createArray() { - return new ArrayBuffer().byteLength; -} - -function createArrayView() { - return new Uint32Array().length; -} - -var currentlyRunning = ''; - -function running(str) { - currentlyRunning = str; - output(str) -} - -function output(str) { - //console.log(str); -} - -function pass(str) { - var exc; - if (str) - exc = currentlyRunning + ': ' + str; - else - exc = currentlyRunning; - output(exc); - return true; -} - -function fail(str) { - var exc; - if (str) - exc = currentlyRunning + ': ' + str; - else - exc = currentlyRunning; - output(exc); - return false; -} - -function assertEq(prefix, expected, val) { - if (expected !== val) { - var str = prefix + ': expected ' + expected + ', got ' + val; - throw str; - } -} - -function assert(prefix, expected) { - if (!expected) { - var str = prefix + ': expected value / true'; - throw str; - } -} - -var buffer; -var byteLength; -var subBuffer; -var subArray; -function testSlice() { - function test(subBuf, starts, size) { - byteLength = size; - subBuffer = eval(subBuf); - subArray = new Int8Array(subBuffer); - assertEq(subBuf, subBuffer.byteLength, byteLength); - for (var i = 0; i < size; ++i) - assertEq('Element ' + i, starts + i, subArray[i]); - } - try { - running('testSlice'); - buffer = new ArrayBuffer(32); - var array = new Int8Array(buffer); - for (var i = 0; i < 32; ++i) - array[i] = i; - test("buffer.slice(0)", 0, 32); - test("buffer.slice(16)", 16, 16); - test("buffer.slice(24)", 24, 8); - test("buffer.slice(32)", 32, 0); - test("buffer.slice(40)", 32, 0); - test("buffer.slice(80)", 32, 0); - test("buffer.slice(-8)", 24, 8); - test("buffer.slice(-16)", 16, 16); - test("buffer.slice(-24)", 8, 24); - test("buffer.slice(-32)", 0, 32); - test("buffer.slice(-40)", 0, 32); - test("buffer.slice(-80)", 0, 32); - test("buffer.slice(0, 32)", 0, 32); - test("buffer.slice(0, 16)", 0, 16); - test("buffer.slice(8, 24)", 8, 16); - test("buffer.slice(16, 32)", 16, 16); - test("buffer.slice(24, 16)", 24, 0); - test("buffer.slice(16, -8)", 16, 8); - test("buffer.slice(-20, 30)", 12, 18); - test("buffer.slice(-8, -20)", 24, 0); - test("buffer.slice(-20, -8)", 12, 12); - test("buffer.slice(-40, 16)", 0, 16); - test("buffer.slice(-40, 40)", 0, 32); - return pass(); - } catch (e) { - return fail(e); - } -} -function testArrayBufferIsViewMethod() { - output('test ArrayBuffer.isView() with various values'); - var retval = true; - try { - if (!ArrayBuffer.isView) { - return fail('ArrayBuffer.isView() method does not exist'); - } else { - output('ArrayBuffer.isView() method exists'); - retval = shouldBe('ArrayBuffer.isView(new Int8Array(1))', 'true'); - if (!retval) return false; - retval = shouldBe('ArrayBuffer.isView(new Uint8Array(1))', 'true'); - if (!retval) return false; - retval = shouldBe('ArrayBuffer.isView(new Uint8ClampedArray(1))', 'true'); - if (!retval) return false; - retval = shouldBe('ArrayBuffer.isView(new Int16Array(1))', 'true'); - if (!retval) return false; - retval = shouldBe('ArrayBuffer.isView(new Uint16Array(1))', 'true'); - if (!retval) return false; - retval = shouldBe('ArrayBuffer.isView(new Int32Array(1))', 'true'); - if (!retval) return false; - retval = shouldBe('ArrayBuffer.isView(new Uint32Array(1))', 'true'); - if (!retval) return false; - retval = shouldBe('ArrayBuffer.isView(new Float32Array(1))', 'true'); - if (!retval) return false; - retval = shouldBe('ArrayBuffer.isView(new Float64Array(1))', 'true'); - if (!retval) return false; - retval = shouldBe('ArrayBuffer.isView(new DataView(new ArrayBuffer(8)))', 'true'); - if (!retval) return false; - // TODO: All these fail. V4VM? - //retval = shouldBe('ArrayBuffer.isView(undefined)', 'false'); - //if (!retval) return false; - //retval = shouldBe('ArrayBuffer.isView(null)', 'false'); - //if (!retval) return false; - //retval = shouldBe('ArrayBuffer.isView(true)', 'false'); - //if (!retval) return false; - //retval = shouldBe('ArrayBuffer.isView(false)', 'false'); - //if (!retval) return false; - //retval = shouldBe('ArrayBuffer.isView(0)', 'false'); - //if (!retval) return false; - //retval = shouldBe('ArrayBuffer.isView(1)', 'false'); - //if (!retval) return false; - //retval = shouldBe('ArrayBuffer.isView(1.0)', 'false'); - //if (!retval) return false; - //retval = shouldBe('ArrayBuffer.isView("hello")', 'false'); - //if (!retval) return false; - //retval = shouldBe('ArrayBuffer.isView({})', 'false'); - //if (!retval) return false; - //retval = shouldBe('ArrayBuffer.isView(function() {})', 'false'); - //if (!retval) return false; - //retval = shouldBe('ArrayBuffer.isView(new Array(1))', 'false'); - } - } catch (e) { - return fail('Exception thrown while testing ArrayBuffer.isView method: ' + e); - } - return retval; -} -function testInheritanceHierarchy() { - output('test inheritance hierarchy of typed array views'); - var retval = true; - try { - var foo = ArrayBufferView; - return fail('ArrayBufferView has [NoInterfaceObject] extended attribute and should not be defined'); - } catch (e) { - output('ArrayBufferView has [NoInterfaceObject] extended attribute and was (correctly) not defined'); - } - // Uint8ClampedArray inherited from Uint8Array in earlier versions - // of the typed array specification. Since this is no longer the - // case, assert the new behavior. - retval = shouldBe('new Uint8ClampedArray(1) instanceof Uint8Array', 'false'); - if (!retval) return false; - retval = shouldBe('Object.getPrototypeOf(Int8Array.prototype)', 'Object.prototype'); - if (!retval) return false; - retval = shouldBe('Object.getPrototypeOf(Uint8Array.prototype)', 'Object.prototype'); - if (!retval) return false; - retval = shouldBe('Object.getPrototypeOf(Uint8ClampedArray.prototype)', 'Object.prototype'); - if (!retval) return false; - retval = shouldBe('Object.getPrototypeOf(Int16Array.prototype)', 'Object.prototype'); - if (!retval) return false; - retval = shouldBe('Object.getPrototypeOf(Uint16Array.prototype)', 'Object.prototype'); - if (!retval) return false; - retval = shouldBe('Object.getPrototypeOf(Int32Array.prototype)', 'Object.prototype'); - if (!retval) return false; - retval = shouldBe('Object.getPrototypeOf(Uint32Array.prototype)', 'Object.prototype'); - if (!retval) return false; - retval = shouldBe('Object.getPrototypeOf(Float32Array.prototype)', 'Object.prototype'); - if (!retval) return false; - retval = shouldBe('Object.getPrototypeOf(Float64Array.prototype)', 'Object.prototype'); - if (!retval) return false; - retval = shouldBe('Object.getPrototypeOf(DataView.prototype)', 'Object.prototype'); - return retval; -} - -// -// Tests for unsigned array variants -// -function testSetAndGet10To1(type, name) { - running('test ' + name + ' SetAndGet10To1'); - try { - var array = new type(10); - for (var i = 0; i < 10; i++) { - array[i] = 10 - i; - } - for (var i = 0; i < 10; i++) { - assertEq('Element ' + i, 10 - i, array[i]); - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function testConstructWithArrayOfUnsignedValues(type, name) { - running('test ' + name + ' ConstructWithArrayOfUnsignedValues'); - try { - var array = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]); - assertEq('Array length', 10, array.length); - for (var i = 0; i < 10; i++) { - assertEq('Element ' + i, 10 - i, array[i]); - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function testConstructWithTypedArrayOfUnsignedValues(type, name) { - running('test ' + name + ' ConstructWithTypedArrayOfUnsignedValues'); - try { - var tmp = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]); - var array = new type(tmp); - assertEq('Array length', 10, array.length); - for (var i = 0; i < 10; i++) { - assertEq('Element ' + i, 10 - i, array[i]); - } - return pass(); - } catch (e) { - return fail(e); - } -} - -// -// Tests for signed array variants -// -function testSetAndGetPos10ToNeg10(type, name) { - running('test ' + name + ' SetAndGetPos10ToNeg10'); - try { - var array = new type(21); - for (var i = 0; i < 21; i++) { - array[i] = 10 - i; - } - for (i = 0; i < 21; i++) { - assertEq('Element ' + i, 10 - i, array[i]); - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function testConstructWithArrayOfSignedValues(type, name) { - running('test ' + name + ' ConstructWithArrayOfSignedValues'); - try { - var array = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]); - assertEq('Array length', 21, array.length); - for (var i = 0; i < 21; i++) { - assertEq('Element ' + i, 10 - i, array[i]); - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function testConstructWithTypedArrayOfSignedValues(type, name) { - running('test ' + name + ' ConstructWithTypedArrayOfSignedValues'); - try { - var tmp = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]); - var array = new type(tmp); - assertEq('Array length', 21, array.length); - for (var i = 0; i < 21; i++) { - assertEq('Element ' + i, 10 - i, array[i]); - } - return pass(); - } catch (e) { - return fail(e); - } -} - -// -// Test cases for integral types. -// Some JavaScript engines need separate copies of this code in order -// to exercise all of their optimized code paths. -// -function testIntegralArrayTruncationBehavior(type, name, unsigned) { - running('test integral array truncation behavior for ' + name); - var sourceData; - var expectedResults; - if (unsigned) { - sourceData = [0.6, 10.6]; - expectedResults = [0, 10]; - } else { - sourceData = [0.6, 10.6, -0.6, -10.6]; - expectedResults = [0, 10, 0, -10]; - } - var numIterations = 10; - var array = new type(numIterations); - // The code block in each of the case statements below is identical, but some - // JavaScript engines need separate copies in order to exercise all of - // their optimized code paths. - try { - switch (type) { - case Int8Array: - for (var ii = 0; ii < sourceData.length; ++ii) { - for (var jj = 0; jj < numIterations; ++jj) { - array[jj] = sourceData[ii]; - assertEq('Storing ' + sourceData[ii], expectedResults[ii], array[jj]); - } - } - break; - case Int16Array: - for (ii = 0; ii < sourceData.length; ++ii) { - for (jj = 0; jj < numIterations; ++jj) { - array[jj] = sourceData[ii]; - assertEq('Storing ' + sourceData[ii], expectedResults[ii], array[jj]); - } - } - break; - case Int32Array: - for (ii = 0; ii < sourceData.length; ++ii) { - for (jj = 0; jj < numIterations; ++jj) { - array[jj] = sourceData[ii]; - assertEq('Storing ' + sourceData[ii], expectedResults[ii], array[jj]); - } - } - break; - case Uint8Array: - for (ii = 0; ii < sourceData.length; ++ii) { - for (jj = 0; jj < numIterations; ++jj) { - array[jj] = sourceData[ii]; - assertEq('Storing ' + sourceData[ii], expectedResults[ii], array[jj]); - } - } - break; - case Uint16Array: - for (ii = 0; ii < sourceData.length; ++ii) { - for (jj = 0; jj < numIterations; ++jj) { - array[jj] = sourceData[ii]; - assertEq('Storing ' + sourceData[ii], expectedResults[ii], array[jj]); - } - } - break; - case Uint32Array: - for (ii = 0; ii < sourceData.length; ++ii) { - for (jj = 0; jj < numIterations; ++jj) { - array[jj] = sourceData[ii]; - assertEq('Storing ' + sourceData[ii], expectedResults[ii], array[jj]); - } - } - break; - default: - fail("Unhandled type"); - break; - } - return pass(); - } catch (e) { - return fail(e); - } -} - -// -// Test cases for both signed and unsigned types -// -function testGetWithOutOfRangeIndices(type, name) { - var retval = true; - console.log('Testing ' + name + ' GetWithOutOfRangeIndices'); - // See below for declaration of this global variable - array = new type([2, 3]); - retval = shouldBeUndefined("array[2]");//(array[2] === undefined); - if (retval) - retval = shouldBeUndefined("array[-1]");//(array[-1] === undefined); - if (retval) - retval = shouldBeUndefined("array[0x20000000]");//(array[0x20000000] === undefined); - return retval; -} - -function testOffsetsAndSizes(type, name, elementSizeInBytes) { - running('test ' + name + ' OffsetsAndSizes'); - try { - var len = 10; - assertEq('type.BYTES_PER_ELEMENT', elementSizeInBytes, type.BYTES_PER_ELEMENT); - var array = new type(len); - assert('array.buffer', array.buffer); - assertEq('array.byteOffset', 0, array.byteOffset); - assertEq('array.length', len, array.length); - assertEq('array.byteLength', len * elementSizeInBytes, array.byteLength); - array = new type(array.buffer, elementSizeInBytes, len - 1); - assert('array.buffer', array.buffer); - assertEq('array.byteOffset', elementSizeInBytes, array.byteOffset); - assertEq('array.length', len - 1, array.length); - assertEq('array.byteLength', (len - 1) * elementSizeInBytes, array.byteLength); - return pass(); - } catch (e) { - return fail(e); - } -} - -function testSetFromTypedArray(type, name) { - running('test ' + name + ' SetFromTypedArray'); - try { - var array = new type(10); - var array2 = new type(5); - for (var i = 0; i < 10; i++) { - assertEq('Element ' + i, 0, array[i]); - } - for (var i = 0; i < array2.length; i++) { - array2[i] = i; - } - array.set(array2); - for (var i = 0; i < array2.length; i++) { - assertEq('Element ' + i, i, array[i]); - } - array.set(array2, 5); - for (var i = 0; i < array2.length; i++) { - assertEq('Element ' + i, i, array[5 + i]); - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function negativeTestSetFromTypedArray(type, name) { - running('negativeTest ' + name + ' SetFromTypedArray'); - try { - var array = new type(5); - var array2 = new type(6); - for (var i = 0; i < 5; i++) { - assertEq('Element ' + i, 0, array[i]); - } - for (var i = 0; i < array2.length; i++) { - array2[i] = i; - } - try { - array.set(array2); - fail('Expected exception from array.set(array2)'); - return; - } catch (e) { - } - try { - array2.set(array, 2); - fail('Expected exception from array2.set(array, 2)'); - return; - } catch (e) { - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function testSetFromArray(type, name) { - running('test ' + name + ' SetFromArray'); - try { - var array = new type(10); - var array2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]; - for (var i = 0; i < 10; i++) { - assertEq('Element ' + i, 0, array[i]); - } - array.set(array2, 0); - for (var i = 0; i < array2.length; i++) { - assertEq('Element ' + i, 10 - i, array[i]); - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function negativeTestSetFromArray(type, name) { - running('negativeTest ' + name + ' SetFromArray'); - try { - var array = new type([2, 3]); - try { - array.set([4, 5], 1); - fail(); - return; - } catch (e) { - } - try { - array.set([4, 5, 6]); - fail(); - return; - } catch (e) { - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function testSubarray(type, name) { - running('test ' + name + ' Subarray'); - try { - var array = new type([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); - var subarray = array.subarray(0, 5); - assertEq('subarray.length', 5, subarray.length); - for (var i = 0; i < 5; i++) { - assertEq('Element ' + i, i, subarray[i]); - } - subarray = array.subarray(4, 10); - assertEq('subarray.length', 6, subarray.length); - for (i = 0; i < 6; i++) { - assertEq('Element ' + i, 4 + i, subarray[i]); - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function negativeTestSubarray(type, name) { - running('negativeTest ' + name + ' Subarray'); - try { - var array = new type([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); - subarray = array.subarray(5, 11); - if (subarray.length !== 5) { - return fail(); - } - subarray = array.subarray(10, 10); - if (subarray.length !== 0) { - return fail(); - } - return pass(); - } catch (e) { - console.log("subarrayfail") - return fail(e); - } -} - -function testSetBoundaryConditions(type, name, testValues, expectedValues) { - running('test ' + name + ' SetBoundaryConditions'); - try { - var array = new type(1); - assertEq('Array length', 1, array.length); - for (var ii = 0; ii < testValues.length; ++ii) { - for (var jj = 0; jj < 10; ++jj) { - array[0] = testValues[ii]; - assertEq('Element 0', expectedValues[ii], array[0]); - } - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function testConstructionBoundaryConditions(type, name, testValues, expectedValues) { - running('test ' + name + ' ConstructionBoundaryConditions'); - try { - var array = new type(testValues); - assertEq('Array length', testValues.length, array.length); - for (var ii = 0; ii < testValues.length; ++ii) { - assertEq('Element ' + ii, expectedValues[ii], array[ii]); - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function testConstructionWithNullBuffer(type, name) { - var array; - try { - array = new type(null); - return fail("Construction of " + name + " with null buffer should throw exception"); - } catch (e) { - output("Construction of " + name + " with null buffer threw exception"); - } - try { - array = new type(null, 0, 0); - return fail("Construction of " + name + " with (null buffer, 0) should throw exception"); - } catch (e) { - output("Construction of " + name + " with (null buffer, 0) threw exception"); - } - try { - array = new type(null, 0, 0); - return fail("Construction of " + name + " with (null buffer, 0, 0) should throw exception"); - } catch (e) { - output("Construction of " + name + " with (null buffer, 0, 0) threw exception"); - } - return pass(); -} - -function shouldThrowIndexSizeErr(func, text) { - var errorText = text + " should throw an exception"; - try { - func(); - return fail(errorText); - } catch (e) { - return pass(text + " threw an exception"); - } -} - -function testConstructionWithOutOfRangeValues(type, name) { - return shouldThrowIndexSizeErr(function() { - var buffer = new ArrayBuffer(4); - var array = new type(buffer, 4, 0x3FFFFFFF); - }, "Construction of " + name + " with out-of-range values"); -} - -function testConstructionWithNegativeOutOfRangeValues(type, name) { - try { - var buffer = new ArrayBuffer(-1); - return fail("Construction of ArrayBuffer with negative size should throw exception"); - } catch (e) { - output("Construction of ArrayBuffer with negative size threw exception"); - } - try { - var array = new type(-1); - return fail("Construction of " + name + " with negative size should throw exception"); - } catch (e) { - output("Construction of " + name + " with negative size threw exception"); - } - return shouldThrowIndexSizeErr(function() { - var buffer = new ArrayBuffer(4); - var array = new type(buffer, 4, -2147483648); - }, "Construction of " + name + " with negative out-of-range values"); -} - -function testConstructionWithUnalignedOffset(type, name, elementSizeInBytes) { - if (elementSizeInBytes > 1) { - return shouldThrowIndexSizeErr(function() { - var buffer = new ArrayBuffer(32); - var array = new type(buffer, 1, elementSizeInBytes); - }, "Construction of " + name + " with unaligned offset"); - } -} - -function testConstructionWithUnalignedLength(type, name, elementSizeInBytes) { - if (elementSizeInBytes > 1) { - return shouldThrowIndexSizeErr(function() { - var buffer = new ArrayBuffer(elementSizeInBytes + 1); - var array = new type(buffer, 0); - }, "Construction of " + name + " with unaligned length"); - } -} - -function testConstructionOfHugeArray(type, name, sz) { - if (sz === 1) - return; - try { - // Construction of huge arrays must fail because byteLength is - // an unsigned long - array = new type(3000000000); - return fail("Construction of huge " + name + " should throw exception"); - } catch (e) { - return pass("Construction of huge " + name + " threw exception"); - } -} - -function testConstructionWithBothArrayBufferAndLength(type, name, elementSizeInBytes) { - var bufByteLength = 1000 * elementSizeInBytes; - var buf = new ArrayBuffer(bufByteLength); - var array1 = new type(buf); - var array2 = new type(bufByteLength / elementSizeInBytes); - if (array1.length === array2.length) { - return pass("Array lengths matched with explicit and implicit creation of ArrayBuffer"); - } else { - return fail("Array lengths DID NOT MATCH with explicit and implicit creation of ArrayBuffer"); - } -} - -// These need to be global for shouldBe to see them -var array; -var typeSize; -function testSubarrayWithOutOfRangeValues(type, name, sz) { - console.log("Testing subarray of " + name); - var retval = true; - try { - var buffer = new ArrayBuffer(32); - array = new type(buffer); - typeSize = sz; - retval = shouldBe("array.length", "32 / typeSize"); - try { - if (retval) - retval = shouldBe("array.subarray(4, 0x3FFFFFFF).length", "(32 / typeSize) - 4"); - if (retval) - retval = shouldBe("array.subarray(4, -2147483648).length", "0"); - // Test subarray() against overflows. - array = array.subarray(2); - if (sz > 1) { - // Full byte offset is +1 larger than the maximum unsigned long int. - // Make sure subarray() still handles it correctly. Otherwise overflow would happen and - // offset would be 0, and array.length array.length would incorrectly be 1. - var start = 4294967296 / sz - 2; - array = array.subarray(start, start + 1); - if (retval) - retval = shouldBe("array.length", "0"); - } - } catch (e) { - return fail("Subarray of " + name + " threw exception"); - } - } catch (e) { - return fail("Exception: " + e); - } - return retval; -} - -function testSubarrayWithDefaultValues(type, name, sz) { - console.log("Testing subarray with default inputs of " + name); - var retval = true; - try { - var buffer = new ArrayBuffer(32); - array = new type(buffer); - typeSize = sz; - retval = shouldBe("array.length", "32 / typeSize"); - try { - if (retval) - retval = shouldBe("array.subarray(0).length", "(32 / typeSize)"); - if (retval) - retval = shouldBe("array.subarray(2).length", "(32 / typeSize) - 2"); - if (retval) - retval = shouldBe("array.subarray(-2).length", "2"); - if (retval) - retval = shouldBe("array.subarray(-2147483648).length", "(32 / typeSize)"); - } catch (e) { - return fail("Subarray of " + name + " threw exception"); - } - } catch (e) { - return fail("Exception: " + e); - } - return retval; -} - -function testSettingFromArrayWithOutOfRangeOffset(type, name) { - var webglArray = new type(32); - var array = []; - for (var i = 0; i < 16; i++) { - array.push(i); - } - try { - webglArray.set(array, 0x7FFFFFF8); - return fail("Setting " + name + " from array with out-of-range offset was not caught"); - } catch (e) { - return pass("Setting " + name + " from array with out-of-range offset was caught"); - } -} - -function testSettingFromFakeArrayWithOutOfRangeLength(type, name) { - var webglArray = new type(32); - var array = {}; - array.length = 0x80000000; - try { - webglArray.set(array, 8); - return fail("Setting " + name + " from fake array with invalid length was not caught"); - } catch (e) { - return pass("Setting " + name + " from fake array with invalid length was caught"); - } -} - -function testSettingFromTypedArrayWithOutOfRangeOffset(type, name) { - var webglArray = new type(32); - var srcArray = new type(16); - for (var i = 0; i < 16; i++) { - srcArray[i] = i; - } - try { - webglArray.set(srcArray, 0x7FFFFFF8); - return fail("Setting " + name + " from " + name + " with out-of-range offset was not caught"); - } catch (e) { - return pass("Setting " + name + " from " + name + " with out-of-range offset was caught"); - } -} - -function negativeTestGetAndSetMethods(type, name) { - array = new type([2, 3]); - shouldBeUndefined("array.get"); - var exceptionThrown = false; - // We deliberately check for an exception here rather than using - // shouldThrow here because the precise contents of the syntax - // error are not specified. - try { - webGLArray.set(0, 1); - } catch (e) { - exceptionThrown = true; - } - var txt = "array.set(0, 1) "; - if (exceptionThrown) { - return pass(txt + "threw exception."); - } else { - return fail(txt + "did not throw exception."); - } -} - -function testNaNConversion(type, name) { - running('test storing NaN in ' + name); - var array = new type([1, 1]); - var results = []; - // The code block in each of the case statements below is identical, but some - // JavaScript engines need separate copies in order to exercise all of - // their optimized code paths. - try { - switch (type) { - case Float32Array: - for (var i = 0; i < array.length; ++i) { - array[i] = NaN; - results[i] = array[i]; - } - break; - case Int8Array: - for (i = 0; i < array.length; ++i) { - array[i] = NaN; - results[i] = array[i]; - } - break; - case Int16Array: - for (i = 0; i < array.length; ++i) { - array[i] = NaN; - results[i] = array[i]; - } - break; - case Int32Array: - for (i = 0; i < array.length; ++i) { - array[i] = NaN; - results[i] = array[i]; - } - break; - case Uint8Array: - for (i = 0; i < array.length; ++i) { - array[i] = NaN; - results[i] = array[i]; - } - break; - case Uint16Array: - for (i = 0; i < array.length; ++i) { - array[i] = NaN; - results[i] = array[i]; - } - break; - case Uint32Array: - for (i = 0; i < array.length; ++i) { - array[i] = NaN; - results[i] = array[i]; - } - break; - default: - return fail("Unhandled type"); - } - // Some types preserve NaN values; all other types convert NaN to zero. - if (type === Float32Array) { - assert('initial NaN preserved', isNaN(new type([NaN])[0])); - for (var i = 0; i < array.length; ++i) - assert('NaN preserved via setter', isNaN(results[i])); - } else { - assertEq('initial NaN converted to zero', 0, new type([NaN])[0]); - for (var i = 0; i < array.length; ++i) - assertEq('NaN converted to zero by setter', 0, results[i]); - } - return pass(); - } catch (e) { - return fail(e); - } -} - -function testConstructionOfHugeArray(type, name, sz) { - if (sz === 1) - return; - try { - // Construction of huge arrays must fail because byteLength is - // an unsigned long - array = new type(3000000000); - return fail("Construction of huge " + name + " should throw exception"); - } catch (e) { - return pass("Construction of huge " + name + " threw exception"); - } -} - -function dataView() { - var array = new Uint8Array([164, 112, 157, 63]); - var dataview; - var retval = true; - retval = shouldThrow("dataview = new DataView(array.buffer, -4500000000)"); - if (!retval) return false; - retval = shouldThrow("dataview = new DataView(array.buffer, -4500000000, 4500000000)"); - if (!retval) return false; - var value = dataview ? dataview.getFloat32(0, true) : 0; - return retval; -} - -var intArray1 = [0, 1, 2, 3, 100, 101, 102, 103, 128, 129, 130, 131, 252, 253, 254, 255]; -var intArray2 = [31, 32, 33, 0, 1, 2, 3, 100, 101, 102, 103, 128, 129, 130, 131, 252, 253, 254, 255]; -var emptyArray = [204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204]; -var arrayBuffer = null; -var view = null; -var viewStart = 0; -var viewLength = 0; - -function getElementSize(func) -{ - switch (func) { - case "Int8": - case "Uint8": - return 1; - case "Int16": - case "Uint16": - return 2; - case "Int32": - case "Uint32": - case "Float32": - return 4; - case "Float64": - return 8; - default: - output("Should not be reached"); - } -} - -function checkGet(func, index, expected, littleEndian) -{ - var expr = "view.get" + func + "(" + index; - if (littleEndian !== undefined) { - expr += ", "; - expr += littleEndian ? "true" : "false"; - } - expr += ")"; - running(expr) - if (index >= 0 && index + getElementSize(func) - 1 < view.byteLength) { - output("shouldbe " + expr + " ," + expected) - return shouldBe(expr, expected); - } else { - output("shouldthrow " + expr) - return shouldThrow(expr); - } -} - -function checkSet(func, index, value, littleEndian) -{ - var expr = "view.set" + func + "(" + index + ", " + value; - var retval = true; - if (littleEndian !== undefined) { - expr += ", "; - expr += littleEndian ? "true" : "false"; - } - expr += ")"; - running(expr) - if (index >= 0 && index + getElementSize(func) - 1 < view.byteLength) { - retval = shouldBeUndefined(expr); - if (!retval) return fail(); - return checkGet(func, index, value, littleEndian); - } else - return shouldThrow(expr); -} - -function test(isTestingGet, func, index, value, littleEndian) -{ - if (isTestingGet) - return checkGet(func, index, value, littleEndian); - else - return checkSet(func, index, value, littleEndian); -} - -function createDataView(array, frontPaddingNum, littleEndian, start, length) -{ - if (!littleEndian) - array.reverse(); - var paddingArray = new Array(frontPaddingNum); - arrayBuffer = (new Uint8Array(paddingArray.concat(array))).buffer; - viewStart = (start !== undefined) ? start : 0; - viewLength = (length !== undefined) ? length : arrayBuffer.byteLength - viewStart; - view = new DataView(arrayBuffer, viewStart, viewLength); - if (!littleEndian) - array.reverse(); // restore the array. -} - -function runIntegerTestCases(isTestingGet, array, start, length) -{ - createDataView(array, 0, true, start, length); - var retval = true; - retval = test(isTestingGet, "Int8", 0, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int8", 8, "-128"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int8", 15, "-1"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint8", 0, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint8", 8, "128"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint8", 15, "255"); - // Little endian. - if (!retval) return fail(); - retval = test(isTestingGet, "Int16", 0, "256", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Int16", 5, "26213", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Int16", 9, "-32127", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Int16", 14, "-2", true); - // Big endian. - if (!retval) return fail(); - retval = test(isTestingGet, "Int16", 0, "1"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int16", 5, "25958"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int16", 9, "-32382"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int16", 14, "-257"); - // Little endian. - if (!retval) return fail(); - retval = test(isTestingGet, "Uint16", 0, "256", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint16", 5, "26213", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint16", 9, "33409", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint16", 14, "65534", true); - // Big endian. - if (!retval) return fail(); - retval = test(isTestingGet, "Uint16", 0, "1"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint16", 5, "25958"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint16", 9, "33154"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint16", 14, "65279"); - // Little endian. - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", 0, "50462976", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", 3, "1717920771", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", 6, "-2122291354", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", 9, "-58490239", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", 12, "-66052", true); - // Big endian. - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", 0, "66051"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", 3, "56911206"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", 6, "1718059137"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", 9, "-2122152964"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", 12, "-50462977"); - // Little endian. - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", 0, "50462976", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", 3, "1717920771", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", 6, "2172675942", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", 9, "4236477057", true); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", 12, "4294901244", true); - // Big endian. - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", 0, "66051"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", 3, "56911206"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", 6, "1718059137"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", 9, "2172814332"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", 12, "4244504319"); - return retval; -} - -function testFloat(isTestingGet, func, array, start, expected) -{ - var retval = true; - // Little endian. - createDataView(array, 0, true, start); - retval = test(isTestingGet, func, 0, expected, true); - createDataView(array, 3, true, start); - if (!retval) return fail(); - retval = test(isTestingGet, func, 3, expected, true); - createDataView(array, 7, true, start); - if (!retval) return fail(); - retval = test(isTestingGet, func, 7, expected, true); - createDataView(array, 10, true, start); - if (!retval) return fail(); - retval = test(isTestingGet, func, 10, expected, true); - // Big endian. - createDataView(array, 0, false); - if (!retval) return fail(); - retval = test(isTestingGet, func, 0, expected, false); - createDataView(array, 3, false); - if (!retval) return fail(); - retval = test(isTestingGet, func, 3, expected, false); - createDataView(array, 7, false); - if (!retval) return fail(); - retval = test(isTestingGet, func, 7, expected, false); - createDataView(array, 10, false); - if (!retval) return fail(); - retval = test(isTestingGet, func, 10, expected, false); - return retval; -} - -function runFloatTestCases(isTestingGet, start) -{ - var retval = true; - retval = testFloat(isTestingGet, "Float32", isTestingGet ? [0, 0, 32, 65] : emptyArray, start, "10"); - if (!retval) return fail(); - retval = testFloat(isTestingGet, "Float32", isTestingGet ? [164, 112, 157, 63] : emptyArray, start, "1.2300000190734863"); - if (!retval) return fail(); - retval = testFloat(isTestingGet, "Float32", isTestingGet ? [95, 53, 50, 199] : emptyArray, start, "-45621.37109375"); - if (!retval) return fail(); - retval = testFloat(isTestingGet, "Float32", isTestingGet ? [255, 255, 255, 127] : emptyArray, start, "NaN"); - if (!retval) return fail(); - retval = testFloat(isTestingGet, "Float32", isTestingGet ? [255, 255, 255, 255] : emptyArray, start, "-NaN"); - if (!retval) return fail(); - retval = testFloat(isTestingGet, "Float64", isTestingGet ? [0, 0, 0, 0, 0, 0, 36, 64] : emptyArray, start, "10"); - if (!retval) return fail(); - retval = testFloat(isTestingGet, "Float64", isTestingGet ? [174, 71, 225, 122, 20, 174, 243, 63] : emptyArray, start, "1.23"); - if (!retval) return fail(); - retval = testFloat(isTestingGet, "Float64", isTestingGet ? [181, 55, 248, 30, 242, 179, 87, 193] : emptyArray, start, "-6213576.4839"); - if (!retval) return fail(); - retval = testFloat(isTestingGet, "Float64", isTestingGet ? [255, 255, 255, 255, 255, 255, 255, 127] : emptyArray, start, "NaN"); - if (!retval) return fail(); - retval = testFloat(isTestingGet, "Float64", isTestingGet ? [255, 255, 255, 255, 255, 255, 255, 255] : emptyArray, start, "-NaN"); - return retval; -} - -function runNegativeIndexTests(isTestingGet) -{ - var retval = true; - createDataView(intArray1, 0, true, 0, 16); - retval = test(isTestingGet, "Int8", -1, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int8", -2, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint8", -1, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint8", -2, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int16", -1, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int16", -2, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int16", -3, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint16", -1, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint16", -2, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint16", -3, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", -1, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", -3, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Int32", -5, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", -1, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", -3, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Uint32", -5, "0"); - createDataView([0, 0, 0, 0, 0, 0, 36, 64], 0, true, 0, 8); - if (!retval) return fail(); - retval = test(isTestingGet, "Float32", -1, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Float32", -3, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Float32", -5, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Float64", -1, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Float64", -5, "0"); - if (!retval) return fail(); - retval = test(isTestingGet, "Float64", -9, "0"); - return retval; -} - -function runConstructorTests() -{ - var retval = true; - arrayBuffer = (new Uint8Array([1, 2])).buffer; - running("Test for constructor taking 1 argument"); - retval = shouldBeDefined("view = new DataView(arrayBuffer)"); - if (!retval) return fail(); - retval = shouldBe("view.byteOffset", "0"); - if (!retval) return fail(); - retval = shouldBe("view.byteLength", "2"); - if (!retval) return fail(); - running("Test for constructor taking 2 arguments"); - retval = shouldBeDefined("view = new DataView(arrayBuffer, 1)"); - if (!retval) return fail(); - retval = shouldBe("view.byteOffset", "1"); - if (!retval) return fail(); - retval = shouldBe("view.byteLength", "1"); - if (!retval) return fail(); - running("Test for constructor taking 3 arguments"); - retval = shouldBeDefined("view = new DataView(arrayBuffer, 0, 1)"); - if (!retval) return fail(); - retval = shouldBe("view.byteOffset", "0"); - if (!retval) return fail(); - retval = shouldBe("view.byteLength", "1"); - if (!retval) return fail(); - running("Test for constructor throwing exception"); - retval = shouldThrow("view = new DataView(arrayBuffer, 0, 3)"); - if (!retval) return fail(); - retval = shouldThrow("view = new DataView(arrayBuffer, 1, 2)"); - if (!retval) return fail(); - retval = shouldThrow("view = new DataView(arrayBuffer, 2, 1)"); - return retval; -} - -function runGetTests() -{ - var retval = true; - running("Test for get methods that work"); - retval = runIntegerTestCases(true, intArray1, 0, 16); - if (!retval) return fail(); - retval = runFloatTestCases(true, 0); - running("Test for get methods that might read beyond range"); - if (!retval) return fail(); - retval = runIntegerTestCases(true, intArray2, 3, 2); - if (!retval) return fail(); - retval = runFloatTestCases(true, 3); - running("Test for get methods that read from negative index"); - if (!retval) return fail(); - retval = runNegativeIndexTests(true); - running("Test for wrong arguments passed to get methods"); - view = new DataView((new Uint8Array([1, 2])).buffer); - if (!retval) return fail(); - retval = shouldThrow("view.getInt8()"); - if (!retval) return fail(); - retval = shouldThrow("view.getUint8()"); - if (!retval) return fail(); - retval = shouldThrow("view.getInt16()"); - if (!retval) return fail(); - retval = shouldThrow("view.getUint16()"); - if (!retval) return fail(); - retval = shouldThrow("view.getInt32()"); - if (!retval) return fail(); - retval = shouldThrow("view.getUint32()"); - if (!retval) return fail(); - retval = shouldThrow("view.getFloat32()"); - if (!retval) return fail(); - retval = shouldThrow("view.getFloat64()"); - return retval; -} - -function runSetTests() -{ - var retval = true; - running("Test for set methods that work"); - retval = runIntegerTestCases(false, emptyArray, 0, 16); - if (!retval) return fail(); - retval = runFloatTestCases(false); - running("Test for set methods that might write beyond the range"); - if (!retval) return fail(); - retval = runIntegerTestCases(false, emptyArray, 3, 2); - if (!retval) return fail(); - retval = runFloatTestCases(false, 7); - running("Test for set methods that write to negative index"); - if (!retval) return fail(); - retval = runNegativeIndexTests(false); - running("Test for wrong arguments passed to set methods"); - view = new DataView((new Uint8Array([1, 2])).buffer); - if (!retval) return fail(); - retval = shouldThrow("view.setInt8()"); - if (!retval) return fail(); - retval = shouldThrow("view.setUint8()"); - if (!retval) return fail(); - retval = shouldThrow("view.setInt16()"); - if (!retval) return fail(); - retval = shouldThrow("view.setUint16()"); - if (!retval) return fail(); - retval = shouldThrow("view.setInt32()"); - if (!retval) return fail(); - retval = shouldThrow("view.setUint32()"); - if (!retval) return fail(); - retval = shouldThrow("view.setFloat32()"); - if (!retval) return fail(); - retval = shouldThrow("view.setFloat64()"); - if (!retval) return fail(); - retval = shouldThrow("view.setInt8(1)"); - if (!retval) return fail(); - retval = shouldThrow("view.setUint8(1)"); - if (!retval) return fail(); - retval = shouldThrow("view.setInt16(1)"); - if (!retval) return fail(); - retval = shouldThrow("view.setUint16(1)"); - if (!retval) return fail(); - retval = shouldThrow("view.setInt32(1)"); - if (!retval) return fail(); - retval = shouldThrow("view.setUint32(1)"); - if (!retval) return fail(); - retval = shouldThrow("view.setFloat32(1)"); - if (!retval) return fail(); - retval = shouldThrow("view.setFloat64(1)"); - return retval; -} - -function runIndexingTests() -{ - var retval = true; - running("Test for indexing that should not work"); - view = new DataView((new Uint8Array([1, 2])).buffer); - retval = shouldBeUndefined("view[0]"); - if (!retval) return fail(); - retval = shouldBeDefined("view[0] = 3"); - if (!retval) return fail(); - retval = shouldBe("view.getUint8(0)", "1"); - return retval; -} - -var testCases = - [ {name: "Float32Array", - type: Float32Array, - unsigned: false, - integral: false, - elementSizeInBytes: 4, - testValues: [ -500.5, 500.5 ], - expectedValues: [ -500.5, 500.5 ] - }, - {name: "Int8Array", - type: Int8Array, - unsigned: false, - integral: true, - elementSizeInBytes: 1, - testValues: [ -128, 127, -129, 128 ], - expectedValues: [ -128, 127, 127, -128 ] - }, - {name: "Int16Array", - type: Int16Array, - unsigned: false, - integral: true, - elementSizeInBytes: 2, - testValues: [ -32768, 32767, -32769, 32768 ], - expectedValues: [ -32768, 32767, 32767, -32768 ] - }, - {name: "Int32Array", - type: Int32Array, - unsigned: false, - integral: true, - elementSizeInBytes: 4, - testValues: [ -2147483648, 2147483647, -2147483649, 2147483648 ], - expectedValues: [ -2147483648, 2147483647, 2147483647, -2147483648 ] - }, - {name: "Uint8Array", - type: Uint8Array, - unsigned: true, - integral: true, - elementSizeInBytes: 1, - testValues: [ 0, 255, -1, 256 ], - expectedValues: [ 0, 255, 255, 0 ] - }, - {name: "Uint16Array", - type: Uint16Array, - unsigned: true, - integral: true, - elementSizeInBytes: 2, - testValues: [ 0, 65535, -1, 65536 ], - expectedValues: [ 0, 65535, 65535, 0 ] - }, - {name: "Uint32Array", - type: Uint32Array, - unsigned: true, - integral: true, - elementSizeInBytes: 4, - testValues: [ 0, 4294967295, -1, 4294967296 ], - expectedValues: [ 0, 4294967295, 4294967295, 0 ] - } - ]; diff --git a/tests/auto/qmltest/canvas3d/tst_conformance_typedarrays.qml b/tests/auto/qmltest/canvas3d/tst_conformance_typedarrays.qml deleted file mode 100644 index 72a21c324231f83393dfdff7ea6f4bbbbcd7f9b4..0000000000000000000000000000000000000000 --- a/tests/auto/qmltest/canvas3d/tst_conformance_typedarrays.qml +++ /dev/null @@ -1,228 +0,0 @@ -/**************************************************************************** -** -** 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_conformance_typedarrays.js" as Content - -// Covers the following WebGL conformance TypedArray tests: -// array-buffer-crash.html -// array-buffer-view-crash.html -// array-unit-tests.html -// array-large-array-tests.html -// data-view-crash.html -// data-view-test.html - -// Doesn't cover the following TypedArray tests: -// typed-arrays-in-workers.html - -Item { - id: top - height: 300 - width: 300 - - Canvas3D { - onInitGL: Content.initGL(this, true, true) - } - - /* - ** Copyright (c) 2012 The Khronos Group Inc. - ** - ** Permission is hereby granted, free of charge, to any person obtaining a - ** copy of this software and/or associated documentation files (the - ** "Materials"), to deal in the Materials without restriction, including - ** without limitation the rights to use, copy, modify, merge, publish, - ** distribute, sublicense, and/or sell copies of the Materials, and to - ** permit persons to whom the Materials are furnished to do so, subject to - ** the following conditions: - ** - ** The above copyright notice and this permission notice shall be included - ** in all copies or substantial portions of the Materials. - ** - ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - */ - - // array-buffer-crash.html - TestCase { - name: "Canvas3D_conformance_array_buffer_crash" - when: windowShown - - function test_array_buffer_no_crash() { - verify(Content.createArray() !== null, - "Test ArrayBuffer.byteLength (new ArrayBuffer().byteLength)") - } - } - - // array-buffer-view-crash.html - TestCase { - name: "Canvas3D_conformance_array_buffer_view_crash" - when: windowShown - - function test_array_buffer_view_no_crash() { - verify(Content.createArrayView() !== null, - "Verify that constructing a typed array view with no arguments and fetching \ - its length does not crash (new Uint32Array().length)") - } - } - - // array-unit-tests.html - TestCase { - // Verifies the functionality of the new array-like objects in the TypedArray spec - name: "Canvas3D_conformance_array_unit_tests" - when: windowShown - - function test_slice() { - verify(Content.testSlice()); - } - - function test_array_buffer_is_view() { - verify(Content.testArrayBufferIsViewMethod()); // Half the tests here fail. Something to check in V4VM? - } - - function test_inheritance_hierarchy() { - verify(Content.testInheritanceHierarchy()); - } - - function test_typed_arrays() { - for (var i = 0; i < Content.testCases.length; i++) { - var testCase = Content.testCases[i]; - Content.running(testCase.name); - var type = testCase.type; - var name = testCase.name; - if (testCase.unsigned) { - verify(Content.testSetAndGet10To1(type, name)); - verify(Content.testConstructWithArrayOfUnsignedValues(type, name)); - verify(Content.testConstructWithTypedArrayOfUnsignedValues(type, name)); - } else { - verify(Content.testSetAndGetPos10ToNeg10(type, name)); - verify(Content.testConstructWithArrayOfSignedValues(type, name)); - verify(Content.testConstructWithTypedArrayOfSignedValues(type, name)); - } - if (testCase.integral) { - verify(Content.testIntegralArrayTruncationBehavior(type, name, testCase.unsigned)); - } - verify(Content.testGetWithOutOfRangeIndices(type, name)); - verify(Content.testOffsetsAndSizes(type, name, testCase.elementSizeInBytes)); - verify(Content.testSetFromTypedArray(type, name)); - verify(Content.negativeTestSetFromTypedArray(type, name)); - verify(Content.testSetFromArray(type, name)); - verify(Content.negativeTestSetFromArray(type, name)); - verify(Content.testSubarray(type, name)); - //verify(Content.negativeTestSubarray(type, name)); // V4VM? Float32Array Subarray: Error: Invalid write to global property "subarray". Something to check in V4VM? - verify(Content.testSetBoundaryConditions(type, - name, - testCase.testValues, - testCase.expectedValues)); - verify(Content.testConstructionBoundaryConditions(type, - name, - testCase.testValues, - testCase.expectedValues)); - //verify(Content.testConstructionWithNullBuffer(type, name)); // V4VM? Float32Array ConstructionBoundaryConditions: Construction of Float32Array with null buffer should throw exception. Something to check in V4VM? - verify(Content.testConstructionWithOutOfRangeValues(type, name)); - //verify(Content.testConstructionWithNegativeOutOfRangeValues(type, name)); // V4VM? Float32Array ConstructionBoundaryConditions: Construction of Float32Array with negative out-of-range values should throw an exception. Something to check in V4VM? - //verify(Content.testConstructionWithUnalignedOffset(type, name, testCase.elementSizeInBytes)); // V4VM? Construction of Int8Array with out-of-range values threw an exception. Something to check in V4VM? - //verify(Content.testConstructionWithUnalignedLength(type, name, testCase.elementSizeInBytes)); // V4VM? Construction of Int8Array with out-of-range values threw an exception. Something to check in V4VM? - //verify(Content.testConstructionOfHugeArray(type, name, testCase.elementSizeInBytes)); // V4VM? Float32Array ConstructionBoundaryConditions: Construction of huge Float32Array should throw exception. Something to check in V4VM? - verify(Content.testConstructionWithBothArrayBufferAndLength(type, name, testCase.elementSizeInBytes)); - verify(Content.testSubarrayWithOutOfRangeValues(type, name, testCase.elementSizeInBytes)); - verify(Content.testSubarrayWithDefaultValues(type, name, testCase.elementSizeInBytes)); - verify(Content.testSettingFromArrayWithOutOfRangeOffset(type, name)); - verify(Content.testSettingFromFakeArrayWithOutOfRangeLength(type, name)); - verify(Content.testSettingFromTypedArrayWithOutOfRangeOffset(type, name)); - verify(Content.negativeTestGetAndSetMethods(type, name)); - verify(Content.testNaNConversion(type, name)); - } - } - } - - // array-large-array-tests.html - TestCase { - name: "Canvas3D_conformance_array_large_array_tests" - when: windowShown - - // Verifies allocation of large array buffers - function test_array_large_array() { - for (var i = 0; i < Content.testCases.length; i++) { - var testCase = Content.testCases[i]; - Content.running(testCase.name); - var type = testCase.type; - var name = testCase.name; - //verify(Content.testConstructionOfHugeArray(type, name, testCase.elementSizeInBytes)); // V4VM? Float32Array: Construction of huge Float32Array should throw exception - } - } - } - - // data-view-crash.html - TestCase { - name: "Canvas3D_conformance_data_view_crash" - when: windowShown - - function test_data_view_crash() { - verify(Content.dataView(), - "Test that DataView does not crash with bad offset or length.") - } - } - - // data-view-test.html - TestCase { - name: "Canvas3D_conformance_data_view_test" - when: windowShown - - function test_data_view_test_1() { - verify(Content.runConstructorTests()); - } - - function test_data_view_test_2() { - //verify(Content.runGetTests()); // V4VM? view.getUint8(0) should be 0. Threw exception TypeError: Property 'getUint8' of object [object Object] is not a function - } - - function test_data_view_test_3() { - //verify(Content.runSetTests()); // V4VM? view.setUint8(0, 0) fails - } - - function test_data_view_test_4() { - //verify(Content.runIndexingTests()); // V4VM? view.getUint8(0) should be 1. Threw exception TypeError: Property 'getUint8' of object [object Object] is not a function - } - } -} diff --git a/tests/auto/qmltest/canvas3d/tst_render_checkresult.js b/tests/auto/qmltest/canvas3d/tst_render_checkresult.js index c2d52af08d7815be69ac135f749dc9e75f1a3d3c..e4cb2df451f6eb4ff76374ee79c89598c41f87b6 100644 --- a/tests/auto/qmltest/canvas3d/tst_render_checkresult.js +++ b/tests/auto/qmltest/canvas3d/tst_render_checkresult.js @@ -34,7 +34,7 @@ ** ****************************************************************************/ -Qt.include("../../../../3rdparty/gl-matrix.js") +Qt.include("../../../../examples/3rdparty/gl-matrix.js") var gl; diff --git a/tests/auto/qmltest/qmltest.pro b/tests/auto/qmltest/qmltest.pro index b33e5c8c56537636b409201233f6937c235a4149..7661ff760b4cf8850e1f45423ffb36398590006c 100644 --- a/tests/auto/qmltest/qmltest.pro +++ b/tests/auto/qmltest/qmltest.pro @@ -7,5 +7,5 @@ CONFIG += console SOURCES += tst_qmltest.cpp -OTHER_FILES += canvas3d/tst_*.qml canvas3d/*.js canvas3d/*.png +OTHER_FILES += canvas3d/tst_*.qml canvas3d/*.js canvas3d/*.png ../../../examples/3rdparty/*.js DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$PWD/canvas3d\\\"\"