From 1b4281b895f3046ea972256182b18696a25f8316 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 24 Jun 2019 16:13:06 -0300 Subject: basic 2D engine is more or less working with Vulkan, including editor. Still a lot to do --- scene/gui/viewport_container.cpp | 4 ++-- scene/main/viewport.cpp | 17 +++++++++++++++-- scene/main/viewport.h | 3 ++- scene/resources/texture.cpp | 32 ++++++++++++++++++++++++++------ scene/resources/texture.h | 4 +++- 5 files changed, 48 insertions(+), 12 deletions(-) (limited to 'scene') diff --git a/scene/gui/viewport_container.cpp b/scene/gui/viewport_container.cpp index 4565b4b538..a76f2924d3 100644 --- a/scene/gui/viewport_container.cpp +++ b/scene/gui/viewport_container.cpp @@ -135,9 +135,9 @@ void ViewportContainer::_notification(int p_what) { continue; if (stretch) - draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size() * Size2(1, -1))); + draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size())); else - draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size() * Size2(1, -1))); + draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size())); } } } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 412632acfc..0e658f7edd 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -74,7 +74,13 @@ void ViewportTexture::setup_local_to_scene() { vp->viewport_textures.insert(this); - VS::get_singleton()->texture_set_proxy(proxy, vp->texture_rid); + if (proxy_ph.is_valid()) { + VS::get_singleton()->texture_proxy_update(proxy, vp->texture_rid); + VS::get_singleton()->free(proxy_ph); + } else { + ERR_FAIL_COND(proxy.is_valid()); //should be invalid + proxy = VS::get_singleton()->texture_proxy_create(vp->texture_rid); + } } void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) { @@ -112,6 +118,10 @@ Size2 ViewportTexture::get_size() const { RID ViewportTexture::get_rid() const { //ERR_FAIL_COND_V_MSG(!vp, RID(), "Viewport Texture must be set to use it."); + if (proxy.is_null()) { + proxy_ph = VS::get_singleton()->texture_2d_placeholder_create(); + proxy = VS::get_singleton()->texture_proxy_create(proxy_ph); + } return proxy; } @@ -146,6 +156,9 @@ ViewportTexture::~ViewportTexture() { vp->viewport_textures.erase(this); } + if (proxy_ph.is_valid()) { + VS::get_singleton()->free(proxy_ph); + } VS::get_singleton()->free(proxy); } @@ -3309,7 +3322,7 @@ Viewport::Viewport() { default_texture.instance(); default_texture->vp = const_cast(this); viewport_textures.insert(default_texture.ptr()); - VS::get_singleton()->texture_set_proxy(default_texture->proxy, texture_rid); + default_texture->proxy = VS::get_singleton()->texture_proxy_create(texture_rid); //internal_listener = SpatialSoundServer::get_singleton()->listener_create(); audio_listener = false; diff --git a/scene/main/viewport.h b/scene/main/viewport.h index af7c8f1356..38597e2e47 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -58,7 +58,8 @@ class ViewportTexture : public Texture2D { friend class Viewport; Viewport *vp; - RID proxy; + mutable RID proxy_ph; + mutable RID proxy; protected: static void _bind_methods(); diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 4f41bce723..c752ee0876 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -193,7 +193,7 @@ void ImageTexture::update(const Ref &p_image, bool p_immediate) { ERR_FAIL_COND(texture.is_null()); ERR_FAIL_COND(p_image->get_width() != w || p_image->get_height() != h); ERR_FAIL_COND(p_image->get_format() != format); - ERR_FAIL_COND(mipmaps != p_image->get_format()); + ERR_FAIL_COND(mipmaps != p_image->has_mipmaps()); if (p_immediate) { VisualServer::get_singleton()->texture_2d_update_immediate(texture, p_image); @@ -1584,11 +1584,18 @@ void ProxyTexture::_bind_methods() { void ProxyTexture::set_base(const Ref &p_texture) { ERR_FAIL_COND(p_texture == this); + base = p_texture; if (base.is_valid()) { - VS::get_singleton()->texture_set_proxy(proxy, base->get_rid()); - } else { - VS::get_singleton()->texture_set_proxy(proxy, RID()); + if (proxy_ph.is_valid()) { + VS::get_singleton()->texture_proxy_update(proxy, base->get_rid()); + VS::get_singleton()->free(proxy_ph); + proxy_ph = RID(); + } else if (proxy.is_valid()) { + VS::get_singleton()->texture_proxy_update(proxy, base->get_rid()); + } else { + proxy = VS::get_singleton()->texture_proxy_create(base->get_rid()); + } } } @@ -1611,6 +1618,10 @@ int ProxyTexture::get_height() const { } RID ProxyTexture::get_rid() const { + if (proxy.is_null()) { + proxy_ph = VS::get_singleton()->texture_2d_placeholder_create(); + proxy = VS::get_singleton()->texture_proxy_create(proxy_ph); + } return proxy; } @@ -1628,7 +1639,12 @@ ProxyTexture::ProxyTexture() { ProxyTexture::~ProxyTexture() { - //VS::get_singleton()->free(proxy); + if (proxy_ph.is_valid()) { + VS::get_singleton()->free(proxy_ph); + } + if (proxy.is_valid()) { + VS::get_singleton()->free(proxy); + } } ////////////////////////////////////////////// @@ -1673,7 +1689,7 @@ void AnimatedTexture::_update_proxy() { } if (frames[current_frame].texture.is_valid()) { - VisualServer::get_singleton()->texture_set_proxy(proxy, frames[current_frame].texture->get_rid()); + VisualServer::get_singleton()->texture_proxy_update(proxy, frames[current_frame].texture->get_rid()); } } @@ -1822,6 +1838,9 @@ void AnimatedTexture::_bind_methods() { AnimatedTexture::AnimatedTexture() { //proxy = VS::get_singleton()->texture_create(); + proxy_ph = VS::get_singleton()->texture_2d_placeholder_create(); + proxy = VS::get_singleton()->texture_proxy_create(proxy_ph); + VisualServer::get_singleton()->texture_set_force_redraw_if_visible(proxy, true); time = 0; frame_count = 1; @@ -1839,6 +1858,7 @@ AnimatedTexture::AnimatedTexture() { AnimatedTexture::~AnimatedTexture() { VS::get_singleton()->free(proxy); + VS::get_singleton()->free(proxy_ph); if (rw_lock) { memdelete(rw_lock); } diff --git a/scene/resources/texture.h b/scene/resources/texture.h index b255a3ebb2..d3650e83ce 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -509,7 +509,8 @@ class ProxyTexture : public Texture2D { GDCLASS(ProxyTexture, Texture2D); private: - RID proxy; + mutable RID proxy_ph; + mutable RID proxy; Ref base; protected: @@ -540,6 +541,7 @@ private: MAX_FRAMES = 256 }; + RID proxy_ph; RID proxy; struct Frame { -- cgit v1.2.3