render task queue the color pick action

This commit is contained in:
2019-07-28 12:11:23 +02:00
parent 36be53aba5
commit 37331d4e24

View File

@@ -72,49 +72,51 @@ void Canvas::pick_update(int plane)
if (m_pick_ready[plane])
return;
// save viewport and clear color states
GLint vp[4];
GLfloat cc[4];
glGetIntegerv(GL_VIEWPORT, vp);
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
GLboolean blend = glIsEnabled(GL_BLEND);
// prepare common states
glViewport(0, 0, m_width, m_height);
glEnable(GL_BLEND);
int i = plane;
m_tmp[i].bindFramebuffer();
m_tmp[i].clear({ 1, 1, 1, 1 });
ShaderManager::use(kShader::TextureAlpha);
ShaderManager::u_int(kShaderUniform::Highlight, false);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
glActiveTexture(GL_TEXTURE0);
m_sampler.bind(0);
for (auto& l : m_layers)
App::I->render_task([this, plane]
{
if (!l->m_visible || l->m_opacity == 0.f)
continue;
ShaderManager::u_float(kShaderUniform::Alpha, l->m_opacity);
l->m_rtt[i].bindTexture();
m_plane.draw_fill();
l->m_rtt[i].unbindTexture();
}
m_sampler.unbind();
// save viewport and clear color states
GLint vp[4];
GLfloat cc[4];
glGetIntegerv(GL_VIEWPORT, vp);
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
GLboolean blend = glIsEnabled(GL_BLEND);
if (!m_pick_data[plane])
m_pick_data[plane] = std::make_unique<glm::u8vec4[]>(m_width*m_height);
glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, m_pick_data[plane].get());
m_tmp[i].unbindFramebuffer();
// restore viewport and clear color states
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
glViewport(vp[0], vp[1], vp[2], vp[3]);
glClearColor(cc[0], cc[1], cc[2], cc[3]);
glActiveTexture(GL_TEXTURE0);
// prepare common states
glViewport(0, 0, m_width, m_height);
glEnable(GL_BLEND);
int i = plane;
m_tmp[i].bindFramebuffer();
m_tmp[i].clear({ 1, 1, 1, 1 });
ShaderManager::use(kShader::TextureAlpha);
ShaderManager::u_int(kShaderUniform::Highlight, false);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
glActiveTexture(GL_TEXTURE0);
m_sampler.bind(0);
for (auto& l : m_layers)
{
if (!l->m_visible || l->m_opacity == 0.f)
continue;
ShaderManager::u_float(kShaderUniform::Alpha, l->m_opacity);
l->m_rtt[i].bindTexture();
m_plane.draw_fill();
l->m_rtt[i].unbindTexture();
}
m_sampler.unbind();
if (!m_pick_data[plane])
m_pick_data[plane] = std::make_unique<glm::u8vec4[]>(m_width * m_height);
glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, m_pick_data[plane].get());
m_tmp[i].unbindFramebuffer();
// restore viewport and clear color states
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
glViewport(vp[0], vp[1], vp[2], vp[3]);
glClearColor(cc[0], cc[1], cc[2], cc[3]);
glActiveTexture(GL_TEXTURE0);
});
m_pick_ready[plane] = true;
}