This commit is contained in:
2018-03-08 22:36:22 +01:00
21 changed files with 236 additions and 141 deletions

View File

@@ -580,7 +580,8 @@ void ui::Canvas::stroke_start(glm::vec2 point, float pressure, const ui::Brush&
}
m_current_stroke = std::make_unique<Stroke>();
m_current_stroke->m_camera = { m_cam_rot, m_cam_fov };
m_current_stroke->m_camera.rot = m_cam_rot;
m_current_stroke->m_camera.fov = m_cam_fov;
m_current_stroke->start(brush);
m_current_stroke->add_point(point, pressure);
@@ -808,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);
@@ -1530,7 +1562,7 @@ ui::Image ui::Canvas::thumbnail_read(std::string data_path)
return std::move(thumb);
}
void ui::Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj)> observer, Layer& layer)
void ui::Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj, int i)> observer, Layer& layer)
{
// save viewport and clear color states
GLint vp[4];
@@ -1549,7 +1581,7 @@ void ui::Canvas::draw_objects(std::function<void(const glm::mat4& camera, const
glm::mat4 plane_camera = glm::lookAt(glm::vec3(0), m_plane_origin[i], m_plane_tangent[i]);
layer.m_rtt[i].bindFramebuffer();
observer(plane_camera, proj);
observer(plane_camera, proj, i);
layer.m_rtt[i].unbindFramebuffer();
}
@@ -1561,7 +1593,7 @@ void ui::Canvas::draw_objects(std::function<void(const glm::mat4& camera, const
glActiveTexture(GL_TEXTURE0);
}
void ui::Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj)> observer)
void ui::Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj, int i)> observer)
{
draw_objects(observer, m_layers[m_current_layer_idx]);
}