summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-12-04 16:54:17 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-12-04 16:54:17 -0300
commit5868754b013fa0579f0781bd8c1c5ba0fc9e784d (patch)
tree0e00ff972e3b1d65b8690d90ad63910e0bd308ea /scene
parentd438ac0aeda8509e5961296a5950c2755ba8a966 (diff)
Added a higher level wrapper for proxy texture
Diffstat (limited to 'scene')
-rw-r--r--scene/register_scene_types.cpp1
-rw-r--r--scene/resources/texture.cpp69
-rw-r--r--scene/resources/texture.h27
3 files changed, 97 insertions, 0 deletions
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index c99bc3c9ef..d6557f508e 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -529,6 +529,7 @@ void register_scene_types() {
ClassDB::register_class<LargeTexture>();
ClassDB::register_class<CurveTexture>();
ClassDB::register_class<GradientTexture>();
+ ClassDB::register_class<ProxyTexture>();
ClassDB::register_class<CubeMap>();
ClassDB::register_class<Animation>();
ClassDB::register_virtual_class<Font>();
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 162edd0d1c..987d6c5f6a 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -1601,3 +1601,72 @@ int GradientTexture::get_width() const {
Ref<Image> GradientTexture::get_data() const {
return VisualServer::get_singleton()->texture_get_data(texture);
}
+
+//////////////////////////////////////
+
+void ProxyTexture::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_base", "base"), &ProxyTexture::set_base);
+ ClassDB::bind_method(D_METHOD("get_base"), &ProxyTexture::get_base);
+
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "base", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_base", "get_base");
+}
+
+void ProxyTexture::set_base(const Ref<Texture> &p_texture) {
+
+ 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());
+ }
+}
+
+Ref<Texture> ProxyTexture::get_base() const {
+
+ return base;
+}
+
+int ProxyTexture::get_width() const {
+
+ if (base.is_valid())
+ return base->get_width();
+ return 1;
+}
+int ProxyTexture::get_height() const {
+
+ if (base.is_valid())
+ return base->get_height();
+ return 1;
+}
+RID ProxyTexture::get_rid() const {
+
+ return proxy;
+}
+
+bool ProxyTexture::has_alpha() const {
+
+ if (base.is_valid())
+ return base->has_alpha();
+ return false;
+}
+
+void ProxyTexture::set_flags(uint32_t p_flags) {
+}
+
+uint32_t ProxyTexture::get_flags() const {
+
+ if (base.is_valid())
+ return base->get_flags();
+ return 0;
+}
+
+ProxyTexture::ProxyTexture() {
+
+ proxy = VS::get_singleton()->texture_create();
+}
+
+ProxyTexture::~ProxyTexture() {
+
+ VS::get_singleton()->free(proxy);
+}
diff --git a/scene/resources/texture.h b/scene/resources/texture.h
index ee54156647..76c0195ef9 100644
--- a/scene/resources/texture.h
+++ b/scene/resources/texture.h
@@ -493,4 +493,31 @@ public:
virtual ~GradientTexture();
};
+class ProxyTexture : public Texture {
+ GDCLASS(ProxyTexture, Texture)
+
+private:
+ RID proxy;
+ Ref<Texture> base;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_base(const Ref<Texture> &p_texture);
+ Ref<Texture> get_base() const;
+
+ virtual int get_width() const;
+ virtual int get_height() const;
+ virtual RID get_rid() const;
+
+ virtual bool has_alpha() const;
+
+ virtual void set_flags(uint32_t p_flags);
+ virtual uint32_t get_flags() const;
+
+ ProxyTexture();
+ ~ProxyTexture();
+};
+
#endif