Merge pull request #7912 from RandomShaper/pause-rasterizer-2.1

Implement time scaling for the rasterizer (2.1)
This commit is contained in:
Rémi Verschelde 2017-08-17 11:43:58 +02:00 committed by GitHub
commit 938dc07b2b
8 changed files with 34 additions and 4 deletions

View File

@ -3951,7 +3951,12 @@ void RasterizerGLES2::begin_frame() {
double time = (OS::get_singleton()->get_ticks_usec() / 1000); // get msec
time /= 1000.0; // make secs
time_delta = time - last_time;
if (frame != 0) {
time_delta = time_scale * (time - last_time);
} else {
time_delta = 0.0f;
}
scaled_time += time_delta;
last_time = time;
frame++;
@ -4966,7 +4971,7 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry, const Material
DEBUG_TEST_ERROR("Material arameters");
if (p_material->shader_cache->uses_time) {
material_shader.set_uniform(MaterialShaderGLES2::TIME, Math::fmod(last_time, shader_time_rollback));
material_shader.set_uniform(MaterialShaderGLES2::TIME, Math::fmod(scaled_time, shader_time_rollback));
draw_next_frame = true;
}
//if uses TIME - draw_next_frame=true
@ -5009,7 +5014,7 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry, const Material
material_shader.set_uniform(MaterialShaderGLES2::FOG_COLOR_END, Vector3(col_end.r, col_end.g, col_end.b));
}
//material_shader.set_uniform(MaterialShaderGLES2::TIME,Math::fmod(last_time,300.0));
//material_shader.set_uniform(MaterialShaderGLES2::TIME,Math::fmod(scaled_time,300.0));
//if uses TIME - draw_next_frame=true
return rebind;
@ -8794,7 +8799,7 @@ void RasterizerGLES2::_canvas_item_setup_shader_uniforms(CanvasItemMaterial *mat
}
if (shader->uses_time) {
canvas_shader.set_uniform(CanvasShaderGLES2::TIME, Math::fmod(last_time, shader_time_rollback));
canvas_shader.set_uniform(CanvasShaderGLES2::TIME, Math::fmod(scaled_time, shader_time_rollback));
draw_next_frame = true;
}
//if uses TIME - draw_next_frame=true
@ -9371,6 +9376,11 @@ bool RasterizerGLES2::is_canvas_light_occluder(const RID &p_rid) const {
return false;
}
void RasterizerGLES2::set_time_scale(float p_scale) {
time_scale = p_scale;
}
void RasterizerGLES2::free(const RID &p_rid) {
if (texture_owner.owns(p_rid)) {
@ -10405,6 +10415,7 @@ void RasterizerGLES2::init() {
#endif
shader_time_rollback = GLOBAL_DEF("rasterizer/shader_time_rollback", 300);
time_scale = 1.0f;
using_canvas_bg = false;
_update_framebuffer();
@ -10737,6 +10748,7 @@ RasterizerGLES2::RasterizerGLES2(bool p_compress_arrays, bool p_keep_ram_copy, b
base_framebuffer = 0;
frame = 0;
scaled_time = 0.0;
draw_next_frame = false;
use_framebuffers = true;
framebuffer.active = false;

View File

@ -1251,6 +1251,7 @@ class RasterizerGLES2 : public Rasterizer {
Size2 window_size;
VS::ViewportRect viewport;
double last_time;
double scaled_time;
double time_delta;
uint64_t frame;
uint64_t scene_pass;
@ -1259,6 +1260,7 @@ class RasterizerGLES2 : public Rasterizer {
VS::ScenarioDebugMode current_debug;
RID overdraw_material;
float shader_time_rollback;
float time_scale;
mutable MaterialShaderGLES2 material_shader;
mutable CanvasShaderGLES2 canvas_shader;
@ -1653,6 +1655,8 @@ public:
virtual bool is_canvas_light_occluder(const RID &p_rid) const;
virtual void set_time_scale(float p_scale);
virtual void free(const RID &p_rid);
virtual void init();

View File

@ -1047,6 +1047,8 @@ public:
virtual bool is_canvas_light_occluder(const RID &p_rid) const = 0;
virtual void set_time_scale(float p_scale) = 0;
virtual void free(const RID &p_rid) = 0;
virtual void init() = 0;

View File

@ -7017,6 +7017,11 @@ Color VisualServerRaster::get_default_clear_color() const {
return clear_color;
}
void VisualServerRaster::set_time_scale(float p_scale) {
rasterizer->set_time_scale(p_scale);
}
void VisualServerRaster::set_boot_image(const Image &p_image, const Color &p_color, bool p_scale) {
if (p_image.empty())

View File

@ -1258,6 +1258,8 @@ public:
virtual void set_default_clear_color(const Color &p_color);
virtual Color get_default_clear_color() const;
virtual void set_time_scale(float p_scale);
VisualServerRaster(Rasterizer *p_rasterizer);
~VisualServerRaster();
};

View File

@ -689,6 +689,7 @@ public:
FUNC3(set_boot_image, const Image &, const Color &, bool);
FUNC1(set_default_clear_color, const Color &);
FUNC0RC(Color, get_default_clear_color);
FUNC1(set_time_scale, float);
FUNC0R(RID, get_test_cube);

View File

@ -537,6 +537,8 @@ void VisualServer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_default_clear_color"), &VisualServer::set_default_clear_color);
ObjectTypeDB::bind_method(_MD("get_default_clear_color"), &VisualServer::get_default_clear_color);
ObjectTypeDB::bind_method(_MD("set_time_scale"), &VisualServer::set_time_scale);
ObjectTypeDB::bind_method(_MD("get_render_info"), &VisualServer::get_render_info);
BIND_CONSTANT(NO_INDEX_ARRAY);

View File

@ -1138,6 +1138,8 @@ public:
virtual void set_default_clear_color(const Color &p_color) = 0;
virtual Color get_default_clear_color() const = 0;
virtual void set_time_scale(float p_scale) = 0;
enum Features {
FEATURE_SHADERS,
FEATURE_MULTITHREADED,