fix usage of i8vec4 instead of u8vec4, fix grid commit bounds

This commit is contained in:
2019-01-20 11:57:09 +01:00
parent c66bc1f1d7
commit 2154396c6b
5 changed files with 44 additions and 21 deletions

View File

@@ -9,6 +9,7 @@ public:
virtual Action* get_redo() = 0;
virtual size_t memory() = 0;
virtual ~Action(){};
Action() = default;
};
class ActionManager

View File

@@ -161,11 +161,15 @@ void Canvas::snap_history(const std::vector<int>& planes)
// save image before commit
glm::vec2 box_or = xy(m_layers[m_current_layer_idx].m_dirty_box[i]);
glm::vec2 box_sz = zw(m_layers[m_current_layer_idx].m_dirty_box[i]) - xy(m_layers[m_current_layer_idx].m_dirty_box[i]);
if (box_sz.x > 0 && box_sz.y > 0)
if (box_sz.x > 0 && box_sz.y > 0 && box_sz.x <= m_layers[m_current_layer_idx].w && box_sz.y <= m_layers[m_current_layer_idx].h)
{
action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4);
glReadPixels(box_or.x, box_or.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());
}
else
{
LOG("snap_history invalid box size (%d, %d)", (int)box_sz.x, (int)box_sz.y);
}
action->m_box[i] = m_layers[m_current_layer_idx].m_dirty_box[i];
action->m_old_box[i] = m_layers[m_current_layer_idx].m_dirty_box[i];
@@ -193,11 +197,15 @@ ActionStroke* Canvas::create_action(int layer)
// save image before commit
glm::vec2 box_or = xy(m_layers[layer].m_dirty_box[i]);
glm::vec2 box_sz = zw(m_layers[layer].m_dirty_box[i]) - xy(m_layers[layer].m_dirty_box[i]);
if (box_sz.x > 0 && box_sz.y > 0)
if (box_sz.x > 0 && box_sz.y > 0 && box_sz.x <= m_layers[m_current_layer_idx].w && box_sz.y <= m_layers[m_current_layer_idx].h)
{
action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4);
glReadPixels(box_or.x, box_or.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());
}
else
{
LOG("create_action invalid box size (%d, %d)", (int)box_sz.x, (int)box_sz.y);
}
action->m_box[i] = m_layers[layer].m_dirty_box[i];
action->m_old_box[i] = m_layers[layer].m_dirty_box[i];
@@ -2290,7 +2298,10 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
// save image before commit
glm::vec2 box_sz = zw(bounds) - xy(bounds);
if (box_sz.x > 0 && box_sz.y > 0)
bool has_data = box_sz.x > 0 && box_sz.y > 0;
if (box_sz.x > layer.w || box_sz.y > layer.h)
__debugbreak();
if (has_data)
{
action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4);
glReadPixels(bounds.x, bounds.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());
@@ -2301,6 +2312,8 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
action->m_old_dirty[i] = layer.m_dirty_face[i];
// draw the tmp layer into the actual layer
if (has_data)
{
ShaderManager::use(kShader::Texture);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-0.5f, 0.5f, -0.5f, 0.5f));
@@ -2310,10 +2323,11 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
m_plane.draw_fill();
rtt.unbindTexture();
layer.m_rtt[i].unbindFramebuffer();
layer.m_dirty_face[i] = true;
layer.m_dirty_box[i] = rect_union(layer.m_dirty_box[i], bounds);
layer.m_dirty_box[i] = { glm::min(xy(layer.m_dirty_box[i]), xy(bounds)), glm::max(zw(layer.m_dirty_box[i]), zw(bounds)) };
}
layer.m_rtt[i].unbindFramebuffer();
}
// save history
@@ -2619,7 +2633,7 @@ void Layer::optimize()
if (!m_dirty_face[i])
continue;
auto data = std::unique_ptr<glm::i8vec4[]>(reinterpret_cast<glm::i8vec4*>(m_rtt[i].readTextureData()));
auto data = std::unique_ptr<glm::u8vec4[]>(reinterpret_cast<glm::u8vec4*>(m_rtt[i].readTextureData()));
glm::ivec2 bbmin(w,h);
glm::ivec2 bbmax(0);
for (int y = 0; y < h; y++)

View File

@@ -54,7 +54,7 @@ public:
{
if (!m_dirty_face[i] || !image[i])
continue;
auto data = reinterpret_cast<glm::i8vec4*>(image[i].get());
auto data = reinterpret_cast<glm::u8vec4*>(image[i].get());
glm::ivec2 bbmin(width, height);
glm::ivec2 bbmax(0);
for (int y = 0; y < height; y++)
@@ -287,6 +287,7 @@ public:
bool clear_layer = false;
int m_layer_idx;
Canvas* m_canvas;
ActionStroke() = default;
virtual void run() override
{
@@ -309,11 +310,18 @@ public:
m_canvas->m_layers[m_layer_idx].m_dirty_box[i] = m_old_box[i];
m_canvas->m_layers[m_layer_idx].m_dirty_face[i] = m_old_dirty[i];
m_canvas->m_layers[m_layer_idx].m_rtt[i].bindTexture();
glm::vec2 box_sz = zw(m_box[i]) - xy(m_box[i]);
if (box_sz.x > 0 && box_sz.y > 0 && box_sz.x <= m_canvas->m_layers[m_layer_idx].w && box_sz.y <= m_canvas->m_layers[m_layer_idx].h)
{
m_canvas->m_layers[m_layer_idx].m_rtt[i].bindTexture();
glTexSubImage2D(GL_TEXTURE_2D, 0, (int)m_box[i].x, (int)m_box[i].y, (int)box_sz.x, (int)box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, m_image[i].get());
m_canvas->m_layers[m_layer_idx].m_rtt[i].unbindTexture();
}
else
{
LOG("undo invalid box size (%d, %d)", (int)box_sz.x, (int)box_sz.y);
}
}
}
virtual size_t memory() override
{

View File

@@ -381,7 +381,7 @@ void NodePanelGrid::bake_uvs()
{
__block float* d_pos = data_pos.get();
__block float* d_nor = data_nor.get();
__block glm::i8vec4* d_out = reinterpret_cast<glm::i8vec4*>(data_out.get());
__block glm::u8vec4* d_out = reinterpret_cast<glm::u8vec4*>(data_out.get());
#if _WIN32
concurrency::parallel_for(int(0), fb.getHeight(), [&](int y)
#elif __IOS__ || __OSX__

View File

@@ -197,7 +197,7 @@ void RTT::clear(glm::vec4 color)
glm::ivec4 RTT::calc_bounds()
{
auto data = std::unique_ptr<glm::i8vec4[]>(reinterpret_cast<glm::i8vec4*>(readTextureData()));
auto data = std::unique_ptr<glm::u8vec4[]>(reinterpret_cast<glm::u8vec4*>(readTextureData()));
glm::ivec2 bbmin(w, h);
glm::ivec2 bbmax(0);
for (int y = 0; y < h; y++)