summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/classes/Physics2DDirectSpaceState.xml67
-rw-r--r--doc/classes/PhysicsDirectSpaceState.xml48
-rw-r--r--drivers/gles3/rasterizer_canvas_gles3.cpp17
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp14
-rw-r--r--editor/editor_data.cpp9
-rw-r--r--editor/editor_data.h1
-rw-r--r--editor/filesystem_dock.cpp55
-rw-r--r--editor/filesystem_dock.h1
-rw-r--r--scene/register_scene_types.cpp16
-rw-r--r--scene/resources/shader.cpp77
-rw-r--r--scene/resources/shader.h17
11 files changed, 255 insertions, 67 deletions
diff --git a/doc/classes/Physics2DDirectSpaceState.xml b/doc/classes/Physics2DDirectSpaceState.xml
index f63b8f17bc..2e2d8e95f9 100644
--- a/doc/classes/Physics2DDirectSpaceState.xml
+++ b/doc/classes/Physics2DDirectSpaceState.xml
@@ -17,8 +17,8 @@
<argument index="0" name="shape" type="Physics2DShapeQueryParameters">
</argument>
<description>
- Check whether the shape can travel to a point. If it can, the method will return an array with two floats: The first is the distance the shape can move in that direction without colliding, and the second is the distance at which it will collide.
- If the shape can not move, the array will be empty.
+ Checks how far the shape can travel toward a point. Note that both the shape and the motion are supplied through a [Physics2DShapeQueryParameters] object. The method will return an array with two floats between 0 and 1, both representing a fraction of [code]motion[/code]. The first is how far the shape can move without triggering a collision, and the second is the point at which a collision will occur. If no collision is detected, the returned array will be [1, 1].
+ If the shape can not move, the array will be empty ([code]dir.empty()==true[/code]).
</description>
</method>
<method name="collide_shape">
@@ -29,7 +29,7 @@
<argument index="1" name="max_results" type="int" default="32">
</argument>
<description>
- Check the intersections of a shape, given through a [Physics2DShapeQueryParameters] object, against the space. The resulting array contains a list of points where the shape intersects another. Like with [method intersect_shape], the number of returned results can be limited to save processing time.
+ Checks the intersections of a shape, given through a [Physics2DShapeQueryParameters] object, against the space. The resulting array contains a list of points where the shape intersects another. Like with [method intersect_shape], the number of returned results can be limited to save processing time.
</description>
</method>
<method name="get_rest_info">
@@ -38,16 +38,15 @@
<argument index="0" name="shape" type="Physics2DShapeQueryParameters">
</argument>
<description>
- Check the intersections of a shape, given through a [Physics2DShapeQueryParameters] object, against the space. If it collides with more than a shape, the nearest one is selected. The returned object is a dictionary containing the following fields:
- pointo: Place where the shapes intersect.
- normal: Normal of the object at the point where the shapes intersect.
- shape: Shape index within the object against which the shape intersected.
- metadata: Metadata of the shape against which the shape intersected. This metadata is different from [method Object.get_meta], and is set with [method Physics2DServer.shape_set_data].
- collider_id: Id of the object against which the shape intersected.
- collider: Object against which the shape intersected.
- rid: [RID] of the object against which the shape intersected.
- linear_velocity: The movement vector of the object the shape intersected, if it was a body. If it was an area, it is (0,0).
- If the shape did not intersect anything, then an empty dictionary (dir.empty()==true) is returned instead.
+ Checks the intersections of a shape, given through a [Physics2DShapeQueryParameters] object, against the space. If it collides with more than one shape, the nearest one is selected. Note that this method does not take into account the [code]motion[/code] property of the object. The returned object is a dictionary containing the following fields:
+ [code]collider_id[/code]: The colliding object's ID.
+ [code]linear_velocity[/code]: The colliding object's velocity [Vector2]. If the object is an [Area2D], the result is [code](0, 0)[/code].
+ [code]metadata[/code]: The intersecting shape's metadata. This metadata is different from [method Object.get_meta], and is set with [method Physics2DServer.shape_set_data].
+ [code]normal[/code]: The object's surface normal at the intersection point.
+ [code]point[/code]: The intersection point.
+ [code]rid[/code]: The intersecting object's [RID].
+ [code]shape[/code]: The shape index of the colliding shape.
+ If the shape did not intersect anything, then an empty dictionary ([code]dir.empty()==true[/code]) is returned instead.
</description>
</method>
<method name="intersect_point">
@@ -62,12 +61,12 @@
<argument index="3" name="collision_layer" type="int" default="2147483647">
</argument>
<description>
- Check whether a point is inside any shape. The shapes the point is inside of are returned in an array containing dictionaries with the following fields:
- shape: Shape index within the object the point is in.
- metadata: Metadata of the shape the point is in. This metadata is different from [method Object.get_meta], and is set with [method Physics2DServer.shape_set_data].
- collider_id: Id of the object the point is in.
- collider: Object the point is inside of.
- rid: [RID] of the object the point is in.
+ Checks whether a point is inside any shape. The shapes the point is inside of are returned in an array containing dictionaries with the following fields:
+ [code]collider[/code]: The colliding object.
+ [code]collider_id[/code]: The colliding object's ID.
+ [code]metadata[/code]: The intersecting shape's metadata. This metadata is different from [method Object.get_meta], and is set with [method Physics2DServer.shape_set_data].
+ [code]rid[/code]: The intersecting object's [RID].
+ [code]shape[/code]: The shape index of the colliding shape.
Additionally, the method can take an array of objects or [RID]s that are to be excluded from collisions, or a bitmask representing the physics layers to check in.
</description>
</method>
@@ -83,15 +82,15 @@
<argument index="3" name="collision_layer" type="int" default="2147483647">
</argument>
<description>
- Intersect a ray in a given space. The returned object is a dictionary with the following fields:
- position: Place where ray is stopped.
- normal: Normal of the object at the point where the ray was stopped.
- shape: Shape index within the object against which the ray was stopped.
- metadata: Metadata of the shape against which the ray was stopped. This metadata is different from [method Object.get_meta], and is set with [method Physics2DServer.shape_set_data].
- collider_id: Id of the object against which the ray was stopped.
- collider: Object against which the ray was stopped.
- rid: [RID] of the object against which the ray was stopped.
- If the ray did not intersect anything, then an empty dictionary (dir.empty()==true) is returned instead.
+ Intersects a ray in a given space. The returned object is a dictionary with the following fields:
+ [code]collider[/code]: The colliding object.
+ [code]collider_id[/code]: The colliding object's ID.
+ [code]metadata[/code]: The intersecting shape's metadata. This metadata is different from [method Object.get_meta], and is set with [method Physics2DServer.shape_set_data].
+ [code]normal[/code]: The object's surface normal at the intersection point.
+ [code]position[/code]: The intersection point.
+ [code]rid[/code]: The intersecting object's [RID].
+ [code]shape[/code]: The shape index of the colliding shape.
+ If the ray did not intersect anything, then an empty dictionary ([code]dir.empty()==true[/code]) is returned instead.
Additionally, the method can take an array of objects or [RID]s that are to be excluded from collisions, or a bitmask representing the physics layers to check in.
</description>
</method>
@@ -103,12 +102,12 @@
<argument index="1" name="max_results" type="int" default="32">
</argument>
<description>
- Check the intersections of a shape, given through a [Physics2DShapeQueryParameters] object, against the space. The intersected shapes are returned in an array containing dictionaries with the following fields:
- shape: Shape index within the object the shape intersected.
- metadata: Metadata of the shape intersected by the shape given through the [Physics2DShapeQueryParameters]. This metadata is different from [method Object.get_meta], and is set with [method Physics2DServer.shape_set_data].
- collider_id: Id of the object the shape intersected.
- collider: Object the shape intersected.
- rid: [RID] of the object the shape intersected.
+ Checks the intersections of a shape, given through a [Physics2DShapeQueryParameters] object, against the space. Note that this method does not take into account the [code]motion[/code] property of the object. The intersected shapes are returned in an array containing dictionaries with the following fields:
+ [code]collider[/code]: The colliding object.
+ [code]collider_id[/code]: The colliding object's ID.
+ [code]metadata[/code]: The intersecting shape's metadata. This metadata is different from [method Object.get_meta], and is set with [method Physics2DServer.shape_set_data].
+ [code]rid[/code]: The intersecting object's [RID].
+ [code]shape[/code]: The shape index of the colliding shape.
The number of intersections can be limited with the second parameter, to reduce the processing time.
</description>
</method>
diff --git a/doc/classes/PhysicsDirectSpaceState.xml b/doc/classes/PhysicsDirectSpaceState.xml
index 56acd34f0a..d93550eb47 100644
--- a/doc/classes/PhysicsDirectSpaceState.xml
+++ b/doc/classes/PhysicsDirectSpaceState.xml
@@ -19,8 +19,8 @@
<argument index="1" name="motion" type="Vector3">
</argument>
<description>
- Check whether the shape can travel to a point. If it can, the method will return an array with two floats between 0 and 1: The first is how far the shape can move toward the point without colliding, and the second is the distance at which it will collide. If no collision is detected, the returned array will be [1, 1].
- If the shape can not move, the array will be empty (dir.empty()==true).
+ Checks whether the shape can travel to a point. The method will return an array with two floats between 0 and 1, both representing a fraction of [code]motion[/code]. The first is how far the shape can move without triggering a collision, and the second is the point at which a collision will occur. If no collision is detected, the returned array will be [1, 1].
+ If the shape can not move, the array will be empty ([code]dir.empty()==true[/code]).
</description>
</method>
<method name="collide_shape">
@@ -31,7 +31,7 @@
<argument index="1" name="max_results" type="int" default="32">
</argument>
<description>
- Check the intersections of a shape, given through a [PhysicsShapeQueryParameters] object, against the space. The resulting array contains a list of points where the shape intersects another. Like with [method intersect_shape], the number of returned results can be limited to save processing time.
+ Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters] object, against the space. The resulting array contains a list of points where the shape intersects another. Like with [method intersect_shape], the number of returned results can be limited to save processing time.
</description>
</method>
<method name="get_rest_info">
@@ -40,14 +40,14 @@
<argument index="0" name="shape" type="PhysicsShapeQueryParameters">
</argument>
<description>
- Check the intersections of a shape, given through a [PhysicsShapeQueryParameters] object, against the space. If it collides with more than a shape, the nearest one is selected. The returned object is a dictionary containing the following fields:
- collider_id: ID of the object against which the shape intersected.
- linear_velocity: The movement vector of the object the shape intersected, if it was a body. If it was an area, it is (0,0).
- normal: Normal of the object at the point where the shapes intersect.
- point: Place where the shapes intersect.
- rid: [RID] of the object against which the shape intersected.
- shape: Shape index within the object against which the shape intersected.
- If the shape did not intersect anything, then an empty dictionary (dir.empty()==true) is returned instead.
+ Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters] object, against the space. If it collides with more than a shape, the nearest one is selected. The returned object is a dictionary containing the following fields:
+ [code]collider_id[/code]: The colliding object's ID.
+ [code]linear_velocity[/code]: The colliding object's velocity [Vector3]. If the object is an [Area], the result is [code](0, 0, 0)[/code].
+ [code]normal[/code]: The object's surface normal at the intersection point.
+ [code]point[/code]: The intersection point.
+ [code]rid[/code]: The intersecting object's [RID].
+ [code]shape[/code]: The shape index of the colliding shape.
+ If the shape did not intersect anything, then an empty dictionary ([code]dir.empty()==true[/code]) is returned instead.
</description>
</method>
<method name="intersect_ray">
@@ -62,14 +62,14 @@
<argument index="3" name="collision_layer" type="int" default="2147483647">
</argument>
<description>
- Intersect a ray in a given space. The returned object is a dictionary with the following fields:
- collider: Object against which the ray was stopped.
- collider_id: ID of the object against which the ray was stopped.
- normal: Normal of the object at the point where the ray was stopped.
- position: Place where ray is stopped.
- rid: [RID] of the object against which the ray was stopped.
- shape: Shape index within the object against which the ray was stopped.
- If the ray did not intersect anything, then an empty dictionary (dir.empty()==true) is returned instead.
+ Intersects a ray in a given space. The returned object is a dictionary with the following fields:
+ [code]collider[/code]: The colliding object.
+ [code]collider_id[/code]: The colliding object's ID.
+ [code]normal[/code]: The object's surface normal at the intersection point.
+ [code]position[/code]: The intersection point.
+ [code]rid[/code]: The intersecting object's [RID].
+ [code]shape[/code]: The shape index of the colliding shape.
+ If the ray did not intersect anything, then an empty dictionary ([code]dir.empty()==true[/code]) is returned instead.
Additionally, the method can take an array of objects or [RID]s that are to be excluded from collisions, or a bitmask representing the physics layers to check in.
</description>
</method>
@@ -81,11 +81,11 @@
<argument index="1" name="max_results" type="int" default="32">
</argument>
<description>
- Check the intersections of a shape, given through a [PhysicsShapeQueryParameters] object, against the space. The intersected shapes are returned in an array containing dictionaries with the following fields:
- collider: Object the shape intersected.
- collider_id: ID of the object the shape intersected.
- rid: [RID] of the object the shape intersected.
- shape: Shape index within the object the shape intersected.
+ Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters] object, against the space. The intersected shapes are returned in an array containing dictionaries with the following fields:
+ [code]collider[/code]: The colliding object.
+ [code]collider_id[/code]: The colliding object's ID.
+ [code]rid[/code]: The intersecting object's [RID].
+ [code]shape[/code]: The shape index of the colliding shape.
The number of intersections can be limited with the second parameter, to reduce the processing time.
</description>
</method>
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp
index a4daa77b50..86415ea740 100644
--- a/drivers/gles3/rasterizer_canvas_gles3.cpp
+++ b/drivers/gles3/rasterizer_canvas_gles3.cpp
@@ -1086,19 +1086,22 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons
}
}
- if (shader_ptr && shader_ptr != shader_cache) {
+ if (shader_ptr) {
if (shader_ptr->canvas_item.uses_screen_texture && !state.canvas_texscreen_used) {
//copy if not copied before
_copy_texscreen(Rect2());
}
- if (shader_ptr->canvas_item.uses_time) {
- VisualServerRaster::redraw_request();
- }
+ if (shader_ptr != shader_cache) {
- state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id);
- state.canvas_shader.bind();
+ if (shader_ptr->canvas_item.uses_time) {
+ VisualServerRaster::redraw_request();
+ }
+
+ state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id);
+ state.canvas_shader.bind();
+ }
if (material_ptr->ubo_id) {
glBindBufferBase(GL_UNIFORM_BUFFER, 2, material_ptr->ubo_id);
@@ -1147,7 +1150,7 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons
glBindTexture(t->target, t->tex_id);
}
- } else if (!shader_ptr) {
+ } else {
state.canvas_shader.set_custom_shader(0);
state.canvas_shader.bind();
}
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index b777f9343a..1c3361d2de 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -1541,7 +1541,19 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) {
if (c.texture.is_valid() && storage->texture_owner.owns(c.texture)) {
- const RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(c.texture);
+ RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(c.texture);
+
+ t = t->get_ptr(); //resolve for proxies
+#ifdef TOOLS_ENABLED
+ if (t->detect_3d) {
+ t->detect_3d(t->detect_3d_ud);
+ }
+#endif
+
+ if (t->render_target) {
+ t->render_target->used_in_frame = true;
+ }
+
glActiveTexture(GL_TEXTURE0);
glBindTexture(t->target, t->tex_id);
restore_tex = true;
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp
index 49d55e6305..214b1cac89 100644
--- a/editor/editor_data.cpp
+++ b/editor/editor_data.cpp
@@ -701,6 +701,15 @@ String EditorData::get_scene_title(int p_idx) const {
return name;
}
+void EditorData::set_scene_path(int p_idx, const String &p_path) {
+
+ ERR_FAIL_INDEX(p_idx, edited_scene.size());
+
+ if (!edited_scene[p_idx].root)
+ return;
+ edited_scene[p_idx].root->set_filename(p_path);
+}
+
String EditorData::get_scene_path(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
diff --git a/editor/editor_data.h b/editor/editor_data.h
index 33a4091a65..f15b7e37f1 100644
--- a/editor/editor_data.h
+++ b/editor/editor_data.h
@@ -185,6 +185,7 @@ public:
String get_scene_title(int p_idx) const;
String get_scene_path(int p_idx) const;
String get_scene_type(int p_idx) const;
+ void set_scene_path(int p_idx, const String &p_path);
Ref<Script> get_scene_root_script(int p_idx) const;
void set_edited_scene_version(uint64_t version, int p_scene_idx = -1);
uint64_t get_edited_scene_version() const;
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 75e4f39e25..dce5a10d67 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -834,6 +834,58 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin
memdelete(da);
}
+void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> &p_renames) const {
+
+ //Rename all resources loaded, be it subresources or actual resources
+ List<Ref<Resource> > cached;
+ ResourceCache::get_cached_resources(&cached);
+
+ for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) {
+
+ Ref<Resource> r = E->get();
+
+ String base_path = r->get_path();
+ String extra_path;
+ int sep_pos = r->get_path().find("::");
+ if (sep_pos >= 0) {
+ extra_path = base_path.substr(sep_pos, base_path.length());
+ base_path = base_path.substr(0, sep_pos);
+ }
+
+ if (p_renames.has(base_path)) {
+ base_path = p_renames[base_path];
+ }
+
+ r->set_path(base_path + extra_path);
+ }
+
+ for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) {
+
+ String path;
+ if (i == EditorNode::get_editor_data().get_edited_scene()) {
+ if (!get_tree()->get_edited_scene_root())
+ continue;
+
+ path = get_tree()->get_edited_scene_root()->get_filename();
+ } else {
+
+ path = EditorNode::get_editor_data().get_scene_path(i);
+ }
+
+ if (p_renames.has(path)) {
+ path = p_renames[path];
+ }
+
+ if (i == EditorNode::get_editor_data().get_edited_scene()) {
+
+ get_tree()->get_edited_scene_root()->set_filename(path);
+ } else {
+
+ EditorNode::get_editor_data().set_scene_path(i, path);
+ }
+ }
+}
+
void FileSystemDock::_update_dependencies_after_move(const Map<String, String> &p_renames) const {
//The following code assumes that the following holds:
// 1) EditorFileSystem contains the old paths/folder structure from before the rename/move.
@@ -910,6 +962,7 @@ void FileSystemDock::_rename_operation_confirm() {
Map<String, String> renames;
_try_move_item(to_rename, new_path, renames);
_update_dependencies_after_move(renames);
+ _update_resource_paths_after_move(renames);
//Rescan everything
print_line("call rescan!");
@@ -959,6 +1012,8 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path) {
}
_update_dependencies_after_move(renames);
+ _update_resource_paths_after_move(renames);
+
print_line("call rescan!");
_rescan();
}
diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h
index bc8d835ba1..65a71b86e0 100644
--- a/editor/filesystem_dock.h
+++ b/editor/filesystem_dock.h
@@ -178,6 +178,7 @@ private:
void _try_move_item(const FileOrFolder &p_item, const String &p_new_path, Map<String, String> &p_renames) const;
void _try_duplicate_item(const FileOrFolder &p_item, const String &p_new_path) const;
void _update_dependencies_after_move(const Map<String, String> &p_renames) const;
+ void _update_resource_paths_after_move(const Map<String, String> &p_renames) const;
void _make_dir_confirm();
void _rename_operation_confirm();
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 39e6698725..0c8837ee1a 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -200,6 +200,9 @@ static ResourceFormatLoaderDynamicFont *resource_loader_dynamic_font = NULL;
static ResourceFormatLoaderStreamTexture *resource_loader_stream_texture = NULL;
+static ResourceFormatSaverShader *resource_saver_shader = NULL;
+static ResourceFormatLoaderShader *resource_loader_shader = NULL;
+
void register_scene_types() {
SceneStringNames::create();
@@ -607,6 +610,12 @@ void register_scene_types() {
resource_loader_text = memnew(ResourceFormatLoaderText);
ResourceLoader::add_resource_format_loader(resource_loader_text, true);
+ resource_saver_shader = memnew(ResourceFormatSaverShader);
+ ResourceSaver::add_resource_format_saver(resource_saver_shader, true);
+
+ resource_loader_shader = memnew(ResourceFormatLoaderShader);
+ ResourceLoader::add_resource_format_loader(resource_loader_shader, true);
+
for (int i = 0; i < 20; i++) {
GLOBAL_DEF("layer_names/2d_render/layer_" + itos(i + 1), "");
GLOBAL_DEF("layer_names/2d_physics/layer_" + itos(i + 1), "");
@@ -632,6 +641,13 @@ void unregister_scene_types() {
memdelete(resource_loader_text);
}
+ if (resource_saver_shader) {
+ memdelete(resource_saver_shader);
+ }
+ if (resource_loader_shader) {
+ memdelete(resource_loader_shader);
+ }
+
SpatialMaterial::finish_shaders();
ParticlesMaterial::finish_shaders();
CanvasItemMaterial::finish_shaders();
diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp
index 66df7dfda8..207c50f673 100644
--- a/scene/resources/shader.cpp
+++ b/scene/resources/shader.cpp
@@ -151,3 +151,80 @@ Shader::~Shader() {
VisualServer::get_singleton()->free(shader);
}
+////////////
+
+RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_original_path, Error *r_error) {
+
+ if (r_error)
+ *r_error = ERR_FILE_CANT_OPEN;
+
+ Ref<Shader> shader;
+ shader.instance();
+
+ Vector<uint8_t> buffer = FileAccess::get_file_as_array(p_path);
+
+ String str;
+ str.parse_utf8((const char *)buffer.ptr(), buffer.size());
+
+ shader->set_code(str);
+
+ if (r_error)
+ *r_error = OK;
+
+ return shader;
+}
+
+void ResourceFormatLoaderShader::get_recognized_extensions(List<String> *p_extensions) const {
+
+ p_extensions->push_back("shader");
+}
+
+bool ResourceFormatLoaderShader::handles_type(const String &p_type) const {
+
+ return (p_type == "Shader");
+}
+
+String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const {
+
+ String el = p_path.get_extension().to_lower();
+ if (el == "shader")
+ return "Shader";
+ return "";
+}
+
+Error ResourceFormatSaverShader::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
+
+ Ref<Shader> shader = p_resource;
+ ERR_FAIL_COND_V(shader.is_null(), ERR_INVALID_PARAMETER);
+
+ String source = shader->get_code();
+
+ Error err;
+ FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
+
+ if (err) {
+
+ ERR_FAIL_COND_V(err, err);
+ }
+
+ file->store_string(source);
+ if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
+ memdelete(file);
+ return ERR_CANT_CREATE;
+ }
+ file->close();
+ memdelete(file);
+
+ return OK;
+}
+
+void ResourceFormatSaverShader::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
+
+ if (Object::cast_to<Shader>(*p_resource)) {
+ p_extensions->push_back("shader");
+ }
+}
+bool ResourceFormatSaverShader::recognize(const RES &p_resource) const {
+
+ return Object::cast_to<Shader>(*p_resource) != NULL;
+}
diff --git a/scene/resources/shader.h b/scene/resources/shader.h
index 5cc70629c7..78d73a33e2 100644
--- a/scene/resources/shader.h
+++ b/scene/resources/shader.h
@@ -31,6 +31,7 @@
#define SHADER_H
#include "io/resource_loader.h"
+#include "io/resource_saver.h"
#include "resource.h"
#include "scene/resources/texture.h"
@@ -38,7 +39,6 @@ class Shader : public Resource {
GDCLASS(Shader, Resource);
OBJ_SAVE_TYPE(Shader);
- RES_BASE_EXTENSION("shd");
public:
enum Mode {
@@ -95,4 +95,19 @@ public:
VARIANT_ENUM_CAST(Shader::Mode);
+class ResourceFormatLoaderShader : public ResourceFormatLoader {
+public:
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual void get_recognized_extensions(List<String> *p_extensions) const;
+ virtual bool handles_type(const String &p_type) const;
+ virtual String get_resource_type(const String &p_path) const;
+};
+
+class ResourceFormatSaverShader : public ResourceFormatSaver {
+public:
+ virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
+ virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;
+ virtual bool recognize(const RES &p_resource) const;
+};
+
#endif // SHADER_H