fix usage of i8vec4 instead of u8vec4, fix grid commit bounds
This commit is contained in:
@@ -9,6 +9,7 @@ public:
|
|||||||
virtual Action* get_redo() = 0;
|
virtual Action* get_redo() = 0;
|
||||||
virtual size_t memory() = 0;
|
virtual size_t memory() = 0;
|
||||||
virtual ~Action(){};
|
virtual ~Action(){};
|
||||||
|
Action() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ActionManager
|
class ActionManager
|
||||||
|
|||||||
@@ -161,11 +161,15 @@ void Canvas::snap_history(const std::vector<int>& planes)
|
|||||||
// save image before commit
|
// save image before commit
|
||||||
glm::vec2 box_or = xy(m_layers[m_current_layer_idx].m_dirty_box[i]);
|
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]);
|
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);
|
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());
|
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_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];
|
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
|
// save image before commit
|
||||||
glm::vec2 box_or = xy(m_layers[layer].m_dirty_box[i]);
|
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]);
|
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);
|
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());
|
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_box[i] = m_layers[layer].m_dirty_box[i];
|
||||||
action->m_old_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
|
// save image before commit
|
||||||
glm::vec2 box_sz = zw(bounds) - xy(bounds);
|
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);
|
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());
|
glReadPixels(bounds.x, bounds.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());
|
||||||
@@ -2301,19 +2312,22 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
|
|||||||
action->m_old_dirty[i] = layer.m_dirty_face[i];
|
action->m_old_dirty[i] = layer.m_dirty_face[i];
|
||||||
|
|
||||||
// draw the tmp layer into the actual layer
|
// draw the tmp layer into the actual layer
|
||||||
ShaderManager::use(kShader::Texture);
|
if (has_data)
|
||||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
{
|
||||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-0.5f, 0.5f, -0.5f, 0.5f));
|
ShaderManager::use(kShader::Texture);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||||
m_sampler_nearest.bind(0);
|
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-0.5f, 0.5f, -0.5f, 0.5f));
|
||||||
rtt.bindTexture();
|
glActiveTexture(GL_TEXTURE0);
|
||||||
m_plane.draw_fill();
|
m_sampler_nearest.bind(0);
|
||||||
rtt.unbindTexture();
|
rtt.bindTexture();
|
||||||
|
m_plane.draw_fill();
|
||||||
|
rtt.unbindTexture();
|
||||||
|
|
||||||
|
layer.m_dirty_face[i] = true;
|
||||||
|
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();
|
layer.m_rtt[i].unbindFramebuffer();
|
||||||
|
|
||||||
layer.m_dirty_face[i] = true;
|
|
||||||
layer.m_dirty_box[i] = rect_union(layer.m_dirty_box[i], bounds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// save history
|
// save history
|
||||||
@@ -2619,7 +2633,7 @@ void Layer::optimize()
|
|||||||
if (!m_dirty_face[i])
|
if (!m_dirty_face[i])
|
||||||
continue;
|
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 bbmin(w,h);
|
||||||
glm::ivec2 bbmax(0);
|
glm::ivec2 bbmax(0);
|
||||||
for (int y = 0; y < h; y++)
|
for (int y = 0; y < h; y++)
|
||||||
|
|||||||
16
src/canvas.h
16
src/canvas.h
@@ -54,7 +54,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (!m_dirty_face[i] || !image[i])
|
if (!m_dirty_face[i] || !image[i])
|
||||||
continue;
|
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 bbmin(width, height);
|
||||||
glm::ivec2 bbmax(0);
|
glm::ivec2 bbmax(0);
|
||||||
for (int y = 0; y < height; y++)
|
for (int y = 0; y < height; y++)
|
||||||
@@ -287,6 +287,7 @@ public:
|
|||||||
bool clear_layer = false;
|
bool clear_layer = false;
|
||||||
int m_layer_idx;
|
int m_layer_idx;
|
||||||
Canvas* m_canvas;
|
Canvas* m_canvas;
|
||||||
|
ActionStroke() = default;
|
||||||
virtual void run() override
|
virtual void run() override
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -309,10 +310,17 @@ 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_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_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]);
|
glm::vec2 box_sz = zw(m_box[i]) - xy(m_box[i]);
|
||||||
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());
|
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].unbindTexture();
|
{
|
||||||
|
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
|
virtual size_t memory() override
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ void NodePanelGrid::bake_uvs()
|
|||||||
{
|
{
|
||||||
__block float* d_pos = data_pos.get();
|
__block float* d_pos = data_pos.get();
|
||||||
__block float* d_nor = data_nor.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
|
#if _WIN32
|
||||||
concurrency::parallel_for(int(0), fb.getHeight(), [&](int y)
|
concurrency::parallel_for(int(0), fb.getHeight(), [&](int y)
|
||||||
#elif __IOS__ || __OSX__
|
#elif __IOS__ || __OSX__
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ void RTT::clear(glm::vec4 color)
|
|||||||
|
|
||||||
glm::ivec4 RTT::calc_bounds()
|
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 bbmin(w, h);
|
||||||
glm::ivec2 bbmax(0);
|
glm::ivec2 bbmax(0);
|
||||||
for (int y = 0; y < h; y++)
|
for (int y = 0; y < h; y++)
|
||||||
|
|||||||
Reference in New Issue
Block a user