2017-01-10 25 views
0

編輯: 我很開心QT/QML和Android應用程序開發。着色器不能在Android工作 - QT/QML應用程序

着色器在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; 
     } 
     " 
+2

老兄,你在SO 5年。你至少可以重新格式化這段代碼,澄清你的問題嗎? – folibis

回答

2
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,但左側t方(0)是int。只需將0更改爲0.0(或.0)即float,它應該可以工作。

我猜Android設備上的着色器編譯器對隱式轉換更挑剔。

+1

@Daniel:非常感謝。這完全解決了我的問題。 –

相關問題