Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt:请求GL ES 3.0时,所有Canvas3D渲染都会中断_Qt_Opengl Es_Qml_Qtquick2_Opengl Es 3.0 - Fatal编程技术网

Qt:请求GL ES 3.0时,所有Canvas3D渲染都会中断

Qt:请求GL ES 3.0时,所有Canvas3D渲染都会中断,qt,opengl-es,qml,qtquick2,opengl-es-3.0,Qt,Opengl Es,Qml,Qtquick2,Opengl Es 3.0,我已经将它提炼成一个完全微不足道的测试用例。在main()中,我请求一个GL ES 3.0上下文。在Canvas3D代码中,我首先设置了所有低级的东西,比如着色器、顶点缓冲区和矩阵。然后我画一个白色三角形。结果是一个窗口,以高频在所有黑白(闪烁)之间交替。也就是说,完全是四轮马车 将我请求的3.0版本更改为2.0版本可以修复它,并且在我的真实应用程序中,可以让所有其他GL功能正常工作 请注意,除Canvas3D之外的QML项目渲染良好。 平台注意:这只在一台PC上进行了测试,规格如下: 操作系

我已经将它提炼成一个完全微不足道的测试用例。在main()中,我请求一个GL ES 3.0上下文。在Canvas3D代码中,我首先设置了所有低级的东西,比如着色器、顶点缓冲区和矩阵。然后我画一个白色三角形。结果是一个窗口,以高频在所有黑白(闪烁)之间交替。也就是说,完全是四轮马车

将我请求的3.0版本更改为2.0版本可以修复它,并且在我的真实应用程序中,可以让所有其他GL功能正常工作

请注意,除Canvas3D之外的QML项目渲染良好。

平台注意:这只在一台PC上进行了测试,规格如下:

  • 操作系统:Windows7
  • GPU:移动英特尔(R)4系列Express芯片组系列
  • GPU驱动程序版本:8.15.10.2869
我的代码:

我的测试用例基于与Qt捆绑的
textureandlight
示例应用程序。由于我的是衍生作品,我必须首先在这里发布许可条款:

/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCanvas3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** 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 https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
现在是实际来源

main.cpp:

GLCode.js:

必需的js库:“glMatrix 2.2.2”。我在它的官方网站上找不到这个确切的版本,但是你可以得到几乎相同的版本(2.2.1)

如果您想更轻松地运行,我还上传了完整的测试用例项目。(下载按钮位于该页面的右上角)。请忽略令人困惑的项目名称,这是一个遗留问题


注意:我相信我的机器可以运行GL ES 3.0,因为实现了
GL ES 3.0->D3D 11
API翻译支持的说法(在靠近开头的表格中)。我的系统支持D3D11,符合
dxdiag.exe
。此外,当我显示
OpenGLInfo.majorvision+“+OpenGLInfo.minorVersion
”的值时,会显示
3.0
,这意味着Qt至少名义上成功地为我提供了一个GLES 3.0上下文。

为什么你认为OpenGL3在你的平台上得到了正确的实现?您使用什么OpenGL选项?你是如何编译Qt的?您使用的确切适配器及其驱动程序版本是什么?@Kuba Ober:我不是假设为GL 3.0,我假设为GL ES 3.0,这是不同的。如果您假设它已正确实现,请参阅我的编辑。关于“您使用什么OpenGL选项?”的答案,我想您应该看看我的主函数,在这里我调用
setAttribute(Qt::AA_UseOpenGLES)。重新编译Qt-我没有,我下载了一个二进制Windows安装程序(我相信源URL是)。我不知道你所说的适配器是什么意思-你是说GPU吗?也许把你的代码运行到apitrace中,看看是否有错误产生?AFAIR ES3与ES2兼容,因此Canvas3D可能会做一些愚蠢的事情。还要检查Qt的bugtracker上是否有打开的bug。为什么您认为OpenGL3在您的平台上得到了正确的实现?您使用什么OpenGL选项?你是如何编译Qt的?您使用的确切适配器及其驱动程序版本是什么?@Kuba Ober:我不是假设为GL 3.0,我假设为GL ES 3.0,这是不同的。如果您假设它已正确实现,请参阅我的编辑。关于“您使用什么OpenGL选项?”的答案,我想您应该看看我的主函数,在这里我调用
setAttribute(Qt::AA_UseOpenGLES)。重新编译Qt-我没有,我下载了一个二进制Windows安装程序(我相信源URL是)。我不知道你所说的适配器是什么意思-你是说GPU吗?也许把你的代码运行到apitrace中,看看是否有错误产生?AFAIR ES3与ES2兼容,因此Canvas3D可能会做一些愚蠢的事情。还要检查Qt的bugtracker上是否有打开的bug。
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QSurfaceFormat>

