Merge pull request #18368 from Gamblify/RasterizerEngineSync

sync rasterizers with engine
This commit is contained in:
Rémi Verschelde 2018-07-25 20:33:37 +02:00 committed by GitHub
commit 237148e80f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 33 additions and 58 deletions

View file

@ -777,7 +777,7 @@ public:
void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) {}
void initialize() {}
void begin_frame() {}
void begin_frame(double frame_step) {}
void set_current_render_target(RID p_render_target) {}
void restore_render_target() {}
void clear_render_target(const Color &p_color) {}

View file

@ -227,21 +227,14 @@ void RasterizerGLES2::initialize() {
scene->initialize();
}
void RasterizerGLES2::begin_frame() {
uint64_t tick = OS::get_singleton()->get_ticks_usec();
void RasterizerGLES2::begin_frame(double frame_step) {
time_total += frame_step;
double delta = double(tick - prev_ticks) / 1000000.0;
delta *= Engine::get_singleton()->get_time_scale();
time_total += delta;
if (delta == 0) {
if (frame_step == 0) {
//to avoid hiccups
delta = 0.001;
frame_step = 0.001;
}
prev_ticks = tick;
// double time_roll_over = GLOBAL_GET("rendering/limits/time/time_rollover_secs");
// if (time_total > time_roll_over)
// time_total = 0; //roll over every day (should be customz
@ -251,9 +244,7 @@ void RasterizerGLES2::begin_frame() {
storage->frame.time[2] = Math::fmod(time_total, 900);
storage->frame.time[3] = Math::fmod(time_total, 60);
storage->frame.count++;
storage->frame.delta = delta;
storage->frame.prev_tick = tick;
storage->frame.delta = frame_step;
storage->update_dirty_resources();
@ -452,7 +443,6 @@ RasterizerGLES2::RasterizerGLES2() {
scene->storage = storage;
storage->scene = scene;
prev_ticks = 0;
time_total = 0;
}

View file

@ -43,7 +43,6 @@ class RasterizerGLES2 : public Rasterizer {
RasterizerCanvasGLES2 *canvas;
RasterizerSceneGLES2 *scene;
uint64_t prev_ticks;
double time_total;
public:
@ -54,7 +53,7 @@ public:
virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale);
virtual void initialize();
virtual void begin_frame();
virtual void begin_frame(double frame_step);
virtual void set_current_render_target(RID p_render_target);
virtual void restore_render_target();
virtual void clear_render_target(const Color &p_color);

View file

@ -2008,7 +2008,6 @@ void RasterizerStorageGLES2::initialize() {
config.shrink_textures_x2 = false;
frame.count = 0;
frame.prev_tick = 0;
frame.delta = 0;
frame.current_rt = NULL;
frame.clear_request = false;

View file

@ -824,7 +824,6 @@ public:
int canvas_draw_commands;
float time[4];
float delta;
uint64_t prev_tick;
uint64_t count;
} frame;

View file

@ -192,22 +192,15 @@ void RasterizerGLES3::initialize() {
scene->initialize();
}
void RasterizerGLES3::begin_frame() {
void RasterizerGLES3::begin_frame(double frame_step) {
uint64_t tick = OS::get_singleton()->get_ticks_usec();
time_total += frame_step;
double delta = double(tick - prev_ticks) / 1000000.0;
delta *= Engine::get_singleton()->get_time_scale();
time_total += delta;
if (delta == 0) {
if (frame_step == 0) {
//to avoid hiccups
delta = 0.001;
frame_step = 0.001;
}
prev_ticks = tick;
double time_roll_over = GLOBAL_GET("rendering/limits/time/time_rollover_secs");
if (time_total > time_roll_over)
time_total = 0; //roll over every day (should be customz
@ -217,9 +210,7 @@ void RasterizerGLES3::begin_frame() {
storage->frame.time[2] = Math::fmod(time_total, 900);
storage->frame.time[3] = Math::fmod(time_total, 60);
storage->frame.count++;
storage->frame.delta = delta;
storage->frame.prev_tick = tick;
storage->frame.delta = frame_step;
storage->update_dirty_resources();
@ -281,7 +272,7 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c
if (p_image.is_null() || p_image->empty())
return;
begin_frame();
begin_frame(0.0);
int window_w = OS::get_singleton()->get_video_mode(0).width;
int window_h = OS::get_singleton()->get_video_mode(0).height;
@ -451,7 +442,6 @@ RasterizerGLES3::RasterizerGLES3() {
scene->storage = storage;
storage->scene = scene;
prev_ticks = 0;
time_total = 0;
}

View file

@ -44,7 +44,6 @@ class RasterizerGLES3 : public Rasterizer {
RasterizerCanvasGLES3 *canvas;
RasterizerSceneGLES3 *scene;
uint64_t prev_ticks;
double time_total;
public:
@ -55,7 +54,7 @@ public:
virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale);
virtual void initialize();
virtual void begin_frame();
virtual void begin_frame(double frame_step);
virtual void set_current_render_target(RID p_render_target);
virtual void restore_render_target();
virtual void clear_render_target(const Color &p_color);

View file

@ -7489,7 +7489,6 @@ void RasterizerStorageGLES3::initialize() {
#endif
frame.count = 0;
frame.prev_tick = 0;
frame.delta = 0;
frame.current_rt = NULL;
config.keep_original_textures = false;

View file

@ -1427,7 +1427,6 @@ public:
int canvas_draw_commands;
float time[4];
float delta;
uint64_t prev_tick;
uint64_t count;
} frame;

View file

@ -1734,8 +1734,11 @@ bool Main::iteration() {
int physics_fps = Engine::get_singleton()->get_iterations_per_second();
float frame_slice = 1.0 / physics_fps;
float time_scale = Engine::get_singleton()->get_time_scale();
MainFrameTime advance = main_timer_sync.advance(frame_slice, physics_fps);
double step = advance.idle_step;
double scaled_step = step * time_scale;
Engine::get_singleton()->_frame_step = step;
@ -1757,8 +1760,6 @@ bool Main::iteration() {
advance.physics_steps = max_physics_steps;
}
float time_scale = Engine::get_singleton()->get_time_scale();
bool exit = false;
Engine::get_singleton()->_in_physics = true;
@ -1805,11 +1806,11 @@ bool Main::iteration() {
if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) {
if (VisualServer::get_singleton()->has_changed()) {
VisualServer::get_singleton()->draw(); // flush visual commands
VisualServer::get_singleton()->draw(true, scaled_step); // flush visual commands
Engine::get_singleton()->frames_drawn++;
}
} else {
VisualServer::get_singleton()->draw(); // flush visual commands
VisualServer::get_singleton()->draw(true, scaled_step); // flush visual commands
Engine::get_singleton()->frames_drawn++;
force_redraw_requested = false;
}

View file

@ -1078,7 +1078,7 @@ public:
virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) = 0;
virtual void initialize() = 0;
virtual void begin_frame() = 0;
virtual void begin_frame(double frame_step) = 0;
virtual void set_current_render_target(RID p_render_target) = 0;
virtual void restore_render_target() = 0;
virtual void clear_render_target(const Color &p_color) = 0;

View file

@ -93,14 +93,14 @@ void VisualServerRaster::request_frame_drawn_callback(Object *p_where, const Str
frame_drawn_callbacks.push_back(fdc);
}
void VisualServerRaster::draw(bool p_swap_buffers) {
void VisualServerRaster::draw(bool p_swap_buffers, double frame_step) {
//needs to be done before changes is reset to 0, to not force the editor to redraw
VS::get_singleton()->emit_signal("frame_pre_draw");
changes = 0;
VSG::rasterizer->begin_frame();
VSG::rasterizer->begin_frame(frame_step);
VSG::scene->update_dirty_instances(); //update scene stuff

View file

@ -660,7 +660,7 @@ public:
virtual void request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata);
virtual void draw(bool p_swap_buffers);
virtual void draw(bool p_swap_buffers, double frame_step);
virtual void sync();
virtual bool has_changed() const;
virtual void init();

View file

@ -37,11 +37,11 @@ void VisualServerWrapMT::thread_exit() {
exit = true;
}
void VisualServerWrapMT::thread_draw() {
void VisualServerWrapMT::thread_draw(bool p_swap_buffers, double frame_step) {
if (!atomic_decrement(&draw_pending)) {
visual_server->draw();
visual_server->draw(p_swap_buffers, frame_step);
}
}
@ -91,15 +91,15 @@ void VisualServerWrapMT::sync() {
}
}
void VisualServerWrapMT::draw(bool p_swap_buffers) {
void VisualServerWrapMT::draw(bool p_swap_buffers, double frame_step) {
if (create_thread) {
atomic_increment(&draw_pending);
command_queue.push(this, &VisualServerWrapMT::thread_draw);
command_queue.push(this, &VisualServerWrapMT::thread_draw, p_swap_buffers, frame_step);
} else {
visual_server->draw(p_swap_buffers);
visual_server->draw(p_swap_buffers, frame_step);
}
}

View file

@ -55,7 +55,7 @@ class VisualServerWrapMT : public VisualServer {
bool create_thread;
uint64_t draw_pending;
void thread_draw();
void thread_draw(bool p_swap_buffers, double frame_step);
void thread_flush();
void thread_exit();
@ -578,7 +578,7 @@ public:
virtual void init();
virtual void finish();
virtual void draw(bool p_swap_buffers);
virtual void draw(bool p_swap_buffers, double frame_step);
virtual void sync();
FUNC0RC(bool, has_changed)

View file

@ -1648,13 +1648,13 @@ Array VisualServer::_mesh_surface_get_skeleton_aabb_bind(RID p_mesh, int p_surfa
void VisualServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("force_sync"), &VisualServer::sync);
ClassDB::bind_method(D_METHOD("force_draw", "swap_buffers"), &VisualServer::draw, DEFVAL(true));
ClassDB::bind_method(D_METHOD("force_draw", "swap_buffers", "frame_step"), &VisualServer::draw, DEFVAL(true), DEFVAL(0.0));
// "draw" and "sync" are deprecated duplicates of "force_draw" and "force_sync"
// FIXME: Add deprecation messages using GH-4397 once available, and retire
// once the warnings have been enabled for a full release cycle
ClassDB::bind_method(D_METHOD("sync"), &VisualServer::sync);
ClassDB::bind_method(D_METHOD("draw", "swap_buffers"), &VisualServer::draw, DEFVAL(true));
ClassDB::bind_method(D_METHOD("draw", "swap_buffers", "frame_step"), &VisualServer::draw, DEFVAL(true), DEFVAL(0.0));
ClassDB::bind_method(D_METHOD("texture_create"), &VisualServer::texture_create);
ClassDB::bind_method(D_METHOD("texture_create_from_image", "image", "flags"), &VisualServer::texture_create_from_image, DEFVAL(TEXTURE_FLAGS_DEFAULT));

View file

@ -955,7 +955,7 @@ public:
/* EVENT QUEUING */
virtual void draw(bool p_swap_buffers = true) = 0;
virtual void draw(bool p_swap_buffers = true, double frame_step = 0.0) = 0;
virtual void sync() = 0;
virtual bool has_changed() const = 0;
virtual void init() = 0;