From fdf914e53e80f49153ea7f999f816010c0ad8e50 Mon Sep 17 00:00:00 2001 From: Geequlim Date: Fri, 3 Jun 2016 22:11:10 +0800 Subject: [PATCH] Add texture region support for stylebox render --- core/command_queue_mt.h | 126 ++++++++++++++++++++++++ drivers/gles2/rasterizer_gles2.cpp | 45 +++++---- drivers/gles2/rasterizer_gles2.h | 2 +- platform/iphone/rasterizer_iphone.cpp | 26 ++--- scene/gui/patch_9_frame.cpp | 5 +- scene/resources/style_box.cpp | 3 +- servers/server_wrap_mt_common.h | 61 ++++++++++++ servers/visual/rasterizer.h | 5 +- servers/visual/rasterizer_dummy.cpp | 3 +- servers/visual/rasterizer_dummy.h | 2 +- servers/visual/visual_server_raster.cpp | 3 +- servers/visual/visual_server_raster.h | 2 +- servers/visual/visual_server_wrap_mt.h | 2 +- servers/visual_server.cpp | 6 +- servers/visual_server.h | 4 +- 15 files changed, 243 insertions(+), 52 deletions(-) diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index b1e0066c358..409543bf25f 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -152,6 +152,23 @@ class CommandQueueMT { virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); } }; + template + struct Command8 : public CommandBase { + + T*instance; + M method; + typename GetSimpleTypeT::type_t p1; + typename GetSimpleTypeT::type_t p2; + typename GetSimpleTypeT::type_t p3; + typename GetSimpleTypeT::type_t p4; + typename GetSimpleTypeT::type_t p5; + typename GetSimpleTypeT::type_t p6; + typename GetSimpleTypeT::type_t p7; + typename GetSimpleTypeT::type_t p8; + + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); } + }; + /* comands that return */ template @@ -270,6 +287,25 @@ class CommandQueueMT { virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; ; } }; + template + struct CommandRet8 : public CommandBase { + + T*instance; + M method; + typename GetSimpleTypeT::type_t p1; + typename GetSimpleTypeT::type_t p2; + typename GetSimpleTypeT::type_t p3; + typename GetSimpleTypeT::type_t p4; + typename GetSimpleTypeT::type_t p5; + typename GetSimpleTypeT::type_t p6; + typename GetSimpleTypeT::type_t p7; + typename GetSimpleTypeT::type_t p8; + R* ret; + SyncSemaphore *sync; + + virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; ; } + }; + /** commands that don't return but sync */ /* comands that return */ @@ -390,6 +426,25 @@ class CommandQueueMT { virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; ; } }; + template + struct CommandSync8 : public CommandBase { + + T*instance; + M method; + typename GetSimpleTypeT::type_t p1; + typename GetSimpleTypeT::type_t p2; + typename GetSimpleTypeT::type_t p3; + typename GetSimpleTypeT::type_t p4; + typename GetSimpleTypeT::type_t p5; + typename GetSimpleTypeT::type_t p6; + typename GetSimpleTypeT::type_t p7; + typename GetSimpleTypeT::type_t p8; + + SyncSemaphore *sync; + + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; ; } + }; + /***** BASE *******/ enum { @@ -639,6 +694,27 @@ public: if (sync) sync->post(); } + + template + void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8 ) { + + Command8 * cmd = allocate_and_lock< Command8 >(); + + cmd->instance=p_instance; + cmd->method=p_method; + cmd->p1=p1; + cmd->p2=p2; + cmd->p3=p3; + cmd->p4=p4; + cmd->p5=p5; + cmd->p6=p6; + cmd->p7=p7; + cmd->p8=p8; + + unlock(); + + if (sync) sync->post(); + } /*** PUSH AND RET COMMANDS ***/ @@ -806,6 +882,31 @@ public: ss->sem->wait(); } + template + void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6,P7 p7,P8 p8, R* r_ret ) { + + CommandRet8 * cmd = allocate_and_lock< CommandRet8 >(); + + cmd->instance=p_instance; + cmd->method=p_method; + cmd->p1=p1; + cmd->p2=p2; + cmd->p3=p3; + cmd->p4=p4; + cmd->p5=p5; + cmd->p6=p6; + cmd->p7=p7; + cmd->p8=p8; + cmd->ret=r_ret; + SyncSemaphore *ss=_alloc_sync_sem(); + cmd->sync=ss; + + unlock(); + + if (sync) sync->post(); + ss->sem->wait(); + } + template void push_and_sync( T * p_instance, M p_method) { @@ -971,6 +1072,31 @@ public: ss->sem->wait(); } + template + void push_and_sync( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6,P7 p7,P8 p8) { + + CommandSync8 * cmd = allocate_and_lock< CommandSync8 >(); + + cmd->instance=p_instance; + cmd->method=p_method; + cmd->p1=p1; + cmd->p2=p2; + cmd->p3=p3; + cmd->p4=p4; + cmd->p5=p5; + cmd->p6=p6; + cmd->p7=p7; + cmd->p8=p8; + + SyncSemaphore *ss=_alloc_sync_sem(); + cmd->sync=ss; + + unlock(); + + if (sync) sync->post(); + ss->sem->wait(); + } + void wait_and_flush_one() { ERR_FAIL_COND(!sync); sync->wait(); diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 79465638d17..8bd2fe38626 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -6497,7 +6497,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans if (!*e->additive_ptr) { additive=false; - *e->additive_ptr=true; + *e->additive_ptr=true; } else { additive=true; } @@ -6684,7 +6684,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans } rebind=true; } - + if (use_hw_skeleton_xform && (skeleton!=prev_skeleton||morph_values!=prev_morph_values)) { if (!prev_skeleton || !skeleton) rebind=true; //went from skeleton <-> no skeleton, needs rebind @@ -6718,7 +6718,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans DEBUG_TEST_ERROR("Setup geometry"); }; - if (i==0 || light!=prev_light || rebind) { + if (i==0 || light!=prev_light || rebind) { if (e->light!=0xFFFF) { _setup_light(e->light); @@ -6958,7 +6958,7 @@ void RasterizerGLES2::_process_glow_bloom() { _copy_screen_quad(); copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_COPY,false); - copy_shader.set_conditional(CopyShaderGLES2::USE_HDR,false); + copy_shader.set_conditional(CopyShaderGLES2::USE_HDR,false); int passes = current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_PASSES]; Vector2 psize(1.0/framebuffer.blur_size,1.0/framebuffer.blur_size); float pscale = current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_SCALE]; @@ -7427,7 +7427,7 @@ void RasterizerGLES2::end_scene() { _process_hdr(); } if (current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]) { - _process_glow_bloom(); + _process_glow_bloom(); int glow_transfer_mode=current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_BLEND_MODE]; if (glow_transfer_mode==1) copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_SCREEN,true); @@ -8438,7 +8438,7 @@ void RasterizerGLES2::canvas_draw_rect(const Rect2& p_rect, int p_flags, const R } -void RasterizerGLES2::canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margin, bool p_draw_center,const Color& p_modulate) { +void RasterizerGLES2::canvas_draw_style_box(const Rect2& p_rect, const Rect2& p_src_region, RID p_texture,const float *p_margin, bool p_draw_center,const Color& p_modulate) { Color m = p_modulate; m.a*=canvas_opacity; @@ -8446,52 +8446,57 @@ void RasterizerGLES2::canvas_draw_style_box(const Rect2& p_rect, RID p_texture,c Texture* texture=_bind_canvas_texture(p_texture); ERR_FAIL_COND(!texture); - /* CORNERS */ + Rect2 region = p_src_region; + if (region.size.width <= 0 ) + region.size.width = texture->width; + if (region.size.height <= 0) + region.size.height = texture->height; + /* CORNERS */ _draw_textured_quad( // top left Rect2( p_rect.pos, Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])), - Rect2( Point2(), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])), + Rect2( region.pos, Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])), Size2( texture->width, texture->height ) ); _draw_textured_quad( // top right Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])), - Rect2( Point2(texture->width-p_margin[MARGIN_RIGHT],0), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])), + Rect2( Point2(region.pos.x+region.size.width-p_margin[MARGIN_RIGHT], region.pos.y), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])), Size2( texture->width, texture->height ) ); _draw_textured_quad( // bottom left Rect2( Point2(p_rect.pos.x,p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])), - Rect2( Point2(0,texture->height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])), + Rect2( Point2(region.pos.x, region.pos.y+region.size.height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])), Size2( texture->width, texture->height ) ); _draw_textured_quad( // bottom right Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])), - Rect2( Point2(texture->width-p_margin[MARGIN_RIGHT],texture->height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])), + Rect2( Point2(region.pos.x+region.size.width-p_margin[MARGIN_RIGHT], region.pos.y+region.size.height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])), Size2( texture->width, texture->height ) ); Rect2 rect_center( p_rect.pos+Point2( p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2( p_rect.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], p_rect.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] )); - Rect2 src_center( Point2( p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2( texture->width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], texture->height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] )); + Rect2 src_center( Point2(region.pos.x+p_margin[MARGIN_LEFT], region.pos.y+p_margin[MARGIN_TOP]), Size2(region.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], region.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] )); _draw_textured_quad( // top Rect2( Point2(rect_center.pos.x,p_rect.pos.y),Size2(rect_center.size.width,p_margin[MARGIN_TOP])), - Rect2( Point2(p_margin[MARGIN_LEFT],0), Size2(src_center.size.width,p_margin[MARGIN_TOP])), + Rect2( Point2(src_center.pos.x,region.pos.y), Size2(src_center.size.width,p_margin[MARGIN_TOP])), Size2( texture->width, texture->height ) ); _draw_textured_quad( // bottom Rect2( Point2(rect_center.pos.x,rect_center.pos.y+rect_center.size.height),Size2(rect_center.size.width,p_margin[MARGIN_BOTTOM])), - Rect2( Point2(p_margin[MARGIN_LEFT],src_center.pos.y+src_center.size.height), Size2(src_center.size.width,p_margin[MARGIN_BOTTOM])), + Rect2( Point2(src_center.pos.x,src_center.pos.y+src_center.size.height), Size2(src_center.size.width,p_margin[MARGIN_BOTTOM])), Size2( texture->width, texture->height ) ); _draw_textured_quad( // left Rect2( Point2(p_rect.pos.x,rect_center.pos.y),Size2(p_margin[MARGIN_LEFT],rect_center.size.height)), - Rect2( Point2(0,p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_LEFT],src_center.size.height)), + Rect2( Point2(region.pos.x,region.pos.y+p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_LEFT],src_center.size.height)), Size2( texture->width, texture->height ) ); _draw_textured_quad( // right Rect2( Point2(rect_center.pos.x+rect_center.size.width,rect_center.pos.y),Size2(p_margin[MARGIN_RIGHT],rect_center.size.height)), - Rect2( Point2(src_center.pos.x+src_center.size.width,p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_RIGHT],src_center.size.height)), + Rect2( Point2(src_center.pos.x+src_center.size.width,region.pos.y+p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_RIGHT],src_center.size.height)), Size2( texture->width, texture->height ) ); if (p_draw_center) { @@ -8569,7 +8574,7 @@ void RasterizerGLES2::canvas_draw_polygon(int p_vertex_count, const int* p_indic #else //WebGL specific impl. - glBindBuffer(GL_ARRAY_BUFFER, gui_quad_buffer); + glBindBuffer(GL_ARRAY_BUFFER, gui_quad_buffer); float *b = GlobalVertexBuffer; int ofs = 0; if(p_vertex_count > MAX_POLYGON_VERTICES){ @@ -9184,7 +9189,7 @@ void RasterizerGLES2::_canvas_item_render_commands(CanvasItem *p_item,CanvasItem CanvasItem::CommandStyle* style = static_cast(c); if (use_normalmap) _canvas_normal_set_flip(Vector2(1,1)); - canvas_draw_style_box(style->rect,style->texture,style->margin,style->draw_center,style->color); + canvas_draw_style_box(style->rect,style->source,style->texture,style->margin,style->draw_center,style->color); } break; case CanvasItem::Command::TYPE_PRIMITIVE: { @@ -9430,7 +9435,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const draw_viewport_func(ci->vp_render->owner,ci->vp_render->udata,ci->vp_render->rect); } memdelete(ci->vp_render); - ci->vp_render=NULL; + ci->vp_render=NULL; canvas_last_material=NULL; canvas_use_modulate=p_modulate!=Color(1,1,1,1); canvas_modulate=p_modulate; @@ -11424,7 +11429,7 @@ RasterizerGLES2::RasterizerGLES2(bool p_compress_arrays,bool p_keep_ram_copy,boo void RasterizerGLES2::restore_framebuffer() { glBindFramebuffer(GL_FRAMEBUFFER, base_framebuffer); - + } RasterizerGLES2::~RasterizerGLES2() { diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h index 35efedc9c8b..c9fc0c247d0 100644 --- a/drivers/gles2/rasterizer_gles2.h +++ b/drivers/gles2/rasterizer_gles2.h @@ -1635,7 +1635,7 @@ public: virtual void canvas_end_rect(); virtual void canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width); virtual void canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate); - virtual void canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1)); + virtual void canvas_draw_style_box(const Rect2& p_rect, const Rect2& p_src_region, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1)); virtual void canvas_draw_primitive(const Vector& p_points, const Vector& p_colors,const Vector& p_uvs, RID p_texture,float p_width); virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor); virtual void canvas_set_transform(const Matrix32& p_transform); diff --git a/platform/iphone/rasterizer_iphone.cpp b/platform/iphone/rasterizer_iphone.cpp index f06f12547ff..99e83343d09 100644 --- a/platform/iphone/rasterizer_iphone.cpp +++ b/platform/iphone/rasterizer_iphone.cpp @@ -2446,7 +2446,7 @@ void RasterizerIPhone::canvas_draw_rect(const Rect2& p_rect, bool p_region, cons } -void RasterizerIPhone::canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margin, bool p_draw_center) { +void RasterizerIPhone::canvas_draw_style_box(const Rect2& p_rect, const Rect2& p_src_region, RID p_texture,const float *p_margin, bool p_draw_center) { glColor4f(1, 1, 1, 1); @@ -2458,52 +2458,56 @@ void RasterizerIPhone::canvas_draw_style_box(const Rect2& p_rect, RID p_texture, glBindTexture( GL_TEXTURE_2D,texture->tex_id ); + Rect2 region = p_src_region; + if (region.size.width <= 0 ) + region.size.width = texture->width; + if (region.size.height <= 0) + region.size.height = texture->height; /* CORNERS */ - _draw_textured_quad( // top left Rect2( p_rect.pos, Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])), - Rect2( Point2(), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])), + Rect2( region.pos, Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])), Size2( texture->width, texture->height ) ); _draw_textured_quad( // top right Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])), - Rect2( Point2(texture->width-p_margin[MARGIN_RIGHT],0), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])), + Rect2( Point2(region.pos.x+region.size.width-p_margin[MARGIN_RIGHT], region.pos.y), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])), Size2( texture->width, texture->height ) ); _draw_textured_quad( // bottom left Rect2( Point2(p_rect.pos.x,p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])), - Rect2( Point2(0,texture->height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])), + Rect2( Point2(region.pos.x, region.pos.y+region.size.height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])), Size2( texture->width, texture->height ) ); _draw_textured_quad( // bottom right Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])), - Rect2( Point2(texture->width-p_margin[MARGIN_RIGHT],texture->height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])), + Rect2( Point2(region.pos.x+region.size.width-p_margin[MARGIN_RIGHT], region.pos.y+region.size.height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])), Size2( texture->width, texture->height ) ); Rect2 rect_center( p_rect.pos+Point2( p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2( p_rect.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], p_rect.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] )); - Rect2 src_center( Point2( p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2( texture->width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], texture->height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] )); + Rect2 src_center( Point2(region.pos.x+p_margin[MARGIN_LEFT], region.pos.y+p_margin[MARGIN_TOP]), Size2(region.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], region.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] )); _draw_textured_quad( // top Rect2( Point2(rect_center.pos.x,p_rect.pos.y),Size2(rect_center.size.width,p_margin[MARGIN_TOP])), - Rect2( Point2(p_margin[MARGIN_LEFT],0), Size2(src_center.size.width,p_margin[MARGIN_TOP])), + Rect2( Point2(src_center.pos.x,region.pos.y), Size2(src_center.size.width,p_margin[MARGIN_TOP])), Size2( texture->width, texture->height ) ); _draw_textured_quad( // bottom Rect2( Point2(rect_center.pos.x,rect_center.pos.y+rect_center.size.height),Size2(rect_center.size.width,p_margin[MARGIN_BOTTOM])), - Rect2( Point2(p_margin[MARGIN_LEFT],src_center.pos.y+src_center.size.height), Size2(src_center.size.width,p_margin[MARGIN_BOTTOM])), + Rect2( Point2(src_center.pos.x,src_center.pos.y+src_center.size.height), Size2(src_center.size.width,p_margin[MARGIN_BOTTOM])), Size2( texture->width, texture->height ) ); _draw_textured_quad( // left Rect2( Point2(p_rect.pos.x,rect_center.pos.y),Size2(p_margin[MARGIN_LEFT],rect_center.size.height)), - Rect2( Point2(0,p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_LEFT],src_center.size.height)), + Rect2( Point2(region.pos.x,region.pos.y+p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_LEFT],src_center.size.height)), Size2( texture->width, texture->height ) ); _draw_textured_quad( // right Rect2( Point2(rect_center.pos.x+rect_center.size.width,rect_center.pos.y),Size2(p_margin[MARGIN_RIGHT],rect_center.size.height)), - Rect2( Point2(src_center.pos.x+src_center.size.width,p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_RIGHT],src_center.size.height)), + Rect2( Point2(src_center.pos.x+src_center.size.width,region.pos.y+p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_RIGHT],src_center.size.height)), Size2( texture->width, texture->height ) ); if (p_draw_center) { diff --git a/scene/gui/patch_9_frame.cpp b/scene/gui/patch_9_frame.cpp index b6e261714c3..c507c3a03fd 100644 --- a/scene/gui/patch_9_frame.cpp +++ b/scene/gui/patch_9_frame.cpp @@ -9,10 +9,9 @@ void Patch9Frame::_notification(int p_what) { if (texture.is_null()) return; - Size2 s=get_size(); RID ci = get_canvas_item(); - VS::get_singleton()->canvas_item_add_style_box(ci,Rect2(Point2(),s),texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center,modulate); + VS::get_singleton()->canvas_item_add_style_box(ci,Rect2(Point2(),s),Rect2(),texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center,modulate); // draw_texture_rect(texture,Rect2(Point2(),s),false,modulate); /* @@ -128,5 +127,3 @@ Patch9Frame::Patch9Frame() { Patch9Frame::~Patch9Frame() { } - - diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 75e38f97015..98a0d30478c 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -138,7 +138,7 @@ void StyleBoxTexture::draw(RID p_canvas_item,const Rect2& p_rect) const { r.pos.y-=expand_margin[MARGIN_TOP]; r.size.x+=expand_margin[MARGIN_LEFT]+expand_margin[MARGIN_RIGHT]; r.size.y+=expand_margin[MARGIN_TOP]+expand_margin[MARGIN_BOTTOM]; - VisualServer::get_singleton()->canvas_item_add_style_box( p_canvas_item,r,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center); + VisualServer::get_singleton()->canvas_item_add_style_box( p_canvas_item,r,Rect2(),texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center); } void StyleBoxTexture::set_draw_center(bool p_draw) { @@ -505,4 +505,3 @@ StyleBoxImageMask::StyleBoxImageMask() { } expand=true; } - diff --git a/servers/server_wrap_mt_common.h b/servers/server_wrap_mt_common.h index cbb75129d01..149e9ec4f97 100644 --- a/servers/server_wrap_mt_common.h +++ b/servers/server_wrap_mt_common.h @@ -698,3 +698,64 @@ }\ } +#define FUNC8R(m_r,m_type,m_arg1, m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8)\ + virtual m_r m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8) { \ + if (Thread::get_caller_ID()!=server_thread) {\ + m_r ret;\ + command_queue.push_and_ret( server_name, &ServerName::m_type,p1, p2, p3, p4, p5, p6, p7, p8, &ret);\ + SYNC_DEBUG\ + return ret;\ + } else {\ + return server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8);\ + }\ + } + +#define FUNC8RC(m_r,m_type,m_arg1, m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8)\ + virtual m_r m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8) const { \ + if (Thread::get_caller_ID()!=server_thread) {\ + m_r ret;\ + command_queue.push_and_ret( server_name, &ServerName::m_type,p1, p2, p3, p4, p5, p6, p7, p8, &ret);\ + SYNC_DEBUG\ + return ret;\ + } else {\ + return server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8);\ + }\ + } + + +#define FUNC8S(m_type,m_arg1, m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8)\ + virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8) { \ + if (Thread::get_caller_ID()!=server_thread) {\ + command_queue.push_and_sync( server_name, &ServerName::m_type,p1, p2, p3, p4, p5, p6, p7, p8);\ + } else {\ + server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8);\ + }\ + } + +#define FUNC8SC(m_type,m_arg1, m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8)\ + virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8) const { \ + if (Thread::get_caller_ID()!=server_thread) {\ + command_queue.push_and_sync( server_name, &ServerName::m_type,p1, p2, p3, p4, p5, p6, p7, p8);\ + } else {\ + server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8);\ + }\ + } + + +#define FUNC8(m_type,m_arg1, m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8)\ + virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8) { \ + if (Thread::get_caller_ID()!=server_thread) {\ + command_queue.push( server_name, &ServerName::m_type,p1, p2, p3, p4, p5, p6, p7, p8);\ + } else {\ + server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8);\ + }\ + } + +#define FUNC8C(m_type,m_arg1, m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8)\ + virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8) const { \ + if (Thread::get_caller_ID()!=server_thread) {\ + command_queue.push( server_name, &ServerName::m_type,p1, p2, p3, p4, p5, p6, p7, p8);\ + } else {\ + server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8);\ + }\ + } diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index f1ad685879c..50ec6792cc4 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -702,6 +702,7 @@ public: struct CommandStyle : public Command { Rect2 rect; + Rect2 source; RID texture; float margin[4]; bool draw_center; @@ -944,12 +945,12 @@ public: virtual void canvas_disable_blending()=0; virtual void canvas_set_opacity(float p_opacity)=0; virtual void canvas_set_blend_mode(VS::MaterialBlendMode p_mode)=0; - virtual void canvas_begin_rect(const Matrix32& p_transform)=0;; + virtual void canvas_begin_rect(const Matrix32& p_transform)=0; virtual void canvas_set_clip(bool p_clip, const Rect2& p_rect)=0; virtual void canvas_end_rect()=0; virtual void canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width)=0; virtual void canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate)=0; - virtual void canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1))=0; + virtual void canvas_draw_style_box(const Rect2& p_rect, const Rect2& p_src_region, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1))=0; virtual void canvas_draw_primitive(const Vector& p_points, const Vector& p_colors,const Vector& p_uvs, RID p_texture,float p_width)=0; virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor)=0; virtual void canvas_set_transform(const Matrix32& p_transform)=0; diff --git a/servers/visual/rasterizer_dummy.cpp b/servers/visual/rasterizer_dummy.cpp index 3b12b503dd0..0e71d224d50 100644 --- a/servers/visual/rasterizer_dummy.cpp +++ b/servers/visual/rasterizer_dummy.cpp @@ -1627,7 +1627,7 @@ void RasterizerDummy::canvas_draw_rect(const Rect2& p_rect, int p_flags, const R } -void RasterizerDummy::canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margin, bool p_draw_center,const Color& p_modulate) { +void RasterizerDummy::canvas_draw_style_box(const Rect2& p_rect, const Rect2& p_src_region, RID p_texture,const float *p_margin, bool p_draw_center,const Color& p_modulate) { } @@ -1959,4 +1959,3 @@ RasterizerDummy::RasterizerDummy() { RasterizerDummy::~RasterizerDummy() { }; - diff --git a/servers/visual/rasterizer_dummy.h b/servers/visual/rasterizer_dummy.h index 674c1659661..ac320e55f93 100644 --- a/servers/visual/rasterizer_dummy.h +++ b/servers/visual/rasterizer_dummy.h @@ -708,7 +708,7 @@ public: virtual void canvas_end_rect(); virtual void canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width); virtual void canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate); - virtual void canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1)); + virtual void canvas_draw_style_box(const Rect2& p_rect, const Rect2& p_src_region, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1)); virtual void canvas_draw_primitive(const Vector& p_points, const Vector& p_colors,const Vector& p_uvs, RID p_texture,float p_width); virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor); virtual void canvas_set_transform(const Matrix32& p_transform); diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index b3721268bf6..532247d94ce 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -3745,7 +3745,7 @@ void VisualServerRaster::canvas_item_add_texture_rect_region(RID p_item, const R } -void VisualServerRaster::canvas_item_add_style_box(RID p_item, const Rect2& p_rect, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright, bool p_draw_center,const Color& p_modulate) { +void VisualServerRaster::canvas_item_add_style_box(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture, const Vector2& p_topleft, const Vector2& p_bottomright, bool p_draw_center,const Color& p_modulate) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); @@ -3755,6 +3755,7 @@ void VisualServerRaster::canvas_item_add_style_box(RID p_item, const Rect2& p_re ERR_FAIL_COND(!style); style->texture=p_texture; style->rect=p_rect; + style->source=p_source; style->draw_center=p_draw_center; style->color=p_modulate; style->margin[MARGIN_LEFT]=p_topleft.x; diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 39ea2f55e66..dcaac6e8d27 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -1171,7 +1171,7 @@ public: virtual void canvas_item_add_circle(RID p_item, const Point2& p_pos, float p_radius,const Color& p_color); virtual void canvas_item_add_texture_rect(RID p_item, const Rect2& p_rect, RID p_texture,bool p_tile=false,const Color& p_modulate=Color(1,1,1),bool p_transpose=false); virtual void canvas_item_add_texture_rect_region(RID p_item, const Rect2& p_rect, RID p_texture,const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1),bool p_transpose=false); - virtual void canvas_item_add_style_box(RID p_item, const Rect2& p_rect, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1)); + virtual void canvas_item_add_style_box(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1)); virtual void canvas_item_add_primitive(RID p_item, const Vector& p_points, const Vector& p_colors,const Vector& p_uvs, RID p_texture,float p_width=1.0); virtual void canvas_item_add_polygon(RID p_item, const Vector& p_points, const Vector& p_colors,const Vector& p_uvs=Vector(), RID p_texture=RID()); virtual void canvas_item_add_triangle_array(RID p_item, const Vector& p_indices, const Vector& p_points, const Vector& p_colors,const Vector& p_uvs=Vector(), RID p_texture=RID(), int p_count=-1); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 80cf43d572c..a97b232c031 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -607,7 +607,7 @@ public: FUNC4(canvas_item_add_circle,RID, const Point2& , float ,const Color& ); FUNC6(canvas_item_add_texture_rect,RID, const Rect2& , RID ,bool ,const Color&,bool ); FUNC6(canvas_item_add_texture_rect_region,RID, const Rect2& , RID ,const Rect2& ,const Color&,bool ); - FUNC7(canvas_item_add_style_box,RID, const Rect2& , RID ,const Vector2& ,const Vector2&, bool ,const Color& ); + FUNC8(canvas_item_add_style_box,RID, const Rect2& , const Rect2&, RID ,const Vector2& ,const Vector2&, bool ,const Color& ); FUNC6(canvas_item_add_primitive,RID, const Vector& , const Vector& ,const Vector& , RID ,float ); FUNC5(canvas_item_add_polygon,RID, const Vector& , const Vector& ,const Vector& , RID ); FUNC7(canvas_item_add_triangle_array,RID, const Vector& , const Vector& , const Vector& ,const Vector& , RID , int ); diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index 5ac0e5b5d5d..570a5a6ee44 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -705,10 +705,10 @@ void VisualServer::_bind_methods() { } -void VisualServer::_canvas_item_add_style_box(RID p_item, const Rect2& p_rect, RID p_texture,const Vector& p_margins, const Color& p_modulate) { +void VisualServer::_canvas_item_add_style_box(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector& p_margins, const Color& p_modulate) { ERR_FAIL_COND(p_margins.size()!=4); - canvas_item_add_style_box(p_item, p_rect, p_texture,Vector2(p_margins[0],p_margins[1]),Vector2(p_margins[2],p_margins[3]),true,p_modulate); + canvas_item_add_style_box(p_item,p_rect,p_source,p_texture,Vector2(p_margins[0],p_margins[1]),Vector2(p_margins[2],p_margins[3]),true,p_modulate); } void VisualServer::_camera_set_orthogonal(RID p_camera,float p_size,float p_z_near,float p_z_far) { @@ -822,5 +822,3 @@ VisualServer::~VisualServer() { singleton=NULL; } - - diff --git a/servers/visual_server.h b/servers/visual_server.h index f32e976b571..f330a6faeec 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -52,7 +52,7 @@ class VisualServer : public Object { void _camera_set_orthogonal(RID p_camera,float p_size,float p_z_near,float p_z_far); void _viewport_set_rect(RID p_viewport,const Rect2& p_rect); Rect2 _viewport_get_rect(RID p_viewport) const; - void _canvas_item_add_style_box(RID p_item, const Rect2& p_rect, RID p_texture,const Vector& p_margins, const Color& p_modulate=Color(1,1,1)); + void _canvas_item_add_style_box(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector& p_margins, const Color& p_modulate=Color(1,1,1)); protected: RID _make_test_cube(); void _free_internal_rids(); @@ -1025,7 +1025,7 @@ public: virtual void canvas_item_add_circle(RID p_item, const Point2& p_pos, float p_radius,const Color& p_color)=0; virtual void canvas_item_add_texture_rect(RID p_item, const Rect2& p_rect, RID p_texture,bool p_tile=false,const Color& p_modulate=Color(1,1,1),bool p_transpose=false)=0; virtual void canvas_item_add_texture_rect_region(RID p_item, const Rect2& p_rect, RID p_texture,const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1),bool p_transpose=false)=0; - virtual void canvas_item_add_style_box(RID p_item, const Rect2& p_rect, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1))=0; + virtual void canvas_item_add_style_box(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1))=0; virtual void canvas_item_add_primitive(RID p_item, const Vector& p_points, const Vector& p_colors,const Vector& p_uvs, RID p_texture,float p_width=1.0)=0; virtual void canvas_item_add_polygon(RID p_item, const Vector& p_points, const Vector& p_colors,const Vector& p_uvs=Vector(), RID p_texture=RID())=0; virtual void canvas_item_add_triangle_array(RID p_item, const Vector& p_indices, const Vector& p_points, const Vector& p_colors,const Vector& p_uvs=Vector(), RID p_texture=RID(), int p_count=-1)=0;