Debian Codegraph @

scene/resources/shader.h

raw symbols SCIP
1 /**************************************************************************/
2 /* shader.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/io/resource.h"
34 #include "core/io/resource_loader.h"
35 #include "core/io/resource_saver.h"
36 #include "scene/resources/texture.h"
37 #include "shader_include.h"
38
39 class Shader : public Resource {
40 GDCLASS(Shader, Resource);
41 OBJ_SAVE_TYPE(Shader);
42
43 public:
44 // Must be kept in sync with the List<String> of shader types in `servers/rendering/shader_types.cpp`.
45 enum Mode {
46 MODE_SPATIAL,
47 MODE_CANVAS_ITEM,
48 MODE_PARTICLES,
49 MODE_SKY,
50 MODE_FOG,
51 MODE_MAX
52 };
53
54 private:
55 mutable RID shader_rid;
56 mutable String preprocessed_code;
57 mutable Mutex shader_rid_mutex;
58
59 Mode mode = MODE_SPATIAL;
60 HashSet<Ref<ShaderInclude>> include_dependencies;
61 String code;
62 String include_path;
63
64 HashMap<StringName, HashMap<int, Ref<Texture>>> default_textures;
65
66 void _check_shader_rid() const;
67 void _dependency_changed();
68 void _recompile();
69 virtual void _update_shader() const; //used for visual shader
70 Array _get_shader_uniform_list(bool p_get_groups = false);
71
72 protected:
73 #ifndef DISABLE_DEPRECATED
74 void _set_default_texture_parameter_bind_compat_95126(const StringName &p_name, const Ref<Texture2D> &p_texture, int p_index = 0);
75 Ref<Texture2D> _get_default_texture_parameter_bind_compat_95126(const StringName &p_name, int p_index = 0) const;
76 static void _bind_compatibility_methods();
77 #endif // DISABLE_DEPRECATED
78
79 static void _bind_methods();
80
81 public:
82 //void set_mode(Mode p_mode);
83 virtual Mode get_mode() const;
84
85 virtual void set_path(const String &p_path, bool p_take_over = false) override;
86 void set_include_path(const String &p_path);
87
88 void set_code(const String &p_code);
89 String get_code() const;
90
91 void inspect_native_shader_code();
92
93 void get_shader_uniform_list(List<PropertyInfo> *p_params, bool p_get_groups = false) const;
94
95 void set_default_texture_parameter(const StringName &p_name, const Ref<Texture> &p_texture, int p_index = 0);
96 Ref<Texture> get_default_texture_parameter(const StringName &p_name, int p_index = 0) const;
97 void get_default_texture_parameter_list(List<StringName> *r_textures) const;
98
99 virtual bool is_text_shader() const;
100
101 virtual RID get_rid() const override;
102
103 Shader();
104 ~Shader();
105 };
106
107 VARIANT_ENUM_CAST(Shader::Mode);
108
109 class ResourceFormatLoaderShader : public ResourceFormatLoader {
110 GDSOFTCLASS(ResourceFormatLoaderShader, ResourceFormatLoader);
111
112 public:
113 virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE) override;
114 virtual void get_recognized_extensions(List<String> *p_extensions) const override;
115 virtual bool handles_type(const String &p_type) const override;
116 virtual String get_resource_type(const String &p_path) const override;
117 };
118
119 class ResourceFormatSaverShader : public ResourceFormatSaver {
120 GDSOFTCLASS(ResourceFormatSaverShader, ResourceFormatSaver);
121
122 public:
123 virtual Error save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags = 0) override;
124 virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const override;
125 virtual bool recognize(const Ref<Resource> &p_resource) const override;
126 };