[英]Shader not working in Android - QT/QML Application
编辑:我是QT / QML和Android应用程序开发的初学者。
着色器在Android中不起作用-QT / QML应用程序
我已经使用QT / QML开发了一个应用程序,并将该应用程序移植到Andriod中。
我在应用程序中使用了着色器。
虽然在Android着色器中部署无法正常工作。
QOpenGLShader::compile(Fragment): ERROR: 0:11: ':' : wrong operand types no operation ':' exists that takes a left-hand operand of type 'float' and a right operand of type 'const int' (or there is no acceptable conversion)
varying highp vec2 qt_TexCoord0; // The coords within the source item uniform sampler2D source; // The source item texture
编辑
ShaderEffect {
anchors.fill: wrapper
id:shader
// Any property you add to the ShaderEffectItem is accessible as a
// "uniform" value in the shader program. See GLSL doc for details.
// Essentially, this is a value you pass to the fragment shader,
// which is the same for every pixel, thus its name.
// Here we add a source item (the scene) as a uniform value. Within the
// shader, we can access it as a sampler2D which is the type used to
// access pixels in a texture. So the source item becomes a texture.
property variant source: ShaderEffectSource
{
sourceItem: scene // The item you want to apply the effect to
hideSource: true // Only show the modified item, not the original
}
property real dividerValue: 0.9
// This is the fragment shader code in GLSL (GL Shading Language)
fragmentShader: "
varying highp vec2 qt_TexCoord0; // The coords within the source item
uniform sampler2D source; // The source item texture
uniform float dividerValue;
void main(void)
{
// Read the source color of the pixel
vec4 sourceColor = texture2D(source, qt_TexCoord0);
// The alpha value of the mask
float alpha = (qt_TexCoord0.x>dividerValue)?1.0:((qt_TexCoord0.x>(dividerValue-.1))?((qt_TexCoord0.x-(dividerValue-0.1))/0.1):0); // = 0.0 at left, 1.0 at right border
// float alpha = (qt_TexCoord0.x>dividerValue)?1.0:qt_TexCoord0.x/dividerValue;
// Multiply the alpha mask on the color to be drawn:
sourceColor *= alpha;
// Write the pixel to the output image
gl_FragColor = sourceColor;
}
"
float alpha = (qt_TexCoord0.x > dividerValue)
? 1.0
: ((qt_TexCoord0.x > (dividerValue-.1))
? ((qt_TexCoord0.x-(dividerValue-0.1)) / 0.1)
: 0);
错误在这里是很清楚的:这里没有运算符:
会在左边带float
,在右边带int
,这恰好是最后一个条件的情况,其中:
运算符( ((qt_TexCoord0.x-(dividerValue-0.1)) / 0.1))
)是float
,但右边( 0
)是一个int
。 只需将0
更改为0.0
(或.0
)即可,它是float
,应该可以使用。
我猜想Android设备上的着色器编译器对于隐式转换会更加挑剔。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.