merge layers and save to png
This commit is contained in:
@@ -414,10 +414,10 @@ void App::initLayout()
|
||||
//exit(0);
|
||||
if (canvas)
|
||||
{
|
||||
canvas->m_canvas->snapshot_save(data_path);
|
||||
canvas->m_canvas->m_use_instanced = !canvas->m_canvas->m_use_instanced;
|
||||
canvas->m_canvas->save(data_path);
|
||||
//canvas->m_canvas->m_use_instanced = !canvas->m_canvas->m_use_instanced;
|
||||
//button->color_normal = canvas->m_canvas->m_use_instanced ? glm::vec4(1, 0, 0, 1) : glm::vec4(0, 1, 0, 1);
|
||||
button->m_text->set_text(canvas->m_canvas->m_use_instanced ? "INST" : "NORM");
|
||||
//button->m_text->set_text(canvas->m_canvas->m_use_instanced ? "INST" : "NORM");
|
||||
}
|
||||
};
|
||||
button->m_text->set_text("NORM");
|
||||
|
||||
@@ -400,6 +400,69 @@ void ui::Canvas::clear_context()
|
||||
}
|
||||
};
|
||||
|
||||
void ui::Canvas::save(std::string data_path)
|
||||
{
|
||||
// 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);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_tmp[i].bindFramebuffer();
|
||||
m_tmp[i].clear({ 1, 1, 1, 1 });
|
||||
|
||||
for (auto layer_index : m_order)
|
||||
{
|
||||
// copy to tmp2 for layer blending
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_tex2[i].bind();
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height);
|
||||
m_tex2[i].unbind();
|
||||
|
||||
m_layers[layer_index].m_rtt[i].bindTexture();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
m_tex2[i].bind();
|
||||
m_sampler.bind(0);
|
||||
m_sampler_bg.bind(1);
|
||||
ShaderManager::use(ui::kShader::StrokeLayer);
|
||||
ShaderManager::u_int(kShaderUniform::TexBG, 1);
|
||||
ShaderManager::u_float(kShaderUniform::Alpha, m_layers[layer_index].m_opacity);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
|
||||
m_plane.draw_fill();
|
||||
m_sampler.unbind();
|
||||
m_sampler_bg.unbind();
|
||||
m_tex2[i].unbind();
|
||||
m_layers[layer_index].m_rtt[i].unbindTexture();
|
||||
}
|
||||
|
||||
m_tmp[i].unbindFramebuffer();
|
||||
}
|
||||
|
||||
auto data = std::make_unique<uint8_t[]>(m_tmp[0].bytes());
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_tmp[i].readTextureData(data.get());
|
||||
static char name[128];
|
||||
sprintf(name, "%s/Face%d.png", data_path.c_str(), i);
|
||||
LOG("writing %s", name);
|
||||
int ret = stbi_write_png(name, m_tmp[i].getWidth(), m_tmp[i].getHeight(), 4, data.get(), m_tmp[i].stride());
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ui::Layer::destroy()
|
||||
|
||||
@@ -75,6 +75,7 @@ public:
|
||||
void snapshot_save(std::string data_path);
|
||||
void snapshot_restore();
|
||||
void clear_context();
|
||||
void save(std::string data_path);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user