本文整理汇总了C++中QOpenGLShader::sourceCode方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLShader::sourceCode方法的具体用法?C++ QOpenGLShader::sourceCode怎么用?C++ QOpenGLShader::sourceCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLShader
的用法示例。
在下文中一共展示了QOpenGLShader::sourceCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shaderCache
//.........这里部分代码省略.........
description.append("Fragment shader: main=");
description.append(snippetNameStr(prog.mainFragShader));
description.append(", srcPixel=");
description.append(snippetNameStr(prog.srcPixelFragShader));
if (prog.compositionFragShader) {
description.append(", composition=");
description.append(snippetNameStr(prog.compositionFragShader));
}
if (prog.maskFragShader) {
description.append(", mask=");
description.append(snippetNameStr(prog.maskFragShader));
}
fragShader->setObjectName(QString::fromLatin1(description));
#endif
if (!fragShader->compileSourceCode(fragSource)) {
qWarning() << "Warning:" << description << "failed to compile!";
break;
}
QScopedPointer<QOpenGLShader> vertexShader(new QOpenGLShader(QOpenGLShader::Vertex));
#if defined(QT_DEBUG)
// Name the shader for easier debugging
description.clear();
description.append("Vertex shader: main=");
description.append(snippetNameStr(prog.mainVertexShader));
description.append(", position=");
description.append(snippetNameStr(prog.positionVertexShader));
vertexShader->setObjectName(QString::fromLatin1(description));
#endif
if (!vertexShader->compileSourceCode(vertexSource)) {
qWarning() << "Warning:" << description << "failed to compile!";
break;
}
shaders.append(vertexShader.data());
shaders.append(fragShader.data());
shaderProgram->addShader(vertexShader.take());
shaderProgram->addShader(fragShader.take());
// We have to bind the vertex attribute names before the program is linked:
shaderProgram->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
if (prog.useTextureCoords)
shaderProgram->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
if (prog.useOpacityAttribute)
shaderProgram->bindAttributeLocation("opacityArray", QT_OPACITY_ATTR);
if (prog.usePmvMatrixAttribute) {
shaderProgram->bindAttributeLocation("pmvMatrix1", QT_PMV_MATRIX_1_ATTR);
shaderProgram->bindAttributeLocation("pmvMatrix2", QT_PMV_MATRIX_2_ATTR);
shaderProgram->bindAttributeLocation("pmvMatrix3", QT_PMV_MATRIX_3_ATTR);
}
}
newProg.reset(new QOpenGLEngineShaderProg(prog));
newProg->program = shaderProgram.take();
newProg->program->link();
if (newProg->program->isLinked()) {
if (!inCache)
shaderCache.store(newProg->program, QOpenGLContext::currentContext());
} else {
QLatin1String none("none");
QLatin1String br("\n");
QString error;
error = QLatin1String("Shader program failed to link,");
#if defined(QT_DEBUG)
error += QLatin1String("\n Shaders Used:\n");
for (int i = 0; i < newProg->program->shaders().count(); ++i) {
QOpenGLShader *shader = newProg->program->shaders().at(i);
error += QLatin1String(" ") + shader->objectName() + QLatin1String(": \n")
+ QLatin1String(shader->sourceCode()) + br;
}
#endif
error += QLatin1String(" Error Log:\n")
+ QLatin1String(" ") + newProg->program->log();
qWarning() << error;
break;
}
newProg->program->bind();
if (newProg->maskFragShader != QOpenGLEngineSharedShaders::NoMaskFragmentShader) {
GLuint location = newProg->program->uniformLocation("maskTexture");
newProg->program->setUniformValue(location, QT_MASK_TEXTURE_UNIT);
}
if (cachedPrograms.count() > 30) {
// The cache is full, so delete the last 5 programs in the list.
// These programs will be least used, as a program us bumped to
// the top of the list when it's used.
for (int i = 0; i < 5; ++i) {
delete cachedPrograms.last();
cachedPrograms.removeLast();
}
}
cachedPrograms.insert(0, newProg.data());
} while (false);
return newProg.take();
}