diff options
Diffstat (limited to 'scene/main/viewport.cpp')
-rw-r--r-- | scene/main/viewport.cpp | 441 |
1 files changed, 256 insertions, 185 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 0c243bd473..ff148cc413 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -51,50 +51,52 @@ #include "globals.h" -int RenderTargetTexture::get_width() const { +int ViewportTexture::get_width() const { ERR_FAIL_COND_V(!vp,0); - return vp->rect.size.width; + return vp->size.width; } -int RenderTargetTexture::get_height() const{ +int ViewportTexture::get_height() const{ ERR_FAIL_COND_V(!vp,0); - return vp->rect.size.height; + return vp->size.height; } -Size2 RenderTargetTexture::get_size() const{ +Size2 ViewportTexture::get_size() const{ ERR_FAIL_COND_V(!vp,Size2()); - return vp->rect.size; + return vp->size; } -RID RenderTargetTexture::get_rid() const{ +RID ViewportTexture::get_rid() const{ ERR_FAIL_COND_V(!vp,RID()); - return vp->render_target_texture_rid; + return vp->texture_rid; } -bool RenderTargetTexture::has_alpha() const{ +bool ViewportTexture::has_alpha() const{ return false; } -void RenderTargetTexture::set_flags(uint32_t p_flags){ +void ViewportTexture::set_flags(uint32_t p_flags){ + + if (!vp) + return; - ERR_FAIL_COND(!vp); if (p_flags&FLAG_FILTER) flags=FLAG_FILTER; else flags=0; - VS::get_singleton()->texture_set_flags(vp->render_target_texture_rid,flags); + VS::get_singleton()->texture_set_flags(vp->texture_rid,flags); } -uint32_t RenderTargetTexture::get_flags() const{ +uint32_t ViewportTexture::get_flags() const{ return flags; } -RenderTargetTexture::RenderTargetTexture(Viewport *p_vp){ +ViewportTexture::ViewportTexture(Viewport *p_vp){ vp=p_vp; flags=0; @@ -141,9 +143,9 @@ void Viewport::_update_stretch_transform() { if (size_override_stretch && size_override) { //print_line("sive override size "+size_override_size); - //print_line("rect size "+rect.size); + //print_line("rect size "+size); stretch_transform=Matrix32(); - Size2 scale = rect.size/(size_override_size+size_override_margin*2); + Size2 scale = size/(size_override_size+size_override_margin*2); stretch_transform.scale(scale); stretch_transform.elements[2]=size_override_margin*scale; @@ -164,14 +166,14 @@ void Viewport::_update_rect() { return; - if (!render_target && parent_control) { + /*if (!render_target && parent_control) { Control *c = parent_control; rect.pos=Point2(); rect.size=c->get_size(); - } - + }*/ +/* VisualServer::ViewportRect vr; vr.x=rect.pos.x; vr.y=rect.pos.y; @@ -191,8 +193,8 @@ void Viewport::_update_rect() { } emit_signal("size_changed"); - render_target_texture->emit_changed(); - + texture->emit_changed(); +*/ } @@ -207,7 +209,7 @@ void Viewport::_parent_draw() { void Viewport::_parent_visibility_changed() { - +/* if (parent_control) { Control *c = parent_control; @@ -216,14 +218,14 @@ void Viewport::_parent_visibility_changed() { _update_listener(); _update_listener_2d(); } - +*/ } void Viewport::_vp_enter_tree() { - if (parent_control) { +/* if (parent_control) { Control *cparent=parent_control; RID parent_ci = cparent->get_canvas_item(); @@ -232,20 +234,21 @@ void Viewport::_vp_enter_tree() { VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,parent_ci); VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,false); - VisualServer::get_singleton()->canvas_item_attach_viewport(canvas_item,viewport); +// VisualServer::get_singleton()->canvas_item_attach_viewport(canvas_item,viewport); parent_control->connect("resized",this,"_parent_resized"); parent_control->connect("visibility_changed",this,"_parent_visibility_changed"); } else if (!parent){ - VisualServer::get_singleton()->viewport_attach_to_screen(viewport,0); +// VisualServer::get_singleton()->viewport_attach_to_screen(viewport,0); } - +*/ } void Viewport::_vp_exit_tree() { + /* if (parent_control) { parent_control->disconnect("resized",this,"_parent_resized"); @@ -268,7 +271,7 @@ void Viewport::_vp_exit_tree() { VisualServer::get_singleton()->viewport_detach(viewport); } - +*/ } @@ -326,31 +329,12 @@ void Viewport::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { if (get_parent()) { - Node *parent=get_parent(); - if (parent) { - parent_control=parent->cast_to<Control>(); - } - } - - - parent=NULL; - Node *parent_node=get_parent(); - - - while(parent_node) { - - parent = parent_node->cast_to<Viewport>(); - if (parent) - break; - - parent_node=parent_node->get_parent(); + parent = get_parent()->get_viewport(); + VisualServer::get_singleton()->viewport_set_parent_viewport(viewport,parent->get_viewport()); + } else { + parent=NULL; } - - if (!render_target) - _vp_enter_tree(); - - current_canvas=find_world_2d()->get_canvas(); VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario()); VisualServer::get_singleton()->viewport_attach_canvas(viewport,current_canvas); @@ -370,7 +354,7 @@ void Viewport::_notification(int p_what) { //3D PhysicsServer::get_singleton()->space_set_debug_contacts(find_world()->get_space(),get_tree()->get_collision_debug_contact_count()); contact_3d_debug_multimesh=VisualServer::get_singleton()->multimesh_create(); - VisualServer::get_singleton()->multimesh_set_instance_count(contact_3d_debug_multimesh,get_tree()->get_collision_debug_contact_count()); + VisualServer::get_singleton()->multimesh_allocate(contact_3d_debug_multimesh,get_tree()->get_collision_debug_contact_count(),VS::MULTIMESH_TRANSFORM_3D,VS::MULTIMESH_COLOR_8BIT); VisualServer::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh,0); VisualServer::get_singleton()->multimesh_set_mesh(contact_3d_debug_multimesh,get_tree()->get_debug_contact_mesh()->get_rid()); contact_3d_debug_instance=VisualServer::get_singleton()->instance_create(); @@ -380,6 +364,7 @@ void Viewport::_notification(int p_what) { } + VS::get_singleton()->viewport_set_active(viewport,true); } break; case NOTIFICATION_READY: { #ifndef _3D_DISABLED @@ -418,8 +403,8 @@ void Viewport::_notification(int p_what) { if (world_2d.is_valid()) world_2d->_remove_viewport(this); - if (!render_target) - _vp_exit_tree(); + //if (!render_target) + // _vp_exit_tree(); VisualServer::get_singleton()->viewport_set_scenario(viewport,RID()); SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); @@ -437,7 +422,10 @@ void Viewport::_notification(int p_what) { } remove_from_group("_viewports"); - parent_control=NULL; + + + VS::get_singleton()->viewport_set_active(viewport,false); + } break; case NOTIFICATION_FIXED_PROCESS: { @@ -452,7 +440,7 @@ void Viewport::_notification(int p_what) { if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) { VisualServer::get_singleton()->canvas_item_clear(contact_2d_debug); - VisualServer::get_singleton()->canvas_item_raise(contact_2d_debug); + VisualServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug,0xFFFFF); //very high index Vector<Vector2> points = Physics2DServer::get_singleton()->space_get_contacts(find_world_2d()->get_space()); int point_count = Physics2DServer::get_singleton()->space_get_contact_count(find_world_2d()->get_space()); @@ -474,27 +462,11 @@ void Viewport::_notification(int p_what) { VS::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh,point_count); - if (point_count>0) { - AABB aabb; - - Transform t; - for(int i=0;i<point_count;i++) { - - if (i==0) - aabb.pos=points[i]; - else - aabb.expand_to(points[i]); - t.origin=points[i]; - VisualServer::get_singleton()->multimesh_instance_set_transform(contact_3d_debug_multimesh,i,t); - } - aabb.grow(aabb.get_longest_axis_size()*0.01); - VisualServer::get_singleton()->multimesh_set_aabb(contact_3d_debug_multimesh,aabb); - } } - if (physics_object_picking && (render_target || Input::get_singleton()->get_mouse_mode()!=Input::MOUSE_MODE_CAPTURED)) { + if (physics_object_picking && (to_screen_rect==Rect2() || Input::get_singleton()->get_mouse_mode()!=Input::MOUSE_MODE_CAPTURED)) { Vector2 last_pos(1e20,1e20); CollisionObject *last_object; @@ -708,15 +680,18 @@ RID Viewport::get_viewport() const { return viewport; } -void Viewport::set_rect(const Rect2& p_rect) { +void Viewport::set_size(const Size2 &p_size) { - if (rect==p_rect) + if (size==p_size.floor()) return; - rect=p_rect; + size=p_size.floor(); + VS::get_singleton()->viewport_set_size(viewport,size.width,size.height); _update_rect(); _update_stretch_transform(); + emit_signal("size_changed"); + } Rect2 Viewport::get_visible_rect() const { @@ -724,12 +699,12 @@ Rect2 Viewport::get_visible_rect() const { Rect2 r; - if (rect.pos==Vector2() && rect.size==Size2()) { + if (size==Size2()) { r=Rect2( Point2(), Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height ) ); } else { - r=Rect2( rect.pos , rect.size ); + r=Rect2( Point2() , size ); } if (size_override) { @@ -740,9 +715,9 @@ Rect2 Viewport::get_visible_rect() const { return r; } -Rect2 Viewport::get_rect() const { +Size2 Viewport::get_size() const { - return rect; + return size; } @@ -1219,10 +1194,10 @@ bool Viewport::is_size_override_stretch_enabled() const { return size_override_stretch; } - +#if 0 void Viewport::set_as_render_target(bool p_enable){ - if (render_target==p_enable) +/* if (render_target==p_enable) return; render_target=p_enable; @@ -1238,117 +1213,126 @@ void Viewport::set_as_render_target(bool p_enable){ if (p_enable) { - render_target_texture_rid = VS::get_singleton()->viewport_get_render_target_texture(viewport); + texture_rid = VS::get_singleton()->viewport_get_texture(viewport); } else { - render_target_texture_rid=RID(); + texture_rid=RID(); } - render_target_texture->set_flags(render_target_texture->flags); - render_target_texture->emit_changed(); + texture->set_flags(texture->flags); + texture->emit_changed(); update_configuration_warning(); + */ } bool Viewport::is_set_as_render_target() const{ return render_target; + } -void Viewport::set_render_target_update_mode(RenderTargetUpdateMode p_mode){ +#endif +void Viewport::set_update_mode(UpdateMode p_mode){ - render_target_update_mode=p_mode; - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RenderTargetUpdateMode(p_mode)); + update_mode=p_mode; + VS::get_singleton()->viewport_set_update_mode(viewport,VS::ViewportUpdateMode(p_mode)); } -Viewport::RenderTargetUpdateMode Viewport::get_render_target_update_mode() const{ +Viewport::UpdateMode Viewport::get_update_mode() const{ - return render_target_update_mode; + return update_mode; } -//RID get_render_target_texture() const; +//RID get_texture() const; void Viewport::queue_screen_capture(){ - VS::get_singleton()->viewport_queue_screen_capture(viewport); + //VS::get_singleton()->viewport_queue_screen_capture(viewport); } Image Viewport::get_screen_capture() const { - return VS::get_singleton()->viewport_get_screen_capture(viewport); +// return VS::get_singleton()->viewport_get_screen_capture(viewport); + return Image(); } -Ref<RenderTargetTexture> Viewport::get_render_target_texture() const { +Ref<ViewportTexture> Viewport::get_texture() const { - return render_target_texture; + return texture; } -void Viewport::set_render_target_vflip(bool p_enable) { +void Viewport::set_vflip(bool p_enable) { - render_target_vflip=p_enable; - VisualServer::get_singleton()->viewport_set_render_target_vflip(viewport,p_enable); + vflip=p_enable; + VisualServer::get_singleton()->viewport_set_vflip(viewport,p_enable); } -bool Viewport::get_render_target_vflip() const{ +bool Viewport::get_vflip() const{ - return render_target_vflip; + return vflip; } -void Viewport::set_render_target_clear_on_new_frame(bool p_enable) { +void Viewport::set_clear_on_new_frame(bool p_enable) { - render_target_clear_on_new_frame=p_enable; - VisualServer::get_singleton()->viewport_set_render_target_clear_on_new_frame(viewport,p_enable); + clear_on_new_frame=p_enable; + //VisualServer::get_singleton()->viewport_set_clear_on_new_frame(viewport,p_enable); } -bool Viewport::get_render_target_clear_on_new_frame() const{ +bool Viewport::get_clear_on_new_frame() const{ - return render_target_clear_on_new_frame; + return clear_on_new_frame; } -void Viewport::render_target_clear() { +void Viewport::set_shadow_atlas_size(int p_size) { + + if (shadow_atlas_size==p_size) + return; - //render_target_clear=true; - VisualServer::get_singleton()->viewport_render_target_clear(viewport); + shadow_atlas_size=p_size; + VS::get_singleton()->viewport_set_shadow_atlas_size(viewport,p_size); } -void Viewport::set_render_target_filter(bool p_enable) { +int Viewport::get_shadow_atlas_size() const{ - if(!render_target) - return; + return shadow_atlas_size; +} - render_target_texture->set_flags(p_enable?int(Texture::FLAG_FILTER):int(0)); +void Viewport::set_shadow_atlas_quadrant_subdiv(int p_quadrant,ShadowAtlasQuadrantSubdiv p_subdiv){ -} -bool Viewport::get_render_target_filter() const{ + ERR_FAIL_INDEX(p_quadrant,4); + ERR_FAIL_INDEX(p_subdiv,SHADOW_ATLAS_QUADRANT_SUBDIV_MAX); - return (render_target_texture->get_flags()&Texture::FLAG_FILTER)!=0; -} + if (shadow_atlas_quadrant_subdiv[p_quadrant]==p_subdiv) + return; -void Viewport::set_render_target_gen_mipmaps(bool p_enable) { + shadow_atlas_quadrant_subdiv[p_quadrant]=p_subdiv; + static const int subdiv[SHADOW_ATLAS_QUADRANT_SUBDIV_MAX]={0,1,4,16,64,256,1024}; - //render_target_texture->set_flags(p_enable?int(Texture::FLAG_FILTER):int(0)); - render_target_gen_mipmaps=p_enable; + VS::get_singleton()->viewport_set_shadow_atlas_quadrant_subdivision(viewport,p_quadrant,subdiv[p_subdiv]); } +Viewport::ShadowAtlasQuadrantSubdiv Viewport::get_shadow_atlas_quadrant_subdiv(int p_quadrant) const{ + + ERR_FAIL_INDEX_V(p_quadrant,4,SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED); + return shadow_atlas_quadrant_subdiv[p_quadrant]; +} + -bool Viewport::get_render_target_gen_mipmaps() const{ +void Viewport::clear() { - //return (render_target_texture->get_flags()&Texture::FLAG_FILTER)!=0; - return render_target_gen_mipmaps; + //clear=true; +// VisualServer::get_singleton()->viewport_clear(viewport); } Matrix32 Viewport::_get_input_pre_xform() const { Matrix32 pre_xf; - if (render_target) { - if (to_screen_rect!=Rect2()) { - pre_xf.elements[2]=-to_screen_rect.pos; - pre_xf.scale(rect.size/to_screen_rect.size); - } - } else { + if (to_screen_rect!=Rect2()) { - pre_xf.elements[2]=-rect.pos; + pre_xf.elements[2]=-to_screen_rect.pos; + pre_xf.scale(size/to_screen_rect.size); } return pre_xf; @@ -1356,9 +1340,9 @@ Matrix32 Viewport::_get_input_pre_xform() const { Vector2 Viewport::_get_window_offset() const { - if (parent_control) { - return (parent_control->get_viewport()->get_final_transform() * parent_control->get_global_transform_with_canvas()).get_origin(); - } +// if (parent_control) { +// return (parent_control->get_viewport()->get_final_transform() * parent_control->get_global_transform_with_canvas()).get_origin(); +// } return Vector2(); } @@ -1454,10 +1438,8 @@ void Viewport::_vp_input(const InputEvent& p_ev) { } #endif - if (parent_control && !parent_control->is_visible()) - return; - if (render_target && to_screen_rect==Rect2()) + if (to_screen_rect==Rect2()) return; //if render target, can't get input events //this one handles system input, p_ev are in system coordinates @@ -1480,10 +1462,10 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) { } #endif - if (parent_control && !parent_control->is_visible()) - return; +// if (parent_control && !parent_control->is_visible()) +// return; - if (render_target && to_screen_rect==Rect2()) + if (to_screen_rect==Rect2()) return; //if render target, can't get input events //this one handles system input, p_ev are in system coordinates @@ -2521,17 +2503,18 @@ bool Viewport::is_using_own_world() const { return own_world.is_valid(); } -void Viewport::set_render_target_to_screen_rect(const Rect2& p_rect) { +void Viewport::set_attach_to_screen_rect(const Rect2& p_rect) { + VS::get_singleton()->viewport_attach_to_screen(viewport,p_rect); to_screen_rect=p_rect; - VisualServer::get_singleton()->viewport_set_render_target_to_screen_rect(viewport,to_screen_rect); } -Rect2 Viewport::get_render_target_to_screen_rect() const{ +Rect2 Viewport::get_attach_to_screen_rect() const{ return to_screen_rect; } + void Viewport::set_physics_object_picking(bool p_enable) { physics_object_picking=p_enable; @@ -2553,7 +2536,7 @@ Vector2 Viewport::get_camera_coords(const Vector2 &p_viewport_coords) const { Vector2 Viewport::get_camera_rect_size() const { - return last_vp_rect.size; + return size; } @@ -2577,6 +2560,16 @@ bool Viewport::is_input_disabled() const { return disable_input; } +void Viewport::set_disable_3d(bool p_disable) { + disable_3d=p_disable; + VS::get_singleton()->viewport_set_disable_3d(viewport,p_disable); +} + +bool Viewport::is_3d_disabled() const { + + return disable_3d; +} + Variant Viewport::gui_get_drag_data() const { return gui.drag_data; } @@ -2587,19 +2580,58 @@ Control *Viewport::get_modal_stack_top() const { String Viewport::get_configuration_warning() const { - if (get_parent() && !get_parent()->cast_to<Control>() && !render_target) { + /*if (get_parent() && !get_parent()->cast_to<Control>() && !render_target) { return TTR("This viewport is not set as render target. If you intend for it to display its contents directly to the screen, make it a child of a Control so it can obtain a size. Otherwise, make it a RenderTarget and assign its internal texture to some node for display."); - } + }*/ return String(); } +void Viewport::gui_reset_canvas_sort_index() { + gui.canvas_sort_index=0; +} +int Viewport::gui_get_canvas_sort_index() { + + return gui.canvas_sort_index++; +} + +void Viewport::set_msaa(MSAA p_msaa) { + + ERR_FAIL_INDEX(p_msaa,5); + if (msaa==p_msaa) + return; + msaa=p_msaa; + VS::get_singleton()->viewport_set_msaa(viewport,VS::ViewportMSAA(p_msaa)); +} + +Viewport::MSAA Viewport::get_msaa() const { + + return msaa; +} + +void Viewport::set_hdr(bool p_hdr) { + + if (hdr==p_hdr) + return; + + hdr=p_hdr; + VS::get_singleton()->viewport_set_hdr(viewport,p_hdr); + +} + +bool Viewport::get_hdr() const{ + + return hdr; +} + + + void Viewport::_bind_methods() { - ObjectTypeDB::bind_method(_MD("set_rect","rect"), &Viewport::set_rect); - ObjectTypeDB::bind_method(_MD("get_rect"), &Viewport::get_rect); + ObjectTypeDB::bind_method(_MD("set_size","size"), &Viewport::set_size); + ObjectTypeDB::bind_method(_MD("get_size"), &Viewport::get_size); ObjectTypeDB::bind_method(_MD("set_world_2d","world_2d:World2D"), &Viewport::set_world_2d); ObjectTypeDB::bind_method(_MD("get_world_2d:World2D"), &Viewport::get_world_2d); ObjectTypeDB::bind_method(_MD("find_world_2d:World2D"), &Viewport::find_world_2d); @@ -2633,27 +2665,24 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("queue_screen_capture"), &Viewport::queue_screen_capture); ObjectTypeDB::bind_method(_MD("get_screen_capture"), &Viewport::get_screen_capture); - ObjectTypeDB::bind_method(_MD("set_as_render_target","enable"), &Viewport::set_as_render_target); - ObjectTypeDB::bind_method(_MD("is_set_as_render_target"), &Viewport::is_set_as_render_target); - - ObjectTypeDB::bind_method(_MD("set_render_target_vflip","enable"), &Viewport::set_render_target_vflip); - ObjectTypeDB::bind_method(_MD("get_render_target_vflip"), &Viewport::get_render_target_vflip); - ObjectTypeDB::bind_method(_MD("set_render_target_clear_on_new_frame","enable"), &Viewport::set_render_target_clear_on_new_frame); - ObjectTypeDB::bind_method(_MD("get_render_target_clear_on_new_frame"), &Viewport::get_render_target_clear_on_new_frame); + ObjectTypeDB::bind_method(_MD("set_vflip","enable"), &Viewport::set_vflip); + ObjectTypeDB::bind_method(_MD("get_vflip"), &Viewport::get_vflip); - ObjectTypeDB::bind_method(_MD("render_target_clear"), &Viewport::render_target_clear); + ObjectTypeDB::bind_method(_MD("set_clear_on_new_frame","enable"), &Viewport::set_clear_on_new_frame); + ObjectTypeDB::bind_method(_MD("get_clear_on_new_frame"), &Viewport::get_clear_on_new_frame); - ObjectTypeDB::bind_method(_MD("set_render_target_filter","enable"), &Viewport::set_render_target_filter); - ObjectTypeDB::bind_method(_MD("get_render_target_filter"), &Viewport::get_render_target_filter); + ObjectTypeDB::bind_method(_MD("clear"), &Viewport::clear); + ObjectTypeDB::bind_method(_MD("set_update_mode","mode"), &Viewport::set_update_mode); + ObjectTypeDB::bind_method(_MD("get_update_mode"), &Viewport::get_update_mode); - ObjectTypeDB::bind_method(_MD("set_render_target_gen_mipmaps","enable"), &Viewport::set_render_target_gen_mipmaps); - ObjectTypeDB::bind_method(_MD("get_render_target_gen_mipmaps"), &Viewport::get_render_target_gen_mipmaps); + ObjectTypeDB::bind_method(_MD("set_msaa","msaa"), &Viewport::set_msaa); + ObjectTypeDB::bind_method(_MD("get_msaa"), &Viewport::get_msaa); - ObjectTypeDB::bind_method(_MD("set_render_target_update_mode","mode"), &Viewport::set_render_target_update_mode); - ObjectTypeDB::bind_method(_MD("get_render_target_update_mode"), &Viewport::get_render_target_update_mode); + ObjectTypeDB::bind_method(_MD("set_hdr","enable"), &Viewport::set_hdr); + ObjectTypeDB::bind_method(_MD("get_hdr"), &Viewport::get_hdr); - ObjectTypeDB::bind_method(_MD("get_render_target_texture:RenderTargetTexture"), &Viewport::get_render_target_texture); + ObjectTypeDB::bind_method(_MD("get_texture:ViewportTexture"), &Viewport::get_texture); ObjectTypeDB::bind_method(_MD("set_physics_object_picking","enable"), &Viewport::set_physics_object_picking); ObjectTypeDB::bind_method(_MD("get_physics_object_picking"), &Viewport::get_physics_object_picking); @@ -2674,7 +2703,7 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_as_audio_listener_2d","enable"), &Viewport::set_as_audio_listener_2d); ObjectTypeDB::bind_method(_MD("is_audio_listener_2d","enable"), &Viewport::is_audio_listener_2d); - ObjectTypeDB::bind_method(_MD("set_render_target_to_screen_rect","rect"), &Viewport::set_render_target_to_screen_rect); + ObjectTypeDB::bind_method(_MD("set_attach_to_screen_rect","rect"), &Viewport::set_attach_to_screen_rect); ObjectTypeDB::bind_method(_MD("get_mouse_pos"), &Viewport::get_mouse_pos); ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"), &Viewport::warp_mouse); @@ -2685,31 +2714,60 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_disable_input","disable"), &Viewport::set_disable_input); ObjectTypeDB::bind_method(_MD("is_input_disabled"), &Viewport::is_input_disabled); + ObjectTypeDB::bind_method(_MD("set_disable_3d","disable"), &Viewport::set_disable_3d); + ObjectTypeDB::bind_method(_MD("is_3d_disabled"), &Viewport::is_3d_disabled); + ObjectTypeDB::bind_method(_MD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip); ObjectTypeDB::bind_method(_MD("_gui_remove_focus"), &Viewport::_gui_remove_focus); - ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"), _SCS("set_rect"), _SCS("get_rect") ); + ObjectTypeDB::bind_method(_MD("set_shadow_atlas_size","size"), &Viewport::set_shadow_atlas_size); + ObjectTypeDB::bind_method(_MD("get_shadow_atlas_size"), &Viewport::get_shadow_atlas_size); + + ObjectTypeDB::bind_method(_MD("set_shadow_atlas_quadrant_subdiv","quadrant","subdiv"), &Viewport::set_shadow_atlas_quadrant_subdiv); + ObjectTypeDB::bind_method(_MD("get_shadow_atlas_quadrant_subdiv","quadrant"), &Viewport::get_shadow_atlas_quadrant_subdiv); + + ADD_PROPERTY( PropertyInfo(Variant::RECT2,"size"), _SCS("set_size"), _SCS("get_size") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"own_world"), _SCS("set_use_own_world"), _SCS("is_using_own_world") ); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world",PROPERTY_HINT_RESOURCE_TYPE,"World"), _SCS("set_world"), _SCS("get_world") ); // ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world_2d",PROPERTY_HINT_RESOURCE_TYPE,"World2D"), _SCS("set_world_2d"), _SCS("get_world_2d") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transparent_bg"), _SCS("set_transparent_background"), _SCS("has_transparent_background") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/enabled"), _SCS("set_as_render_target"), _SCS("is_set_as_render_target") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/v_flip"), _SCS("set_render_target_vflip"), _SCS("get_render_target_vflip") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/clear_on_new_frame"), _SCS("set_render_target_clear_on_new_frame"), _SCS("get_render_target_clear_on_new_frame") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/filter"), _SCS("set_render_target_filter"), _SCS("get_render_target_filter") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/gen_mipmaps"), _SCS("set_render_target_gen_mipmaps"), _SCS("get_render_target_gen_mipmaps") ); - ADD_PROPERTY( PropertyInfo(Variant::INT,"render_target/update_mode",PROPERTY_HINT_ENUM,"Disabled,Once,When Visible,Always"), _SCS("set_render_target_update_mode"), _SCS("get_render_target_update_mode") ); + ADD_PROPERTY( PropertyInfo(Variant::INT,"msaa",PROPERTY_HINT_ENUM,"Disabled,2x,4x,8x,16x"), _SCS("set_msaa"), _SCS("get_msaa") ); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"hdr"), _SCS("set_hdr"), _SCS("get_hdr") ); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/v_flip"), _SCS("set_vflip"), _SCS("get_vflip") ); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/clear_on_new_frame"), _SCS("set_clear_on_new_frame"), _SCS("get_clear_on_new_frame") ); + ADD_PROPERTY( PropertyInfo(Variant::INT,"render_target/update_mode",PROPERTY_HINT_ENUM,"Disabled,Once,When Visible,Always"), _SCS("set_update_mode"), _SCS("get_update_mode") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener/enable_2d"), _SCS("set_as_audio_listener_2d"), _SCS("is_audio_listener_2d") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener/enable_3d"), _SCS("set_as_audio_listener"), _SCS("is_audio_listener") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"physics/object_picking"), _SCS("set_physics_object_picking"), _SCS("get_physics_object_picking") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gui/disable_input"), _SCS("set_disable_input"), _SCS("is_input_disabled") ); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"3d/disable_3d"), _SCS("set_disable_3d"), _SCS("is_3d_disabled") ); + ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow_atlas/size"), _SCS("set_shadow_atlas_size"), _SCS("get_shadow_atlas_size") ); + ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas/quad_0",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), _SCS("set_shadow_atlas_quadrant_subdiv"), _SCS("get_shadow_atlas_quadrant_subdiv"),0 ); + ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas/quad_1",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), _SCS("set_shadow_atlas_quadrant_subdiv"), _SCS("get_shadow_atlas_quadrant_subdiv"),1 ); + ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas/quad_2",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), _SCS("set_shadow_atlas_quadrant_subdiv"), _SCS("get_shadow_atlas_quadrant_subdiv"),2 ); + ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas/quad_3",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), _SCS("set_shadow_atlas_quadrant_subdiv"), _SCS("get_shadow_atlas_quadrant_subdiv"),3 ); ADD_SIGNAL(MethodInfo("size_changed")); - BIND_CONSTANT( RENDER_TARGET_UPDATE_DISABLED ); - BIND_CONSTANT( RENDER_TARGET_UPDATE_ONCE ); - BIND_CONSTANT( RENDER_TARGET_UPDATE_WHEN_VISIBLE ); - BIND_CONSTANT( RENDER_TARGET_UPDATE_ALWAYS ); + BIND_CONSTANT( UPDATE_DISABLED ); + BIND_CONSTANT( UPDATE_ONCE ); + BIND_CONSTANT( UPDATE_WHEN_VISIBLE ); + BIND_CONSTANT( UPDATE_ALWAYS ); + + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_1 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_4 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_16 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_64 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_256 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_1024 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_MAX ); + + BIND_CONSTANT( MSAA_DISABLED ); + BIND_CONSTANT( MSAA_2X ); + BIND_CONSTANT( MSAA_4X ); + BIND_CONSTANT( MSAA_8X ); + BIND_CONSTANT( MSAA_16X ); } @@ -2723,6 +2781,7 @@ Viewport::Viewport() { world_2d = Ref<World2D>( memnew( World2D )); viewport = VisualServer::get_singleton()->viewport_create(); + texture_rid=VisualServer::get_singleton()->viewport_get_texture(viewport); internal_listener = SpatialSoundServer::get_singleton()->listener_create(); audio_listener=false; internal_listener_2d = SpatialSound2DServer::get_singleton()->listener_create(); @@ -2734,19 +2793,28 @@ Viewport::Viewport() { size_override=false; size_override_stretch=false; size_override_size=Size2(1,1); - render_target_gen_mipmaps=false; - render_target=false; - render_target_vflip=false; - render_target_clear_on_new_frame=true; - //render_target_clear=true; - render_target_update_mode=RENDER_TARGET_UPDATE_WHEN_VISIBLE; - render_target_texture = Ref<RenderTargetTexture>( memnew( RenderTargetTexture(this) ) ); + gen_mipmaps=false; + + vflip=false; + clear_on_new_frame=true; + //clear=true; + update_mode=UPDATE_WHEN_VISIBLE; + texture = Ref<ViewportTexture>( memnew( ViewportTexture(this) ) ); physics_object_picking=false; physics_object_capture=0; physics_object_over=0; physics_last_mousepos=Vector2(1e20,1e20); + shadow_atlas_size=0; + for(int i=0;i<4;i++) { + shadow_atlas_quadrant_subdiv[i]=SHADOW_ATLAS_QUADRANT_SUBDIV_MAX; + } + set_shadow_atlas_quadrant_subdiv(0,SHADOW_ATLAS_QUADRANT_SUBDIV_4); + set_shadow_atlas_quadrant_subdiv(1,SHADOW_ATLAS_QUADRANT_SUBDIV_4); + set_shadow_atlas_quadrant_subdiv(2,SHADOW_ATLAS_QUADRANT_SUBDIV_16); + set_shadow_atlas_quadrant_subdiv(3,SHADOW_ATLAS_QUADRANT_SUBDIV_64); + String id=itos(get_instance_ID()); input_group = "_vp_input"+id; @@ -2755,6 +2823,7 @@ Viewport::Viewport() { unhandled_key_input_group = "_vp_unhandled_key_input"+id; disable_input=false; + disable_3d=false; //window tooltip gui.tooltip_timer = -1; @@ -2766,9 +2835,11 @@ Viewport::Viewport() { gui.tooltip_label=NULL; gui.drag_preview=NULL; gui.drag_attempted=false; + gui.canvas_sort_index=0; - parent_control=NULL; + msaa=MSAA_DISABLED; + hdr=false; } @@ -2779,8 +2850,8 @@ Viewport::~Viewport() { VisualServer::get_singleton()->free( viewport ); SpatialSoundServer::get_singleton()->free(internal_listener); SpatialSound2DServer::get_singleton()->free(internal_listener_2d); - if (render_target_texture.is_valid()) - render_target_texture->vp=NULL; //so if used, will crash + if (texture.is_valid()) + texture->vp=NULL; //so if used, will crash } |