static QSurfaceFormat createSurfaceFormat() {
    QSurfaceFormat format;
    format.setVersion(3, 0);
    return format;
}

int main(int argc, char *argv[])
{
    QSurfaceFormat::setDefaultFormat(::createSurfaceFormat());
    QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}
import QtQuick 2.0
import QtCanvas3D 1.0
import QtQuick.Window 2.0

import "GLCode.js" as GLCode

Window {
    width: 800
    height: 500
    visible: true

    Canvas3D {
        anchors.fill: parent

        id: canvas3d

        onInitializeGL: {
            GLCode.initializeGL();
        }

        onPaintGL: {
            GLCode.paintGL();
        }

        onResizeGL: {
            GLCode.resizeGL();
        }
    }
}
Qt.include("gl-matrix.js")

var gl;
var vertexPositionAttribute;
var mvMatrix = mat4.create();
var pMatrix  = mat4.create();
var pMatrixUniform;
var mvMatrixUniform;
var colorUniform; // unused. removing it produced a weird error. please ignore.

function initializeGL() {
    gl = canvas3d.getContext("canvas3d");

    gl.disable(gl.DEPTH_TEST);
    gl.disable(gl.CULL_FACE);
    gl.clearColor(0.0, 0.0, 0.0, 1.0);

    initShaders();

    initBuffers();
}

function resizeGL()
{
    gl.viewport(0, 0, canvas3d.width, canvas3d.height);
    mat4.perspective(pMatrix, degToRad(45), canvas3d.width / canvas3d.height, 0.1, 500.0);
    gl.uniformMatrix4fv(pMatrixUniform, false, pMatrix);
}

function degToRad(degrees) {
    return degrees * Math.PI / 180;
}

function paintGL() {
    gl.clear(gl.COLOR_BUFFER_BIT);

    mat4.identity(mvMatrix);
    mat4.translate(mvMatrix, mvMatrix, [0, 0, -10.0]);

    gl.uniformMatrix4fv(mvMatrixUniform, false, mvMatrix);
    gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0);
}

function initBuffers()
{
    var cubeVertexPositionBuffer = gl.createBuffer();
    cubeVertexPositionBuffer.name = "cubeVertexPositionBuffer";
    gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
    gl.bufferData(gl.ARRAY_BUFFER,
                new Float32Array([
                                        -1.0, -1.0,
                                        1.0, -1.0,
                                        1.0,  1.0
                                 ]),
                gl.STATIC_DRAW);

    gl.vertexAttribPointer(vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);

    var cubeVertexIndexBuffer = gl.createBuffer();
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);
    gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,
                  new Uint16Array([0,  1,  2]),
                  gl.STATIC_DRAW);
}

function initShaders()
{
    var vertexShader = getShader(gl,
                                  "attribute highp vec3 aVertexPosition;  \
                                                                         \
                                  uniform mat4 uMVMatrix;                \
                                  uniform mat4 uPMatrix;                 \
                                                                         \
                                  void main(void) {                      \
                                      gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \
                                  }"
                                 , gl.VERTEX_SHADER);
    var fragmentShader = getShader(gl,
                                   "void main(void) {                  \
                                        gl_FragColor = vec4(1.0);           \
                                    }"
                                   , gl.FRAGMENT_SHADER);
    var shaderProgram = gl.createProgram();

    gl.attachShader(shaderProgram, vertexShader);
    gl.attachShader(shaderProgram, fragmentShader);

    gl.linkProgram(shaderProgram);

    if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
        console.log("Could not initialise shaders");
        console.log(gl.getProgramInfoLog(shaderProgram));
    }

    gl.useProgram(shaderProgram);

    vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
    gl.enableVertexAttribArray(vertexPositionAttribute);

    pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
    mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
}

function getShader(gl, str, type) {
    var shader = gl.createShader(type);
    gl.shaderSource(shader, str);
    gl.compileShader(shader);

    if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
        console.log("JS:Shader compile failed");
        console.log(gl.getShaderInfoLog(shader));
        return null;
    }

    return shader;
}