diff options
author | Andy Nichols <andy.nichols@qt.io> | 2017-12-07 16:59:21 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-01-05 08:18:45 +0000 |
commit | 561ebae1b9d0c8b06720f90c4a970a3c47733bab (patch) | |
tree | 90cc4acc9d7fa9eb11359db39234f5fc69174df6 | |
parent | d95aad8e20645718ec2806c5f77622e51905e798 (diff) |
Cleanup unused methods in Q3DSCustomMaterial
This is where the material generation code was previously.
Also removed the now useless test associated with material generation by
the Q3DSCustomMaterial.
Change-Id: Ia9460396cf45f2ba72535c27b2c302c57e218afa
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r-- | src/runtime/q3dscustommaterial.cpp | 109 | ||||
-rw-r--r-- | src/runtime/q3dscustommaterial.h | 8 | ||||
-rw-r--r-- | tests/auto/materialparser/tst_q3dscustommaterialparser.cpp | 14 |
3 files changed, 0 insertions, 131 deletions
diff --git a/src/runtime/q3dscustommaterial.cpp b/src/runtime/q3dscustommaterial.cpp index d1fb038..e265754 100644 --- a/src/runtime/q3dscustommaterial.cpp +++ b/src/runtime/q3dscustommaterial.cpp @@ -50,10 +50,6 @@ Q3DSCustomMaterial::Q3DSCustomMaterial() { } -Q3DSCustomMaterial::~Q3DSCustomMaterial() -{ -} - QString Q3DSCustomMaterial::name() const { return m_name; @@ -104,111 +100,6 @@ const QHash<QString, Q3DSMaterial::Buffer> &Q3DSCustomMaterial::buffers() const return m_buffers; } -Qt3DRender::QMaterial *Q3DSCustomMaterial::generateMaterial() -{ - auto material = new Qt3DRender::QMaterial(); - auto *effect = new Qt3DRender::QEffect(); - auto *technique = new Qt3DRender::QTechnique(); - QVector<Qt3DRender::QRenderPass *> renderPasses; - QVector<Qt3DRender::QShaderProgram *> shaderPrograms; - - QString shaderPrefix = QStringLiteral("#include \"customMaterial.glsllib\"\n"); - - // Generate completed Shader Code (resolve #includes) - // Add Shaders to shader program - for (auto shader: m_shaders) { - shaderPrograms.append(generateShaderProgram(shader, m_shadersSharedCode, shaderPrefix)); - } - - // TODO: Create A RenderPasses for each pass - - // TODO: Add Shader program to each Render pass as needed (1 : 1) - - - // Add Renderpasses to technique - for (auto renderpass : renderPasses) { - technique->addRenderPass(renderpass); - } - - // Add Technique to Effect - effect->addTechnique(technique); - - // Add parameters to effect - //for (auto parameter : parameters) - // effect->addParameter(parameter); - - // Set the Effect to be active for this material - material->setEffect(effect); - - return material; -} - -Qt3DRender::QShaderProgram* Q3DSCustomMaterial::generateShaderProgram(const Q3DSMaterial::Shader &shader, const QString &globalSharedCode, const QString &shaderPrefixCode) const -{ - QString shaderPrefix = resolveShaderIncludes(shaderPrefixCode); - QString globalShared = resolveShaderIncludes(globalSharedCode); - QString shared = resolveShaderIncludes(shader.shared); - QString vertexShader = resolveShaderIncludes(shader.vertexShader); - QString fragmentShader = resolveShaderIncludes(shader.fragmentShader); - - // Initialize - if (vertexShader.isEmpty()) - vertexShader.append(QLatin1String("void vert(){}")); - - if (fragmentShader.isEmpty()) - fragmentShader.append(QLatin1String("void frag(){}")); - - // Assemble - QByteArray vertexShaderCode; - QByteArray fragmentShaderCode; - // Vertex - vertexShaderCode.append(shaderPrefix.toUtf8()); - vertexShaderCode.append(globalShared.toUtf8()); - vertexShaderCode.append(shared.toUtf8()); - vertexShaderCode.append(QByteArrayLiteral("\n#ifdef VERTEX_SHADER\n")); - vertexShaderCode.append(vertexShader.toUtf8()); - vertexShaderCode.append(QByteArrayLiteral("\n#endif\n")); - - // Fragment - fragmentShaderCode.append(shaderPrefix.toUtf8()); - fragmentShaderCode.append(globalShared.toUtf8()); - fragmentShaderCode.append(shared.toUtf8()); - fragmentShaderCode.append(QByteArrayLiteral("\n#ifdef FRAGMENT_SHADER\n")); - fragmentShaderCode.append(fragmentShader.toUtf8()); - fragmentShaderCode.append(QByteArrayLiteral("\n#endif\n")); - - auto shaderProgram = new Qt3DRender::QShaderProgram(); - shaderProgram->setVertexShaderCode(vertexShaderCode); - shaderProgram->setFragmentShaderCode(fragmentShaderCode); - return shaderProgram; -} - -QString Q3DSCustomMaterial::resolveShaderIncludes(const QString &shaderCode) const -{ - QString output; - QTextStream inputStream(const_cast<QString*>(&shaderCode), QIODevice::ReadOnly); - QString currentLine; - while (inputStream.readLineInto(¤tLine)) { - // Check if starts with #include - currentLine = currentLine.trimmed(); - if (currentLine.startsWith(QStringLiteral("#include"))) { - QString fileName = currentLine.split('"', QString::SkipEmptyParts).last(); - fileName.prepend(Q3DSUtils::resourcePrefix() + QLatin1String("res/effectlib/")); - QFile file(fileName); - if (!file.open(QIODevice::ReadOnly)) - qWarning() << QObject::tr("Could not open glsllib '%1'").arg(fileName); - else - output.append(QString::fromUtf8(file.readAll())); - file.close(); - output.append(QLatin1String("\n")); - } else { - output.append(currentLine); - output.append(QLatin1String("\n")); - } - } - return output; -} - int Q3DSCustomMaterial::layerCount() const { return m_layerCount; diff --git a/src/runtime/q3dscustommaterial.h b/src/runtime/q3dscustommaterial.h index 496feb8..8b68b73 100644 --- a/src/runtime/q3dscustommaterial.h +++ b/src/runtime/q3dscustommaterial.h @@ -47,7 +47,6 @@ class Q3DSV_EXPORT Q3DSCustomMaterial { public: Q3DSCustomMaterial(); - ~Q3DSCustomMaterial(); QString name() const; QString description() const; @@ -63,8 +62,6 @@ public: const QVector<Q3DSMaterial::Pass> &passes() const; const QHash<QString, Q3DSMaterial::Buffer> &buffers() const; - Qt3DRender::QMaterial *generateMaterial(); - bool isAlwaysDirty() const; int layerCount() const; // nothing to do with normal layers @@ -85,11 +82,6 @@ public: bool materialHasRefraction() const; private: - Qt3DRender::QShaderProgram *generateShaderProgram(const Q3DSMaterial::Shader &shader, - const QString &globalSharedCode, - const QString &shaderPrefixCode) const; - QString resolveShaderIncludes(const QString &shaderCode) const; - // MaterialElement QString m_name; QString m_description; diff --git a/tests/auto/materialparser/tst_q3dscustommaterialparser.cpp b/tests/auto/materialparser/tst_q3dscustommaterialparser.cpp index 73f5ca2..f441d54 100644 --- a/tests/auto/materialparser/tst_q3dscustommaterialparser.cpp +++ b/tests/auto/materialparser/tst_q3dscustommaterialparser.cpp @@ -45,7 +45,6 @@ private Q_SLOTS: void testInvalid(); void testRepeatedLoad(); void testValidateData(); - void testMaterialGeneration(); void testCommands(); void testBuffers(); }; @@ -152,19 +151,6 @@ void tst_Q3DSCustomMaterialParser::testValidateData() QVERIFY(material.shaderIsGlossy()); } -void tst_Q3DSCustomMaterialParser::testMaterialGeneration() -{ - Q3DSCustomMaterialParser parser; - bool ok = false; - auto customMaterial = parser.parse(QStringLiteral(":/data/carbon_fiber.material"), &ok); - QVERIFY(ok); - - auto material = customMaterial.generateMaterial(); - QVERIFY(material != nullptr); - - delete material; -} - void tst_Q3DSCustomMaterialParser::testCommands() { Q3DSCustomMaterialParser parser; |