add ComboBox node, add blend modes button in stroke panel, move brush shader code to ShaderManager and avoid the same shader being recompiled many times

This commit is contained in:
2017-11-12 03:02:40 +00:00
parent fa4e67617b
commit daaa7f9d48
16 changed files with 154 additions and 54 deletions

View File

@@ -90,44 +90,10 @@ bool ui::BrushMesh::create()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// STROKE - INSTANCED
static const char* shader_stroke_inst_v =
SHADER_VERSION
"in vec4 pos;"
"in vec2 uvs;"
"in mat4 a_mvp;"
"in float a_flow;"
"out vec3 uv;"
"out float alpha;"
"void main(){"
" uv = vec3(uvs, pos.w);"
" alpha = a_flow;"
" gl_Position = a_mvp * vec4(pos.xyz, 1.0);"
"}";
static const char* shader_stroke_inst_f =
SHADER_VERSION
"uniform mediump sampler2D tex;"
"uniform mediump sampler2D tex_stencil;\n"
"uniform mediump vec4 col;"
"uniform mediump vec2 resolution;\n"
"uniform mediump vec2 stencil_offset;\n"
"uniform mediump float stencil_alpha;\n"
"in mediump float alpha;"
"in mediump vec3 uv;"
"out mediump vec4 frag;"
"void main(){"
" mediump vec2 uv2 = gl_FragCoord.st / resolution;\n"
" mediump float stencil = 1.0 - (texture(tex_stencil, (uv2+stencil_offset)).r * 0.9) * stencil_alpha;\n"
" mediump float a = (1.0 - texture(tex, uv.xy).r) * alpha * stencil;"
" frag = vec4(col.rgb, a);"
"}";
auto shader = ShaderManager::get(kShader::BrushStroke);
if (!shader.create(shader_stroke_inst_v, shader_stroke_inst_f))
LOG("Failed to create shader BrushMesh Stroke");
loc_flow = shader.GetAttribLocation("a_flow");
loc_mvp = shader.GetAttribLocation("a_mvp");
loc_flow = shader->GetAttribLocation("a_flow");
loc_mvp = shader->GetAttribLocation("a_mvp");
#if USE_VBO
glGenVertexArrays(1, &vao);