gpt4 book ai didi

qt - QOpenGLShaderProgram : is possible to make error output nice?

转载 作者:行者123 更新时间:2023-12-03 07:54:12 26 4
gpt4 key购买 nike

我正在通过OpenGL和Qt在GPU上实现一些数值算法。
但是我不是很熟悉。
我想从当前着色器中提取一些函数到某个“着色器库”,并通过字符串插值在其他着色器中使用它。实现起来并不难,但我不知道如何处理着色器的编译错误

我使用以下代码来编译着色器

QOpenGLShaderProgram *shaderProgram = new QOpenGLShaderProgram();
if (!shaderProgram->addShaderFromSourceFile(QOpenGLShader::Fragment,fragmentShaderFileName)) {
qDebug() << "Failed to compile fragment shader";
//..........

当出现一些编译错误时,Qt将显示以下消息(示例)
QOpenGLShader::compile(Fragment): 0:331(9): error: syntax error, unexpected NEW_IDENTIFIER, expecting ',' or ';'

*** Problematic Fragment shader source code ***
//my shader source code

是否可以捕获错误行号并使用它来构建我自己的错误消息? (带有突出显示的行)

最佳答案

根据Qt文档,您可以使用 QOpenGLShaderProgram::log() :

Returns the errors and warnings that occurred during the last link() or addShader() with explicitly specified source code.



然后,您可以解析结果字符串以构建自己的错误消息。

关于qt - QOpenGLShaderProgram : is possible to make error output nice?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30436195/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com