summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-10-10 18:31:01 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-10-10 18:31:01 -0300
commit1527cf8c0d17891dd0ebf99d484f83daa46eba3c (patch)
treea9a0fc5a00f8f57a973f2861d051b76f99642114 /scene
parent850eaf7ed796d2f2d9a35c6bc4ba9a4e69f5ca1d (diff)
2D Shaders are working again using the new syntax, though all is buggy in general
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/canvas_item.cpp14
-rw-r--r--scene/2d/canvas_item.h4
-rw-r--r--scene/gui/color_picker.cpp37
-rw-r--r--scene/gui/color_picker.h2
-rw-r--r--scene/resources/material.h3
5 files changed, 9 insertions, 51 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index 07ee1ff753..0696261401 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -55,7 +55,7 @@ bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value)
}
}
if (pr) {
- VisualServer::get_singleton()->material_set_param(material,pr,p_value);
+ VisualServer::get_singleton()->material_set_param(_get_material(),pr,p_value);
return true;
}
}
@@ -78,7 +78,7 @@ bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const {
StringName pr = shader->remap_param(p_name);
if (pr) {
- r_ret=VisualServer::get_singleton()->material_get_param(material,pr);
+ r_ret=VisualServer::get_singleton()->material_get_param(_get_material(),pr);
return true;
}
}
@@ -111,7 +111,7 @@ void CanvasItemMaterial::set_shader(const Ref<Shader>& p_shader) {
if (shader.is_valid())
rid=shader->get_rid();
- VS::get_singleton()->material_set_shader(material,rid);
+ VS::get_singleton()->material_set_shader(_get_material(),rid);
_change_notify(); //properties for shader exposed
emit_changed();
}
@@ -123,18 +123,14 @@ Ref<Shader> CanvasItemMaterial::get_shader() const{
void CanvasItemMaterial::set_shader_param(const StringName& p_param,const Variant& p_value){
- VS::get_singleton()->material_set_param(material,p_param,p_value);
+ VS::get_singleton()->material_set_param(_get_material(),p_param,p_value);
}
Variant CanvasItemMaterial::get_shader_param(const StringName& p_param) const{
- return VS::get_singleton()->material_get_param(material,p_param);
+ return VS::get_singleton()->material_get_param(_get_material(),p_param);
}
-RID CanvasItemMaterial::get_rid() const {
-
- return material;
-}
void CanvasItemMaterial::_bind_methods() {
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index b65c1a60b4..9cc7982aa3 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -41,10 +41,9 @@ class Font;
class StyleBox;
-class CanvasItemMaterial : public Material{
+class CanvasItemMaterial : public Material {
OBJ_TYPE(CanvasItemMaterial,Material);
- RID material;
Ref<Shader> shader;
public:
/*enum ShadingMode {
@@ -70,7 +69,6 @@ public:
void set_shader_param(const StringName& p_param,const Variant& p_value);
Variant get_shader_param(const StringName& p_param) const;
- virtual RID get_rid() const;
CanvasItemMaterial();
~CanvasItemMaterial();
};
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 27bdb581e1..3d9c07ac86 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -34,31 +34,12 @@
#include "os/input.h"
#include "os/keyboard.h"
-void update_material(Ref<CanvasItemMaterial>mat,const Color& p_color,float h,float s,float v) {
- if (!mat.is_valid())
- return;
- Ref<Shader> sdr = mat->get_shader();
- if (!sdr.is_valid())
- return;
-
- mat->set_shader_param("R",p_color.r);
- mat->set_shader_param("G",p_color.g);
- mat->set_shader_param("B",p_color.b);
- mat->set_shader_param("H",h);
- mat->set_shader_param("S",s);
- mat->set_shader_param("V",v);
- mat->set_shader_param("A",p_color.a);
-}
void ColorPicker::_notification(int p_what) {
switch(p_what) {
case NOTIFICATION_THEME_CHANGED: {
- uv_material->set_shader(get_shader("uv_editor"));
- w_material->set_shader(get_shader("w_editor"));
- update_material(uv_material,color,h,s,v);
- update_material(w_material,color,h,s,v);
uv_edit->set_texture(get_icon("color_main"));
w_edit->set_texture(get_icon("color_hue"));
sample->set_texture(get_icon("color_sample"));
@@ -68,8 +49,6 @@ void ColorPicker::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
btn_pick->set_icon(get_icon("screen_picker", "ColorPicker"));
- update_material(uv_material, color,h,s,v);
- update_material(w_material, color,h,s,v);
uv_edit->get_child(0)->cast_to<Control>()->update();
w_edit->get_child(0)->cast_to<Control>()->update();
@@ -113,8 +92,6 @@ void ColorPicker::set_color(const Color& p_color) {
if (!is_inside_tree())
return;
- update_material(uv_material, color,h,s,v);
- update_material(w_material, color,h,s,v);
uv_edit->get_child(0)->cast_to<Control>()->update();
w_edit->get_child(0)->cast_to<Control>()->update();
@@ -509,7 +486,6 @@ ColorPicker::ColorPicker() :
uv_edit->add_child(c);
c->set_area_as_parent_rect();
c->set_stop_mouse(false);
- c->set_material(memnew ( CanvasItemMaterial ));
Vector<Variant> args=Vector<Variant>();
args.push_back(0);
args.push_back(c);
@@ -525,7 +501,6 @@ ColorPicker::ColorPicker() :
w_edit->add_child(c);
c->set_area_as_parent_rect();
c->set_stop_mouse(false);
- c->set_material(memnew ( CanvasItemMaterial ));
args.clear();
args.push_back(1);
args.push_back(c);
@@ -593,18 +568,6 @@ ColorPicker::ColorPicker() :
//_update_color();
updating=false;
- uv_material.instance();
- Ref<Shader> s_uv = get_shader("uv_editor");
- uv_material->set_shader(s_uv);
-
- w_material.instance();
-
- Ref<Shader> s_w = get_shader("w_editor");
- w_material->set_shader(s_w);
-
- uv_edit->set_material(uv_material);
- w_edit->set_material(w_material);
-
set_color(Color(1,1,1));
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index 5e2cc57274..b742454361 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -57,8 +57,6 @@ private:
List<Color> presets;
ToolButton *btn_pick;
CheckButton *btn_mode;
- Ref<CanvasItemMaterial> uv_material;
- Ref<CanvasItemMaterial> w_material;
HSlider *scroll[4];
SpinBox *values[4];
Label *labels[4];
diff --git a/scene/resources/material.h b/scene/resources/material.h
index 87afa60ce9..1acc031641 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -46,6 +46,9 @@ class Material : public Resource {
OBJ_SAVE_TYPE( Material );
RID material;
+protected:
+
+ _FORCE_INLINE_ RID _get_material() const { return material; }
public:
virtual RID get_rid() const;