implement load/unload frames

This commit is contained in:
2019-10-22 19:37:55 +02:00
parent 63f8d2f81c
commit 8e4f77333e
11 changed files with 211 additions and 116 deletions

View File

@@ -5,9 +5,23 @@
struct LayerFrame
{
struct Snapshot
{
std::unique_ptr<uint8_t[]> image[6] = SIXPLETTE(0);
std::array<glm::vec4, 6> m_dirty_box = SIXPLETTE(glm::vec4(0));
std::array<bool, 6> m_dirty_face = SIXPLETTE(false);
int width = 0;
int height = 0;
void create(int w, int h);
void clear();
void optimize();
int memsize() const;
};
std::array<RTT, 6> m_rtt;
std::array<glm::vec4, 6> m_dirty_box = SIXPLETTE(glm::vec4(0));
std::array<bool, 6> m_dirty_face = SIXPLETTE(false);
std::unique_ptr<Snapshot> m_gpu_data;
int m_duration = 1;
int w = 0, h = 0;
@@ -23,17 +37,23 @@ struct LayerFrame
bool create(int width, int height, int duration = 1);
bool resize(int width, int height);
void clear(const glm::vec4& c);
LayerFrame clone() const noexcept;
LayerFrame clone() noexcept;
// return previous state
bool gpu_load() noexcept;
// return if succesfully loaded on gpu
bool gpu_unload() noexcept;
Snapshot snapshot(std::array<glm::vec4, 6>* dirty_box = nullptr, std::array<bool, 6>* dirty_face = nullptr);
void restore(const Snapshot& snap);
};
class Layer
{
static uint32_t s_count;
std::vector<LayerFrame> m_frames;
public:
Layer() { id = s_count++; }
Layer(const Layer&) = delete;
uint32_t id;
std::vector<LayerFrame> m_frames;
int m_frame_index = 0;
bool m_visible = true;
bool m_alpha_locked = false;
@@ -43,18 +63,6 @@ public:
std::string m_name;
int w = 0;
int h = 0;
struct Snapshot
{
std::unique_ptr<uint8_t[]> image[6] = SIXPLETTE(0);
std::array<glm::vec4, 6> m_dirty_box = SIXPLETTE(glm::vec4(0));
std::array<bool, 6> m_dirty_face = SIXPLETTE(false);
int width = 0;
int height = 0;
void create(int w, int h);
void clear();
void optimize();
int memsize() const;
};
RTT& rtt(int i, int frame = -1);
glm::vec4& box(int i, int frame = -1);
bool& face(int i, int frame = -1);
@@ -64,13 +72,17 @@ public:
bool add_frame();
void remove_frame(int frame);
void duplicate_frame(int frame);
void frames_gpu_update();
int frames_count() const noexcept { return m_frames.size(); }
int frame_duration(int frame) const noexcept { return m_frames[frame].m_duration; }
void set_frame_duration(int frame, int duration) noexcept { m_frames[frame].m_duration = duration; }
int total_duration() const noexcept;
void goto_frame(int frame) noexcept;
void clear(const glm::vec4& c, int frame = -1);
Snapshot snapshot(int frame = -1, std::array<glm::vec4, 6>* dirty_box = nullptr, std::array<bool, 6>* dirty_face = nullptr);
LayerFrame::Snapshot snapshot(int frame = -1, std::array<glm::vec4, 6>* dirty_box = nullptr, std::array<bool, 6>* dirty_face = nullptr);
TextureCube gen_cube();
Texture2D gen_equirect();
void restore(const Snapshot& snap, int frame = -1);
void restore(const LayerFrame::Snapshot& snap, int frame = -1);
void destroy();
void optimize(int frame = -1);
};