prepare to draw on multiple planes
This commit is contained in:
@@ -8,6 +8,44 @@
|
||||
|
||||
NS_START
|
||||
|
||||
class Layer
|
||||
{
|
||||
public:
|
||||
RTT m_rtt[6];
|
||||
bool m_visible = true;
|
||||
bool m_locked = false;
|
||||
float m_opacity = 1.f;
|
||||
std::string m_name;
|
||||
bool create(int width, int height, std::string name)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_rtt[i].create(width, height);
|
||||
m_rtt[i].bindFramebuffer();
|
||||
m_rtt[i].clear();
|
||||
m_rtt[i].unbindFramebuffer();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void clear(const glm::vec4& c)
|
||||
{
|
||||
// push clear color state
|
||||
GLfloat cc[4];
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
|
||||
glClearColor(c.r, c.g, c.b, c.a);
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_rtt[i].bindFramebuffer();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_rtt[i].unbindFramebuffer();
|
||||
}
|
||||
|
||||
// restore clear color state
|
||||
glClearColor(cc[0], cc[1], cc[2], cc[3]);
|
||||
}
|
||||
};
|
||||
|
||||
class Canvas
|
||||
{
|
||||
Plane m_plane;
|
||||
@@ -27,9 +65,12 @@ public:
|
||||
bool m_show_tmp = false;
|
||||
std::vector<Layer> m_layers;
|
||||
std::vector<int> m_order;
|
||||
RTT m_tmp;
|
||||
Texture2D m_tex;
|
||||
Texture2D m_tex2;
|
||||
glm::vec4 m_dirty_box[6];
|
||||
RTT m_tmp[6];
|
||||
Texture2D m_tex[6];
|
||||
Texture2D m_tex2[6];
|
||||
glm::vec3 m_plane_origin[6];
|
||||
glm::vec3 m_plane_normal[6];
|
||||
Sampler m_sampler;
|
||||
Sampler m_sampler_bg;
|
||||
glm::vec2 m_cam_rot;
|
||||
@@ -52,8 +93,9 @@ class ActionStroke : public Action
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<Stroke> m_stroke;
|
||||
std::unique_ptr<uint8_t[]> m_image;
|
||||
glm::ivec4 m_box;
|
||||
std::unique_ptr<uint8_t[]> m_image[6];
|
||||
glm::ivec4 m_box[6];
|
||||
bool m_dirty[6];
|
||||
int m_layer_idx;
|
||||
Canvas* m_canvas;
|
||||
virtual void run() override
|
||||
@@ -62,12 +104,17 @@ public:
|
||||
}
|
||||
virtual void undo() override
|
||||
{
|
||||
m_canvas->m_layers[m_layer_idx].m_rtt.bindTexture();
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
// empty data
|
||||
if (!m_image[i])
|
||||
continue;
|
||||
|
||||
glm::vec2 box_sz = m_box.zw() - m_box.xy();
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, m_box.x, m_box.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, m_image.get());
|
||||
|
||||
m_canvas->m_layers[m_layer_idx].m_rtt.unbindTexture();
|
||||
m_canvas->m_layers[m_layer_idx].m_rtt[i].bindTexture();
|
||||
glm::vec2 box_sz = m_box[i].zw() - m_box[i].xy();
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, m_box[i].x, m_box[i].y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, m_image[i].get());
|
||||
m_canvas->m_layers[m_layer_idx].m_rtt[i].unbindTexture();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user