2013-02-05 61 views
1

這裏着色器是的片段着色器代碼片段(我需要使混合在着色器):IOS的​​OpenGL ES 2.0共混與設備和模擬器

float a = texture2D(tMask, texCoords).x; // opacity of current pixel from mask texture. 
if (a == 0.0) 
    discard; 
else { 
    vec4 dst_clr = texture2D(tBkgText, posCoords); // color of current pixel in current framebuffer. 
    vec4 src_clr = vec4(vColor.rgb, sOpacity); 
    gl_FragColor = src_clr * a + dst_clr * (1.0 - a); 
} 

下面是混合功能和等式:

glBlendFunc(GL_ONE, GL_ZERO); 
glBlendEquation(GL_FUNC_ADD); 

這裏是在設備上(左)結果和模擬器(右):

on device on simulator

如何使它在仿真器上工作?

UPDATE:

我已經刪除discard

float a = texture2D(tMask, texCoords).x; // opacity of current pixel from mask texture. 
vec4 dst_clr = texture2D(tBkgText, posCoords); // color of current pixel in current framebuffer. 
vec4 src_clr = vec4(vColor.rgb, sOpacity); 
gl_FragColor = src_clr * a + dst_clr * (1.0 - a); 

現在導致在設備上的樣子:

on device without "discard"

+0

啓用混合?同樣,iOS設備上的'discard()'可能非常昂貴,if()'語句也是如此,所以你可能會更好地移除該條件,並始終將alpha值傳遞到計算中,即使它是0. –

+0

是的,當然,混合是啓用。你可以在模擬器的例子中看到這個。 – George

回答

0

我用後加入glFlush解決了這個問題glDrawArrays。問題在於當繪圖出現在關聯的幀緩衝區中時紋理未被更新。