add NodeImageTexture for dynamic images, test image thumbnail opening and rendering
This commit is contained in:
@@ -212,7 +212,7 @@ void ui::Canvas::stroke_draw()
|
||||
}
|
||||
void ui::Canvas::stroke_commit()
|
||||
{
|
||||
if (!m_dirty)
|
||||
if (!m_dirty || m_layers.empty())
|
||||
return;
|
||||
m_dirty = false;
|
||||
|
||||
@@ -503,7 +503,7 @@ void ui::Canvas::save(std::string data_path)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
void ui::Canvas::save_project(std::string data_path)
|
||||
void ui::Canvas::project_save(std::string data_path)
|
||||
{
|
||||
static char name[128];
|
||||
sprintf(name, "%s/latlong.pano", data_path.c_str());
|
||||
@@ -513,6 +513,14 @@ void ui::Canvas::save_project(std::string data_path)
|
||||
LOG("cannot write project to %s", name);
|
||||
return;
|
||||
}
|
||||
|
||||
// load thumbnail
|
||||
Image thumb = thumbnail_generate(64, 64);
|
||||
fwrite(&thumb.width, sizeof(int), 1, fp);
|
||||
fwrite(&thumb.height, sizeof(int), 1, fp);
|
||||
fwrite(&thumb.comp, sizeof(int), 1, fp);
|
||||
fwrite(thumb.data(), thumb.size(), 1, fp);
|
||||
|
||||
fwrite(&m_width, sizeof(int), 1, fp);
|
||||
fwrite(&m_height, sizeof(int), 1, fp);
|
||||
|
||||
@@ -538,7 +546,7 @@ void ui::Canvas::save_project(std::string data_path)
|
||||
LOG("project saved to %s", name);
|
||||
}
|
||||
|
||||
void ui::Canvas::open_project(std::string data_path)
|
||||
void ui::Canvas::project_open(std::string data_path)
|
||||
{
|
||||
static char name[128];
|
||||
sprintf(name, "%s/latlong.pano", data_path.c_str());
|
||||
@@ -548,6 +556,14 @@ void ui::Canvas::open_project(std::string data_path)
|
||||
LOG("cannot write project to %s", name);
|
||||
return;
|
||||
}
|
||||
|
||||
// skip thumbnail
|
||||
Image thumb;
|
||||
fread(&thumb.width, sizeof(int), 1, fp);
|
||||
fread(&thumb.height, sizeof(int), 1, fp);
|
||||
fread(&thumb.comp, sizeof(int), 1, fp);
|
||||
fseek(fp, thumb.size(), SEEK_CUR);
|
||||
|
||||
fread(&m_width, sizeof(int), 1, fp);
|
||||
fread(&m_height, sizeof(int), 1, fp);
|
||||
|
||||
@@ -581,8 +597,86 @@ void ui::Canvas::open_project(std::string data_path)
|
||||
fclose(fp);
|
||||
LOG("project restore from %s", name);
|
||||
}
|
||||
ui::Image ui::Canvas::thumbnail_generate(int w, int h)
|
||||
{
|
||||
// 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, w, h);
|
||||
|
||||
RTT fb;
|
||||
fb.create(w, h);
|
||||
fb.bindFramebuffer();
|
||||
fb.clear({ 1, 1, 1, 1 });
|
||||
ui::Plane m_face_plane;
|
||||
m_face_plane.create<1>(2, 2);
|
||||
|
||||
// recalculate because of different aspect ratio than the m_proj matrix
|
||||
glm::mat4 proj = glm::perspective(glm::radians(m_cam_fov), (float)w / (float)h, 0.1f, 1000.f);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
for (int plane_index = 0; plane_index < 6; plane_index++)
|
||||
{
|
||||
auto plane_mvp = proj * m_mv * m_plane_transform[plane_index] * glm::translate(glm::vec3(0, 0, -1));
|
||||
|
||||
ui::ShaderManager::use(kShader::Checkerboard);
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp);
|
||||
m_face_plane.draw_fill();
|
||||
|
||||
ui::ShaderManager::use(kShader::TextureAlpha);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp);
|
||||
for (auto layer_index : m_order)
|
||||
{
|
||||
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_layers[layer_index].m_opacity);
|
||||
m_layers[layer_index].m_rtt[plane_index].bindTexture();
|
||||
m_face_plane.draw_fill();
|
||||
m_layers[layer_index].m_rtt[plane_index].unbindTexture();
|
||||
}
|
||||
}
|
||||
|
||||
fb.unbindFramebuffer();
|
||||
|
||||
// read the rendered image
|
||||
ui::Image image;
|
||||
image.create(w, h);
|
||||
fb.readTextureData((uint8_t*)image.data());
|
||||
|
||||
fb.destroy();
|
||||
|
||||
// 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);
|
||||
|
||||
return std::move(image);
|
||||
}
|
||||
ui::Image ui::Canvas::thumbnail_read(std::string data_path)
|
||||
{
|
||||
static char name[128];
|
||||
sprintf(name, "%s/latlong.pano", data_path.c_str());
|
||||
FILE* fp = fopen(name, "rb");
|
||||
if (!fp)
|
||||
{
|
||||
LOG("cannot read project %s", name);
|
||||
return {}; // return empty image
|
||||
}
|
||||
Image thumb;
|
||||
fread(&thumb.width, sizeof(int), 1, fp);
|
||||
fread(&thumb.height, sizeof(int), 1, fp);
|
||||
fread(&thumb.comp, sizeof(int), 1, fp);
|
||||
thumb.create();
|
||||
fread((uint8_t*)thumb.data(), thumb.size(), 1, fp);
|
||||
fclose(fp);
|
||||
LOG("project thumbnail read from %s", name);
|
||||
return std::move(thumb);
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ui::Layer::destroy()
|
||||
|
||||
Reference in New Issue
Block a user