diff options
-rw-r--r-- | core/os/os.cpp | 1 | ||||
-rw-r--r-- | core/os/os.h | 3 | ||||
-rw-r--r-- | drivers/gles2/rasterizer_gles2.cpp | 4 | ||||
-rw-r--r-- | main/main.cpp | 1 | ||||
-rw-r--r-- | scene/2d/animated_sprite.cpp | 5 | ||||
-rw-r--r-- | scene/2d/sprite.cpp | 7 |
6 files changed, 18 insertions, 3 deletions
diff --git a/core/os/os.cpp b/core/os/os.cpp index 2db926e556..ee9f12b79d 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -516,6 +516,7 @@ OS::OS() { _target_fps=0; _render_thread_mode=RENDER_THREAD_SAFE; _time_scale=1.0; + _pixel_snap=false; Math::seed(1234567); } diff --git a/core/os/os.h b/core/os/os.h index d89734d7d3..e5338b4a02 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -58,6 +58,7 @@ class OS { float _fps; int _target_fps; float _time_scale; + bool _pixel_snap; char *last_error; @@ -393,7 +394,7 @@ public: void set_time_scale(float p_scale); float get_time_scale() const; - + _FORCE_INLINE_ bool get_use_pixel_snap() const { return _pixel_snap; } OS(); virtual ~OS(); diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index a3c742577a..3d75ed29f3 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -4145,7 +4145,7 @@ void RasterizerGLES2::begin_frame() { //fragment_lighting=Globals::get_singleton()->get("rasterizer/use_fragment_lighting"); #ifdef TOOLS_ENABLED - canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP,GLOBAL_DEF("rasterizer/use_pixel_snap",false)); + canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP,GLOBAL_DEF("display/use_2d_pixel_snap",false)); shadow_filter=ShadowFilterTechnique(int(Globals::get_singleton()->get("rasterizer/shadow_filter"))); #endif @@ -10807,7 +10807,7 @@ void RasterizerGLES2::init() { copy_shader.set_conditional(CopyShaderGLES2::USE_8BIT_HDR,!use_fp16_fb); canvas_shader.set_conditional(CanvasShaderGLES2::USE_DEPTH_SHADOWS,read_depth_supported); - canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP,GLOBAL_DEF("rasterizer/use_pixel_snap",false)); + canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP,GLOBAL_DEF("display/use_2d_pixel_snap",false)); npo2_textures_available=true; //fragment_lighting=false; diff --git a/main/main.cpp b/main/main.cpp index 84f7c3a88e..e1bc3b9fd9 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -701,6 +701,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas GLOBAL_DEF("display/resizable",video_mode.resizable); GLOBAL_DEF("display/test_width",0); GLOBAL_DEF("display/test_height",0); + OS::get_singleton()->_pixel_snap=GLOBAL_DEF("display/use_2d_pixel_snap",false); if (rtm==-1) { rtm=GLOBAL_DEF("render/thread_model",OS::RENDER_THREAD_SAFE); if (rtm>=1) //hack for now diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index 0b00ac9560..342b86b4c1 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -28,6 +28,8 @@ /*************************************************************************/ #include "animated_sprite.h" #include "scene/scene_string_names.h" +#include "os/os.h" + void AnimatedSprite::edit_set_pivot(const Point2& p_pivot) { set_offset(p_pivot); @@ -153,6 +155,9 @@ void AnimatedSprite::_notification(int p_what) { if (centered) ofs-=s/2; + if (OS::get_singleton()->get_use_pixel_snap()) { + ofs=ofs.floor(); + } Rect2 dst_rect(ofs,s); if (hflip) diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 87697fc073..89d9966958 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -30,6 +30,7 @@ #include "core/core_string_names.h" #include "scene/scene_string_names.h" #include "scene/main/viewport.h" +#include "os/os.h" void Sprite::edit_set_pivot(const Point2& p_pivot) { @@ -85,6 +86,9 @@ void Sprite::_notification(int p_what) { Point2 ofs=offset; if (centered) ofs-=s/2; + if (OS::get_singleton()->get_use_pixel_snap()) { + ofs=ofs.floor(); + } Rect2 dst_rect(ofs,s); @@ -422,6 +426,9 @@ void ViewportSprite::_notification(int p_what) { if (centered) ofs-=s/2; + if (OS::get_singleton()->get_use_pixel_snap()) { + ofs=ofs.floor(); + } Rect2 dst_rect(ofs,s); texture->draw_rect_region(ci,dst_rect,src_rect,modulate); |