我正在尝试创建ShaderEffect的别名。但是,当我这样做时:
Item {
id: root;
property color colorBackground: Qt.rgba(0.9, 0.9, 0.9, 1.0);
property color colorStroke: Qt.rgba(0.1, 0.1, 0.1, 1.0);
layer.enabled: true;
layer.effect: ShaderEffect {
property alias colorBackground: root.colorBackground;
property alias colorStroke: root.colorStroke;
fragmentShader: "
uniform lowp sampler2D source; // This item
uniform lowp float qt_Opacity; // Inherited opacity of this item
uniform lowp vec4 colorBackground;
varying highp vec2 qt_TexCoord0;
void main() {
lowp vec4 p = texture2D(source, qt_TexCoord0);
lowp float g = dot(p.xyz, vec3(0.344, 0.5, 0.156));
gl_FragColor = colorBackground;
}";
}
}
Unable to find id root
当我这么做的时候:
Item {
property alias colorBackground: shaderEffect.colorBackground;
property alias colorStroke: shaderEffect.colorStroke;
layer.enabled: true;
layer.effect: ShaderEffect {
id: shaderEffect;
property color colorBackground: Qt.rgba(0.9, 0.9, 0.9, 1.0);
property color colorStroke: Qt.rgba(0.1, 0.1, 0.1, 1.0);
fragmentShader: "
uniform lowp sampler2D source; // This item
uniform lowp float qt_Opacity; // Inherited opacity of this item
uniform lowp vec4 color;
varying highp vec2 qt_TexCoord0;
void main() {
lowp vec4 p = texture2D(source, qt_TexCoord0);
lowp float g = dot(p.xyz, vec3(0.344, 0.5, 0.156));
gl_FragColor = color;
}";
}
}
我得到了同样的错误,但与shaderEffect。
如何解决这个问题?