diff --git a/.gitignore b/.gitignore index 79a9a7c..222af98 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ android/android.iml android/local.properties data/brushes data/thumbs +PanoPainter.aps +panopainter-log.txt diff --git a/engine/canvas.cpp b/engine/canvas.cpp index 3499ece..1a77382 100644 --- a/engine/canvas.cpp +++ b/engine/canvas.cpp @@ -809,27 +809,58 @@ void ui::Canvas::import_equirectangular(std::string file_path) void ui::Canvas::import_equirectangular_thread(std::string file_path) { - Texture2D tex; - gl_state gl; App::I.async_start(); + + gl_state gl; gl.save(); snap_history({0,1,2,3,4,5}); - tex.load_file(file_path); - ui::Sphere sphere; - glDisable(GL_DEPTH_TEST); - sphere.create<64, 64>(2.f); - draw_objects([&](const glm::mat4& camera, const glm::mat4& proj){ - m_sampler.bind(0); - glActiveTexture(GL_TEXTURE0); - tex.bind(); - ShaderManager::use(ui::kShader::Texture); - ShaderManager::u_int(kShaderUniform::Tex, 0); - ShaderManager::u_mat4(kShaderUniform::MVP, proj * camera * - glm::eulerAngleY(glm::radians(-90.f)) * glm::scale(glm::vec3(1,-1,1))); - sphere.draw_fill(); - tex.unbind(); - m_sampler.unbind(); - }); + + Image img; + img.load_file(file_path); + + if (img.width == img.height / 6) + { + Texture2D tex; + static GLint indices[] = { 5, 1, 4, 0, 2, 3 }; + static GLint formats[] = { GL_RED, GL_RG, GL_RGB, GL_RGBA }; + static GLint iformats[] = { GL_R8, GL_RG8, GL_RGB8, GL_RGBA8 }; + tex.create(img.width, img.width, iformats[img.comp - 1], formats[img.comp - 1]); + int stride = img.width * img.width * img.comp; + ui::Plane plane; + plane.create<1>(2, 2); + draw_objects([&](const glm::mat4& camera, const glm::mat4& proj, int i) { + tex.update(img.m_data.get() + indices[i] * stride); + m_sampler.bind(0); + glActiveTexture(GL_TEXTURE0); + tex.bind(); + ShaderManager::use(ui::kShader::Texture); + ShaderManager::u_int(kShaderUniform::Tex, 0); + ShaderManager::u_mat4(kShaderUniform::MVP, glm::scale(glm::vec3(1, -1, 1))); + plane.draw_fill(); + tex.unbind(); + m_sampler.unbind(); + }); + } + else + { + Texture2D tex; + tex.load_file(file_path); + ui::Sphere sphere; + glDisable(GL_DEPTH_TEST); + sphere.create<64, 64>(2.f); + draw_objects([&](const glm::mat4& camera, const glm::mat4& proj, int i) { + m_sampler.bind(0); + glActiveTexture(GL_TEXTURE0); + tex.bind(); + ShaderManager::use(ui::kShader::Texture); + ShaderManager::u_int(kShaderUniform::Tex, 0); + ShaderManager::u_mat4(kShaderUniform::MVP, proj * camera * + glm::eulerAngleY(glm::radians(-90.f)) * glm::scale(glm::vec3(1, -1, 1))); + sphere.draw_fill(); + tex.unbind(); + m_sampler.unbind(); + }); + } for (int i = 0; i < 6; i++) { m_layers[m_current_layer_idx].m_dirty_box[i] = glm::vec4(0, 0, m_width, m_height); @@ -1531,7 +1562,7 @@ ui::Image ui::Canvas::thumbnail_read(std::string data_path) return std::move(thumb); } -void ui::Canvas::draw_objects(std::function observer, Layer& layer) +void ui::Canvas::draw_objects(std::function observer, Layer& layer) { // save viewport and clear color states GLint vp[4]; @@ -1550,7 +1581,7 @@ void ui::Canvas::draw_objects(std::function observer) +void ui::Canvas::draw_objects(std::function observer) { draw_objects(observer, m_layers[m_current_layer_idx]); } diff --git a/engine/canvas.h b/engine/canvas.h index 0156143..d4f5218 100644 --- a/engine/canvas.h +++ b/engine/canvas.h @@ -145,8 +145,8 @@ public: ui::Image thumbnail_generate(int w, int h); ui::Image thumbnail_read(std::string data_path); void preview_generate(); - void draw_objects(std::function); - void draw_objects(std::function, Layer& layer); + void draw_objects(std::function); + void draw_objects(std::function, Layer& layer); bool ray_intersect(glm::vec3 ray_origin, glm::vec3 ray_dir, glm::vec3 plane_origin, glm::vec3 plane_normal, glm::vec3 plane_tangent, glm::vec3 &out_hit); void point_unproject(glm::vec2 loc, glm::vec4 vp, glm::mat4 camera, glm::mat4 proj, diff --git a/libs/glm b/libs/glm index 9f1aae0..1190ae0 160000 --- a/libs/glm +++ b/libs/glm @@ -1 +1 @@ -Subproject commit 9f1aae08f71d1a1939d3bb8dcb771722d836cf9f +Subproject commit 1190ae0b0e6ab38dc4a650ce7ad79be66a7a4de1 diff --git a/libs/stb/stb b/libs/stb/stb index 3e7f2d6..9d9f75e 160000 --- a/libs/stb/stb +++ b/libs/stb/stb @@ -1 +1 @@ -Subproject commit 3e7f2d6ebddfe54bd9a9491db1349513a357bfe5 +Subproject commit 9d9f75eb682dd98b34de08bb5c489c6c561c9fa6 diff --git a/libs/tinyxml2 b/libs/tinyxml2 index 5b733ff..e1b5043 160000 --- a/libs/tinyxml2 +++ b/libs/tinyxml2 @@ -1 +1 @@ -Subproject commit 5b733ff4810049d24085c87d989c1d06dcdf8f82 +Subproject commit e1b50439c94181d3c271cbc5a9b3445640f8f4e9