Move canvas action pixel mapping to renderer gl
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "canvas.h"
|
||||
#include "canvas_actions.h"
|
||||
#include "node_panel_layer.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
void ActionStroke::undo()
|
||||
{
|
||||
@@ -36,8 +37,21 @@ void ActionStroke::undo()
|
||||
{
|
||||
App::I->render_task([&]
|
||||
{
|
||||
const auto texture_target = pp::renderer::gl::texture_2d_target();
|
||||
const auto pixel_format = pp::renderer::gl::rgba_pixel_format();
|
||||
const auto component_type = pp::renderer::gl::unsigned_byte_component_type();
|
||||
|
||||
m_canvas->m_layers[m_layer_idx]->rtt(i, m_frame_idx).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());
|
||||
glTexSubImage2D(
|
||||
texture_target,
|
||||
0,
|
||||
(int)m_box[i].x,
|
||||
(int)m_box[i].y,
|
||||
(int)box_sz.x,
|
||||
(int)box_sz.y,
|
||||
pixel_format,
|
||||
component_type,
|
||||
m_image[i].get());
|
||||
m_canvas->m_layers[m_layer_idx]->rtt(i, m_frame_idx).unbindTexture();
|
||||
});
|
||||
}
|
||||
@@ -76,11 +90,22 @@ Action* ActionStroke::get_redo()
|
||||
glm::vec2 box_sz = zw(box) - xy(box);
|
||||
if (box_sz.x > 0 && box_sz.y > 0 && box_sz.x <= layer->w && box_sz.y <= layer->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[]>(
|
||||
static_cast<size_t>((int)box_sz.x) * static_cast<size_t>((int)box_sz.y) * 4U);
|
||||
App::I->render_task([&]
|
||||
{
|
||||
const auto pixel_format = pp::renderer::gl::rgba_pixel_format();
|
||||
const auto component_type = pp::renderer::gl::unsigned_byte_component_type();
|
||||
|
||||
layer->rtt(i, m_frame_idx).bindFramebuffer();
|
||||
glReadPixels(box_or.x, box_or.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());
|
||||
glReadPixels(
|
||||
(int)box_or.x,
|
||||
(int)box_or.y,
|
||||
(int)box_sz.x,
|
||||
(int)box_sz.y,
|
||||
pixel_format,
|
||||
component_type,
|
||||
action->m_image[i].get());
|
||||
layer->rtt(i, m_frame_idx).unbindFramebuffer();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user