render task queue the color pick action
This commit is contained in:
@@ -72,49 +72,51 @@ void Canvas::pick_update(int plane)
|
|||||||
if (m_pick_ready[plane])
|
if (m_pick_ready[plane])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// save viewport and clear color states
|
App::I->render_task([this, plane]
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
if (!l->m_visible || l->m_opacity == 0.f)
|
// save viewport and clear color states
|
||||||
continue;
|
GLint vp[4];
|
||||||
ShaderManager::u_float(kShaderUniform::Alpha, l->m_opacity);
|
GLfloat cc[4];
|
||||||
l->m_rtt[i].bindTexture();
|
glGetIntegerv(GL_VIEWPORT, vp);
|
||||||
m_plane.draw_fill();
|
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
|
||||||
l->m_rtt[i].unbindTexture();
|
GLboolean blend = glIsEnabled(GL_BLEND);
|
||||||
}
|
|
||||||
m_sampler.unbind();
|
|
||||||
|
|
||||||
if (!m_pick_data[plane])
|
// prepare common states
|
||||||
m_pick_data[plane] = std::make_unique<glm::u8vec4[]>(m_width*m_height);
|
glViewport(0, 0, m_width, m_height);
|
||||||
glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, m_pick_data[plane].get());
|
glEnable(GL_BLEND);
|
||||||
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);
|
|
||||||
|
|
||||||
|
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;
|
m_pick_ready[plane] = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user