summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2019-05-24 10:13:53 +0300
committerAntti Määttä <antti.maatta@qt.io>2019-05-24 11:41:18 +0300
commitbd083f50691e35ac0ab572ebc92fe15dae2f2989 (patch)
treedf632e92d0182b126d4a656a5ff31d9da0f50f4d /src
parentf8eec0839b432d6d33b01ce748e47df5dfeda680 (diff)
Do not add fragOutput for custom materialsv2.4.0-beta2v2.4.0-beta1
Also do not require users to leave the main function open for custom shaders. Task-number: QT3DS-3544 Change-Id: I81a8969bb39d6716746b3172402bd9150461df67 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/runtime/q3dscustommaterialgenerator.cpp7
-rw-r--r--src/runtime/shadergenerator/q3dscustommaterialvertexpipeline.cpp11
-rw-r--r--src/runtime/shadergenerator/q3dsdefaultvertexpipeline.cpp4
-rw-r--r--src/runtime/shadergenerator/q3dsdefaultvertexpipeline_p.h4
-rw-r--r--src/runtime/shadergenerator/q3dsshadergenerators.cpp10
-rw-r--r--src/runtime/shadergenerator/q3dsshadergenerators_p.h4
6 files changed, 23 insertions, 17 deletions
diff --git a/src/runtime/q3dscustommaterialgenerator.cpp b/src/runtime/q3dscustommaterialgenerator.cpp
index 2566f49..43c80b3 100644
--- a/src/runtime/q3dscustommaterialgenerator.cpp
+++ b/src/runtime/q3dscustommaterialgenerator.cpp
@@ -110,8 +110,11 @@ Qt3DRender::QMaterial *Q3DSCustomMaterialGenerator::generateMaterial(
return material;
}
-void Q3DSCustomMaterialGenerator::fillFeatureSet(Q3DSShaderFeatureSet *features, Q3DSLayerNode *layer3DS, bool gles, Q3DSCustomMaterialInstance *material, Q3DSReferencedMaterial *referencedMaterial)
+void Q3DSCustomMaterialGenerator::fillFeatureSet(
+ Q3DSShaderFeatureSet *features, Q3DSLayerNode *layer3DS, bool gles,
+ Q3DSCustomMaterialInstance *material, Q3DSReferencedMaterial *referencedMaterial)
{
+ Q_UNUSED(gles);
Q3DSLayerAttached *layerData = static_cast<Q3DSLayerAttached *>(layer3DS->attached());
Q_ASSERT(layerData);
@@ -140,7 +143,7 @@ void Q3DSCustomMaterialGenerator::fillFeatureSet(Q3DSShaderFeatureSet *features,
features->append(Q3DSShaderPreprocessorFeature(QLatin1String("QT3DS_ENABLE_SSDO"), false));
features->append(Q3DSShaderPreprocessorFeature(QLatin1String("QT3DS_ENABLE_SSM"), !layerData->shadowMapData.shadowCasters.isEmpty()));
features->append(Q3DSShaderPreprocessorFeature(QLatin1String("QT3DS_ENABLE_SSAO"), layerData->ssaoTextureData.enabled));
- features->append(Q3DSShaderPreprocessorFeature(QLatin1String("Q3DS_NO_FRAGOUTPUT"), gles));
+ features->append(Q3DSShaderPreprocessorFeature(QLatin1String("Q3DS_NO_FRAGOUTPUT"), true));
}
QT_END_NAMESPACE
diff --git a/src/runtime/shadergenerator/q3dscustommaterialvertexpipeline.cpp b/src/runtime/shadergenerator/q3dscustommaterialvertexpipeline.cpp
index 91adec8..2705341 100644
--- a/src/runtime/shadergenerator/q3dscustommaterialvertexpipeline.cpp
+++ b/src/runtime/shadergenerator/q3dscustommaterialvertexpipeline.cpp
@@ -306,7 +306,7 @@ struct ShaderGenerator : public Q3DSCustomMaterialShaderGenerator
}
}
- void generateFragmentShader(const QString &shaderName, bool hasCustomVertexShader)
+ bool generateFragmentShader(const QString &shaderName, bool hasCustomVertexShader)
{
// Get the shader source from the Q3DSCustomMaterial based
// on the name provided. If there is only 1 shader then
@@ -388,7 +388,7 @@ struct ShaderGenerator : public Q3DSCustomMaterialShaderGenerator
vertexShader.generateViewVector();
}
addProperties(vertexShader, fragmentShader);
- return;
+ return true;
}
if (hasLighting && lightmapIndirectImage) {
@@ -485,15 +485,16 @@ struct ShaderGenerator : public Q3DSCustomMaterialShaderGenerator
fragmentShader << " rgba.a *= object_opacity;\n";
fragmentShader << " fragColor = rgba;\n";
+ return false;
}
Qt3DRender::QShaderProgram *generateCustomMaterialShader(const QString &shaderName)
{
bool hasCustomVertexShader = generateVertexShader(shaderName);
- generateFragmentShader(shaderName, hasCustomVertexShader);
+ bool hasCustomFragmentShader = generateFragmentShader(shaderName, hasCustomVertexShader);
- vertexGenerator().endVertexGeneration();
- vertexGenerator().endFragmentGeneration();
+ vertexGenerator().endVertexGeneration(hasCustomVertexShader);
+ vertexGenerator().endFragmentGeneration(hasCustomFragmentShader);
return programGenerator()->compileGeneratedShader(shaderName, m_currentFeatureSet);
}
diff --git a/src/runtime/shadergenerator/q3dsdefaultvertexpipeline.cpp b/src/runtime/shadergenerator/q3dsdefaultvertexpipeline.cpp
index 19fafb5..f5c19b8 100644
--- a/src/runtime/shadergenerator/q3dsdefaultvertexpipeline.cpp
+++ b/src/runtime/shadergenerator/q3dsdefaultvertexpipeline.cpp
@@ -1120,8 +1120,8 @@ struct ShaderGenerator : public Q3DSDefaultMaterialShaderGenerator
generateVertexShader();
generateFragmentShader();
- vertexGenerator().endVertexGeneration();
- vertexGenerator().endFragmentGeneration();
+ vertexGenerator().endVertexGeneration(false);
+ vertexGenerator().endFragmentGeneration(false);
return programGenerator()->compileGeneratedShader(description, m_CurrentFeatureSet);
}
diff --git a/src/runtime/shadergenerator/q3dsdefaultvertexpipeline_p.h b/src/runtime/shadergenerator/q3dsdefaultvertexpipeline_p.h
index 44aacf6..3c989a0 100644
--- a/src/runtime/shadergenerator/q3dsdefaultvertexpipeline_p.h
+++ b/src/runtime/shadergenerator/q3dsdefaultvertexpipeline_p.h
@@ -119,8 +119,8 @@ public:
virtual bool hasActiveWireframe() = 0; // varEdgeDistance is a valid entity
// responsible for closing all vertex and fragment generation
- virtual void endVertexGeneration() = 0;
- virtual void endFragmentGeneration() = 0;
+ virtual void endVertexGeneration(bool customShader) = 0;
+ virtual void endFragmentGeneration(bool customShader) = 0;
};
class Q3DSDefaultMaterialShaderGenerator : public Q3DSAbstractMaterialGenerator
diff --git a/src/runtime/shadergenerator/q3dsshadergenerators.cpp b/src/runtime/shadergenerator/q3dsshadergenerators.cpp
index 5b80881..1b4b9ce 100644
--- a/src/runtime/shadergenerator/q3dsshadergenerators.cpp
+++ b/src/runtime/shadergenerator/q3dsshadergenerators.cpp
@@ -348,7 +348,7 @@ void Q3DSSubsetMaterialVertexPipeline::doGenerateVertexColor()
vertex().append("\tvarColor = attr_color;");
}
-void Q3DSSubsetMaterialVertexPipeline::endVertexGeneration()
+void Q3DSSubsetMaterialVertexPipeline::endVertexGeneration(bool customShader)
{
if (hasTessellation()) {
@@ -365,12 +365,14 @@ void Q3DSSubsetMaterialVertexPipeline::endVertexGeneration()
finalizeWireframeGeometryShader();
geometry().append("}");
}
- vertex().append("}");
+ if (!customShader)
+ vertex().append("}");
}
-void Q3DSSubsetMaterialVertexPipeline::endFragmentGeneration()
+void Q3DSSubsetMaterialVertexPipeline::endFragmentGeneration(bool customShader)
{
- fragment().append("}");
+ if (!customShader)
+ fragment().append("}");
}
void Q3DSSubsetMaterialVertexPipeline::addInterpolationParameter(const char *inName, const char *inType)
diff --git a/src/runtime/shadergenerator/q3dsshadergenerators_p.h b/src/runtime/shadergenerator/q3dsshadergenerators_p.h
index 6ba5069..8cf2a7b 100644
--- a/src/runtime/shadergenerator/q3dsshadergenerators_p.h
+++ b/src/runtime/shadergenerator/q3dsshadergenerators_p.h
@@ -76,9 +76,9 @@ struct Q3DSSubsetMaterialVertexPipeline : public Q3DSVertexPipelineImpl
void doGenerateVertexColor() override;
- void endVertexGeneration() override;
+ void endVertexGeneration(bool customShader) override;
- void endFragmentGeneration() override;
+ void endFragmentGeneration(bool customShader) override;
void addInterpolationParameter(const char *inName, const char *inType) override;