implement framebuffer fetch on iOS for bleding
This commit is contained in:
@@ -85,16 +85,27 @@ void App::initShaders()
|
||||
"}\n";
|
||||
static const char* shader_blend_f =
|
||||
SHADER_VERSION
|
||||
#ifdef __IOS__
|
||||
"#extension GL_EXT_shader_framebuffer_fetch : enable\n"
|
||||
#endif
|
||||
"uniform sampler2D tex;\n"
|
||||
"uniform sampler2D tex_alpha;\n"
|
||||
"uniform sampler2D tex_bg;\n"
|
||||
"uniform mediump float alpha;\n"
|
||||
"uniform int blend_mode;\n"
|
||||
"in mediump vec2 uv;\n"
|
||||
#ifdef __IOS__
|
||||
"inout mediump vec4 frag;\n"
|
||||
#else
|
||||
"out mediump vec4 frag;\n"
|
||||
#endif
|
||||
SHADER_FUNCTION_BLEND
|
||||
"void main() {\n"
|
||||
#ifdef __IOS__
|
||||
" mediump vec4 bg = frag;\n"
|
||||
#else
|
||||
" mediump vec4 bg = texture(tex_bg, uv);\n"
|
||||
#endif
|
||||
" mediump vec4 fg = vec4(texture(tex, uv).rgb, texture(tex_alpha, uv).a);\n"
|
||||
" if (fg.a == 0.0) { frag = bg; return; }\n"
|
||||
" mediump float contribution = (1.0 - bg.a) * fg.a;\n"
|
||||
@@ -338,7 +349,6 @@ void App::initShaders()
|
||||
SHADER_VERSION
|
||||
#ifdef __IOS__
|
||||
"#extension GL_EXT_shader_framebuffer_fetch : enable\n"
|
||||
// "#extension GL_EXT_shader_image_load_store : enable\n"
|
||||
#endif
|
||||
"uniform mediump sampler2D tex;\n"
|
||||
"uniform mediump sampler2D tex_bg;\n"
|
||||
|
||||
@@ -271,7 +271,9 @@ void NodeCanvas::draw()
|
||||
ShaderManager::use(kShader::TextureBlend);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_int(kShaderUniform::TexA, 1);
|
||||
#ifndef __IOS__
|
||||
ShaderManager::u_int(kShaderUniform::TexBG, 2);
|
||||
#endif
|
||||
ShaderManager::u_int(kShaderUniform::BlendMode, m_canvas->m_layers[layer_index].m_blend_mode);
|
||||
ShaderManager::u_float(kShaderUniform::Alpha, 1.f);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-1, 1, -1, 1));
|
||||
@@ -280,16 +282,21 @@ void NodeCanvas::draw()
|
||||
m_blender_rtt.bindTexture();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
m_blender_rtt.bindTexture();
|
||||
#ifndef __IOS__
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
m_blender_bg.bind();
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_blender_bg.size().x, m_blender_bg.size().y);
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0,
|
||||
m_blender_bg.size().x, m_blender_bg.size().y);
|
||||
#endif
|
||||
|
||||
m_face_plane.draw_fill();
|
||||
|
||||
#ifndef __IOS__
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
m_blender_bg.unbind();
|
||||
#endif
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
m_blender_bg.unbind();
|
||||
m_blender_rtt.unbindTexture();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_blender_rtt.unbindTexture();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user