move the ui/shaders reload into the ui thread, add rtt region copy, add box/rect conversion
This commit is contained in:
30
src/app.cpp
30
src/app.cpp
@@ -577,7 +577,6 @@ void App::draw(float dt)
|
||||
void App::update(float dt)
|
||||
{
|
||||
static std::mutex mutex;
|
||||
static float reload_timer = 0.f;
|
||||
|
||||
// avoid multiple threads to update the scene
|
||||
//std::lock_guard<std::mutex> lock(mutex);
|
||||
@@ -585,17 +584,6 @@ void App::update(float dt)
|
||||
if (!(redraw || animate))
|
||||
return;
|
||||
|
||||
#if /*_DEBUG &&*/ (_WIN32 || __OSX__)
|
||||
reload_timer += dt;
|
||||
if (reload_timer > 1.0)
|
||||
{
|
||||
reload_timer = 0;
|
||||
if (ShaderManager::reload())
|
||||
stroke->update_controls();
|
||||
layout.reload();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (auto* main = layout[main_id])
|
||||
main->update(width, height, zoom);
|
||||
|
||||
@@ -843,6 +831,7 @@ void App::ui_thread_main()
|
||||
auto t_start = std::chrono::high_resolution_clock::now();
|
||||
float t_frame = 0;
|
||||
float t_fps_counter = 0;
|
||||
float t_reloader = 0;
|
||||
int rendered_frames = 0;
|
||||
while (ui_running)
|
||||
{
|
||||
@@ -891,6 +880,23 @@ void App::ui_thread_main()
|
||||
rendered_frames = 0;
|
||||
}
|
||||
|
||||
#if /*_DEBUG &&*/ (_WIN32 || __OSX__)
|
||||
t_reloader += dt;
|
||||
if (t_reloader > 1.0)
|
||||
{
|
||||
t_reloader = 0;
|
||||
if (ShaderManager::reload())
|
||||
{
|
||||
stroke->update_controls();
|
||||
redraw = true;
|
||||
}
|
||||
if (layout.reload())
|
||||
{
|
||||
redraw = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
tick(dt);
|
||||
|
||||
if (redraw)
|
||||
|
||||
22
src/rtt.cpp
22
src/rtt.cpp
@@ -103,7 +103,27 @@ void RTT::copy(const RTT & source)
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboID);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, source.fboID);
|
||||
glBlitFramebuffer(0, 0, source.w, source.h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
glBlitFramebuffer(0, 0, source.w, source.h, 0, 0, w, h,
|
||||
GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDFboID);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, oldRFboID);
|
||||
});
|
||||
}
|
||||
|
||||
void RTT::copy(const RTT& source, const glm::vec4& rect)
|
||||
{
|
||||
App::I->render_task([&]
|
||||
{
|
||||
auto r = rect_intersection(rect, { 0, 0, w, h });
|
||||
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDFboID);
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldRFboID);
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboID);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, source.fboID);
|
||||
glBlitFramebuffer(r.x, r.y, r.z, r.w, r.x, r.y, r.z, r.w,
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDFboID);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, oldRFboID);
|
||||
|
||||
@@ -19,7 +19,10 @@ public:
|
||||
~RTT();
|
||||
|
||||
void destroy();
|
||||
// copy with interpolation
|
||||
void copy(const RTT& source);
|
||||
// copy a region
|
||||
void copy(const RTT& source, const glm::vec4& rect);
|
||||
void resize(int width, int height);
|
||||
bool create(int width, int height, int tex = -1, GLint internal_format = GL_RGBA8, bool depth_buffer = false);
|
||||
bool recreate() { return create(w, h); }
|
||||
|
||||
12
src/util.cpp
12
src/util.cpp
@@ -22,6 +22,18 @@ bool point_in_rect(const glm::vec2& p, const glm::vec4& r)
|
||||
return p.x > r.x && p.x < r.x+r.z && p.y > r.y && p.y < r.y+r.w;
|
||||
}
|
||||
|
||||
// from {origin, size} to {min, max}
|
||||
glm::vec4 rect_to_box(const glm::vec4& r)
|
||||
{
|
||||
return { xy(r), xy(r) + zw(r) };
|
||||
}
|
||||
|
||||
// from {min, max} to {origin, size}
|
||||
glm::vec4 box_to_rect(const glm::vec4& b)
|
||||
{
|
||||
return { xy(b), zw(b) - xy(b) };
|
||||
}
|
||||
|
||||
// params and returns {origin, size} form
|
||||
glm::vec4 rect_intersection(glm::vec4 a, glm::vec4 b)
|
||||
{
|
||||
|
||||
10
src/util.h
10
src/util.h
@@ -45,6 +45,11 @@ std::vector<T> poly_remove_duplicate(const std::vector<T>& v, const float toller
|
||||
template<>
|
||||
std::vector<vertex_t> poly_remove_duplicate<vertex_t>(const std::vector<vertex_t>& v, const float tollerance);
|
||||
|
||||
// from {origin, size} to {min, max}
|
||||
glm::vec4 rect_to_box(const glm::vec4& rect);
|
||||
// from {min, max} to {origin, size}
|
||||
glm::vec4 box_to_rect(const glm::vec4& box);
|
||||
|
||||
// params {x, y} and {origin, size} form
|
||||
bool point_in_rect(const glm::vec2& point, const glm::vec4& rect);
|
||||
// params and returns {origin, size} form
|
||||
@@ -52,12 +57,14 @@ glm::vec4 rect_intersection(glm::vec4 a, glm::vec4 b);
|
||||
// params and returns {origin, size} form
|
||||
glm::vec4 rect_union(glm::vec4 a, glm::vec4 b);
|
||||
// return the are of the box {min, max}
|
||||
|
||||
float box_area(glm::vec4 b);
|
||||
glm::vec2 box_size(glm::vec4 b);
|
||||
// params and returns {min, max} form
|
||||
glm::vec4 box_union(glm::vec4 a, glm::vec4 b);
|
||||
// params and returns {min, max} form
|
||||
glm::vec4 box_intersection(glm::vec4 a, glm::vec4 b);
|
||||
|
||||
bool ray_intersect(glm::vec3 ray_origin, glm::vec3 ray_dir, glm::vec3 plane_origin,
|
||||
glm::vec3 plane_normal, glm::vec3 plane_tangent, glm::vec3& out_hit, float& out_t);
|
||||
float lines_distance(const glm::vec3& p0a, const glm::vec3& p0b,
|
||||
@@ -67,17 +74,20 @@ bool segments_intersect_3d(const glm::vec3& p0a, const glm::vec3& p0b,
|
||||
bool segments_intersect(const glm::vec2& p0a, const glm::vec2& p0b,
|
||||
const glm::vec2& p1a, const glm::vec2& p1b, glm::vec2& out_pt, glm::vec2& out_hit_uv);
|
||||
bool point_side(glm::vec2 a, glm::vec2 b, glm::vec2 p);
|
||||
|
||||
std::vector<vertex_t> poly_intersect(const vertex_t* poly_begin, const vertex_t* poly_end, const std::vector<glm::vec2>& clip);
|
||||
std::vector<glm::vec2> poly_intersect(const std::vector<glm::vec2>& poly, const std::vector<glm::vec2>& clip);
|
||||
std::vector<glm::vec3> poly_clip_near(const std::vector<glm::vec3>& poly, float near_plane_distance);
|
||||
std::vector<vertex_t> triangulate(const std::vector<vertex_t>& points);
|
||||
std::vector<vertex_t> triangulate(const std::vector<glm::vec2>& points);
|
||||
std::vector<vertex_t> triangulate_simple(const std::vector<vertex_t>& vertices);
|
||||
|
||||
glm::vec4 rand_color();
|
||||
glm::vec3 convert_long_rgb(uint32_t hex);
|
||||
uint32_t convert_rgb_long(glm::vec3 rgb);
|
||||
glm::vec3 convert_hsv2rgb(const glm::vec3 c);
|
||||
glm::vec3 convert_rgb2hsv(const glm::vec3 c);
|
||||
|
||||
std::vector<std::string> split(const std::string& subject, char d, int max_split = 0);
|
||||
std::string unescape(const std::string& s);
|
||||
std::wstring str2wstr(const std::string& str);
|
||||
|
||||
Reference in New Issue
Block a user