简体   繁体   English

iOs OpenGL ES 2.0与设备和模拟器上的着色器混合

[英]iOs OpenGL ES 2.0 blending with shader on device and on simulator

Here is the fragment of fragment shader code (I need make blending in the shader): 这是片段着色器代码的片段(我需要在着色器中进行混合):

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);
}

Here are the blending function and equation: 这是混合函数和方程式:

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

And here are results on device (left) and on simulator (right): 这是设备(左)和模拟器(右)的结果:

在设备上在模拟器上

How to make so that it works like on an emulator? 如何使它像在模拟器上一样工作?

UPDATE: 更新:

I've removed discard : 我已经删除了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);

Now result on the device looks like: 现在设备上的结果如下:

在没有“丢弃”的设备上

I resolved this problem with adding glFlush after glDrawArrays . 我通过在glDrawArrays之后添加glFlush解决了这个问题。 The problem was that the texture was not updated when the drawing occurs in its associated framebuffer. 问题在于,当绘图在其关联的帧缓冲区中发生时,纹理没有更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM