rendering_device_binds.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. /*************************************************************************/
  2. /* rendering_device_binds.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef RENDERING_DEVICE_BINDS_H
  31. #define RENDERING_DEVICE_BINDS_H
  32. #include "servers/rendering/rendering_device.h"
  33. #define RD_SETGET(m_type, m_member) \
  34. void set_##m_member(m_type p_##m_member) { base.m_member = p_##m_member; } \
  35. m_type get_##m_member() const { return base.m_member; }
  36. #define RD_BIND(m_variant_type, m_class, m_member) \
  37. ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_member); \
  38. ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_member)), &m_class::get_##m_member); \
  39. ADD_PROPERTY(PropertyInfo(m_variant_type, #m_member), "set_" _MKSTR(m_member), "get_" _MKSTR(m_member))
  40. #define RD_SETGET_SUB(m_type, m_sub, m_member) \
  41. void set_##m_sub##_##m_member(m_type p_##m_member) { base.m_sub.m_member = p_##m_member; } \
  42. m_type get_##m_sub##_##m_member() const { return base.m_sub.m_member; }
  43. #define RD_BIND_SUB(m_variant_type, m_class, m_sub, m_member) \
  44. ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_sub) "_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_sub##_##m_member); \
  45. ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_sub) "_" _MKSTR(m_member)), &m_class::get_##m_sub##_##m_member); \
  46. ADD_PROPERTY(PropertyInfo(m_variant_type, _MKSTR(m_sub) "_" _MKSTR(m_member)), "set_" _MKSTR(m_sub) "_" _MKSTR(m_member), "get_" _MKSTR(m_sub) "_" _MKSTR(m_member))
  47. class RDTextureFormat : public Reference {
  48. GDCLASS(RDTextureFormat, Reference)
  49. friend class RenderingDevice;
  50. RD::TextureFormat base;
  51. public:
  52. RD_SETGET(RD::DataFormat, format)
  53. RD_SETGET(uint32_t, width)
  54. RD_SETGET(uint32_t, height)
  55. RD_SETGET(uint32_t, depth)
  56. RD_SETGET(uint32_t, array_layers)
  57. RD_SETGET(uint32_t, mipmaps)
  58. RD_SETGET(RD::TextureType, texture_type)
  59. RD_SETGET(RD::TextureSamples, samples)
  60. RD_SETGET(uint32_t, usage_bits)
  61. void add_shareable_format(RD::DataFormat p_format) { base.shareable_formats.push_back(p_format); }
  62. void remove_shareable_format(RD::DataFormat p_format) { base.shareable_formats.erase(p_format); }
  63. protected:
  64. static void _bind_methods() {
  65. RD_BIND(Variant::INT, RDTextureFormat, format);
  66. RD_BIND(Variant::INT, RDTextureFormat, width);
  67. RD_BIND(Variant::INT, RDTextureFormat, height);
  68. RD_BIND(Variant::INT, RDTextureFormat, depth);
  69. RD_BIND(Variant::INT, RDTextureFormat, array_layers);
  70. RD_BIND(Variant::INT, RDTextureFormat, mipmaps);
  71. RD_BIND(Variant::INT, RDTextureFormat, texture_type);
  72. RD_BIND(Variant::INT, RDTextureFormat, samples);
  73. RD_BIND(Variant::INT, RDTextureFormat, usage_bits);
  74. ClassDB::bind_method(D_METHOD("add_shareable_format", "format"), &RDTextureFormat::add_shareable_format);
  75. ClassDB::bind_method(D_METHOD("remove_shareable_format", "format"), &RDTextureFormat::remove_shareable_format);
  76. }
  77. };
  78. class RDTextureView : public Reference {
  79. GDCLASS(RDTextureView, Reference)
  80. friend class RenderingDevice;
  81. RD::TextureView base;
  82. public:
  83. RD_SETGET(RD::DataFormat, format_override)
  84. RD_SETGET(RD::TextureSwizzle, swizzle_r)
  85. RD_SETGET(RD::TextureSwizzle, swizzle_g)
  86. RD_SETGET(RD::TextureSwizzle, swizzle_b)
  87. RD_SETGET(RD::TextureSwizzle, swizzle_a)
  88. protected:
  89. static void _bind_methods() {
  90. RD_BIND(Variant::INT, RDTextureView, format_override);
  91. RD_BIND(Variant::INT, RDTextureView, swizzle_r);
  92. RD_BIND(Variant::INT, RDTextureView, swizzle_g);
  93. RD_BIND(Variant::INT, RDTextureView, swizzle_b);
  94. RD_BIND(Variant::INT, RDTextureView, swizzle_a);
  95. }
  96. };
  97. class RDAttachmentFormat : public Reference {
  98. GDCLASS(RDAttachmentFormat, Reference)
  99. friend class RenderingDevice;
  100. RD::AttachmentFormat base;
  101. public:
  102. RD_SETGET(RD::DataFormat, format)
  103. RD_SETGET(RD::TextureSamples, samples)
  104. RD_SETGET(uint32_t, usage_flags)
  105. protected:
  106. static void _bind_methods() {
  107. RD_BIND(Variant::INT, RDAttachmentFormat, format);
  108. RD_BIND(Variant::INT, RDAttachmentFormat, samples);
  109. RD_BIND(Variant::INT, RDAttachmentFormat, usage_flags);
  110. }
  111. };
  112. class RDSamplerState : public Reference {
  113. GDCLASS(RDSamplerState, Reference)
  114. friend class RenderingDevice;
  115. RD::SamplerState base;
  116. public:
  117. RD_SETGET(RD::SamplerFilter, mag_filter)
  118. RD_SETGET(RD::SamplerFilter, min_filter)
  119. RD_SETGET(RD::SamplerFilter, mip_filter)
  120. RD_SETGET(RD::SamplerRepeatMode, repeat_u)
  121. RD_SETGET(RD::SamplerRepeatMode, repeat_v)
  122. RD_SETGET(RD::SamplerRepeatMode, repeat_w)
  123. RD_SETGET(float, lod_bias)
  124. RD_SETGET(bool, use_anisotropy)
  125. RD_SETGET(float, anisotropy_max)
  126. RD_SETGET(bool, enable_compare)
  127. RD_SETGET(RD::CompareOperator, compare_op)
  128. RD_SETGET(float, min_lod)
  129. RD_SETGET(float, max_lod)
  130. RD_SETGET(RD::SamplerBorderColor, border_color)
  131. RD_SETGET(bool, unnormalized_uvw)
  132. protected:
  133. static void _bind_methods() {
  134. RD_BIND(Variant::INT, RDSamplerState, mag_filter);
  135. RD_BIND(Variant::INT, RDSamplerState, min_filter);
  136. RD_BIND(Variant::INT, RDSamplerState, mip_filter);
  137. RD_BIND(Variant::INT, RDSamplerState, repeat_u);
  138. RD_BIND(Variant::INT, RDSamplerState, repeat_v);
  139. RD_BIND(Variant::INT, RDSamplerState, repeat_w);
  140. RD_BIND(Variant::FLOAT, RDSamplerState, lod_bias);
  141. RD_BIND(Variant::BOOL, RDSamplerState, use_anisotropy);
  142. RD_BIND(Variant::FLOAT, RDSamplerState, anisotropy_max);
  143. RD_BIND(Variant::BOOL, RDSamplerState, enable_compare);
  144. RD_BIND(Variant::INT, RDSamplerState, compare_op);
  145. RD_BIND(Variant::FLOAT, RDSamplerState, min_lod);
  146. RD_BIND(Variant::FLOAT, RDSamplerState, max_lod);
  147. RD_BIND(Variant::INT, RDSamplerState, border_color);
  148. RD_BIND(Variant::BOOL, RDSamplerState, unnormalized_uvw);
  149. }
  150. };
  151. class RDVertexAttribute : public Reference {
  152. GDCLASS(RDVertexAttribute, Reference)
  153. friend class RenderingDevice;
  154. RD::VertexAttribute base;
  155. public:
  156. RD_SETGET(uint32_t, location)
  157. RD_SETGET(uint32_t, offset)
  158. RD_SETGET(RD::DataFormat, format)
  159. RD_SETGET(uint32_t, stride)
  160. RD_SETGET(RD::VertexFrequency, frequency)
  161. protected:
  162. static void _bind_methods() {
  163. RD_BIND(Variant::INT, RDVertexAttribute, location);
  164. RD_BIND(Variant::INT, RDVertexAttribute, offset);
  165. RD_BIND(Variant::INT, RDVertexAttribute, format);
  166. RD_BIND(Variant::INT, RDVertexAttribute, stride);
  167. RD_BIND(Variant::INT, RDVertexAttribute, frequency);
  168. }
  169. };
  170. class RDShaderSource : public Reference {
  171. GDCLASS(RDShaderSource, Reference)
  172. String source[RD::SHADER_STAGE_MAX];
  173. RD::ShaderLanguage language = RD::SHADER_LANGUAGE_GLSL;
  174. public:
  175. void set_stage_source(RD::ShaderStage p_stage, const String &p_source) {
  176. ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);
  177. source[p_stage] = p_source;
  178. }
  179. String get_stage_source(RD::ShaderStage p_stage) const {
  180. ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String());
  181. return source[p_stage];
  182. }
  183. void set_language(RD::ShaderLanguage p_language) {
  184. language = p_language;
  185. }
  186. RD::ShaderLanguage get_language() const {
  187. return language;
  188. }
  189. protected:
  190. static void _bind_methods() {
  191. ClassDB::bind_method(D_METHOD("set_stage_source", "stage", "source"), &RDShaderSource::set_stage_source);
  192. ClassDB::bind_method(D_METHOD("get_stage_source", "stage"), &RDShaderSource::get_stage_source);
  193. ClassDB::bind_method(D_METHOD("set_language", "language"), &RDShaderSource::set_language);
  194. ClassDB::bind_method(D_METHOD("get_language"), &RDShaderSource::get_language);
  195. ADD_GROUP("Source", "source_");
  196. ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_vertex"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_VERTEX);
  197. ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_fragment"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_FRAGMENT);
  198. ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_control"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_CONTROL);
  199. ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_evaluation"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_EVALUATION);
  200. ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_compute"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_COMPUTE);
  201. ADD_GROUP("Syntax", "source_");
  202. ADD_PROPERTY(PropertyInfo(Variant::INT, "language", PROPERTY_HINT_RANGE, "GLSL,HLSL"), "set_language", "get_language");
  203. }
  204. };
  205. class RDShaderBytecode : public Resource {
  206. GDCLASS(RDShaderBytecode, Resource)
  207. Vector<uint8_t> bytecode[RD::SHADER_STAGE_MAX];
  208. String compile_error[RD::SHADER_STAGE_MAX];
  209. public:
  210. void set_stage_bytecode(RD::ShaderStage p_stage, const Vector<uint8_t> &p_bytecode) {
  211. ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);
  212. bytecode[p_stage] = p_bytecode;
  213. }
  214. Vector<uint8_t> get_stage_bytecode(RD::ShaderStage p_stage) const {
  215. ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, Vector<uint8_t>());
  216. return bytecode[p_stage];
  217. }
  218. void set_stage_compile_error(RD::ShaderStage p_stage, const String &p_compile_error) {
  219. ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);
  220. compile_error[p_stage] = p_compile_error;
  221. }
  222. String get_stage_compile_error(RD::ShaderStage p_stage) const {
  223. ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String());
  224. return compile_error[p_stage];
  225. }
  226. protected:
  227. static void _bind_methods() {
  228. ClassDB::bind_method(D_METHOD("set_stage_bytecode", "stage", "bytecode"), &RDShaderBytecode::set_stage_bytecode);
  229. ClassDB::bind_method(D_METHOD("get_stage_bytecode", "stage"), &RDShaderBytecode::get_stage_bytecode);
  230. ClassDB::bind_method(D_METHOD("set_stage_compile_error", "stage", "compile_error"), &RDShaderBytecode::set_stage_compile_error);
  231. ClassDB::bind_method(D_METHOD("get_stage_compile_error", "stage"), &RDShaderBytecode::get_stage_compile_error);
  232. ADD_GROUP("Bytecode", "bytecode_");
  233. ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_vertex"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_VERTEX);
  234. ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_fragment"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_FRAGMENT);
  235. ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_control"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_CONTROL);
  236. ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_evaluation"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_EVALUATION);
  237. ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_compute"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_COMPUTE);
  238. ADD_GROUP("Compile Error", "compile_error_");
  239. ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_vertex"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_VERTEX);
  240. ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_fragment"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_FRAGMENT);
  241. ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_control"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_CONTROL);
  242. ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_evaluation"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_EVALUATION);
  243. ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_compute"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_COMPUTE);
  244. }
  245. };
  246. class RDShaderFile : public Resource {
  247. GDCLASS(RDShaderFile, Resource)
  248. Map<StringName, Ref<RDShaderBytecode>> versions;
  249. String base_error;
  250. public:
  251. void set_bytecode(const Ref<RDShaderBytecode> &p_bytecode, const StringName &p_version = StringName()) {
  252. ERR_FAIL_COND(p_bytecode.is_null());
  253. versions[p_version] = p_bytecode;
  254. emit_changed();
  255. }
  256. Ref<RDShaderBytecode> get_bytecode(const StringName &p_version = StringName()) const {
  257. ERR_FAIL_COND_V(!versions.has(p_version), Ref<RDShaderBytecode>());
  258. return versions[p_version];
  259. }
  260. Vector<StringName> get_version_list() const {
  261. Vector<StringName> vnames;
  262. for (Map<StringName, Ref<RDShaderBytecode>>::Element *E = versions.front(); E; E = E->next()) {
  263. vnames.push_back(E->key());
  264. }
  265. vnames.sort_custom<StringName::AlphCompare>();
  266. return vnames;
  267. }
  268. void set_base_error(const String &p_error) {
  269. base_error = p_error;
  270. emit_changed();
  271. }
  272. String get_base_error() const {
  273. return base_error;
  274. }
  275. void print_errors(const String &p_file) {
  276. if (base_error != "") {
  277. ERR_PRINT("Error parsing shader '" + p_file + "':\n\n" + base_error);
  278. } else {
  279. for (Map<StringName, Ref<RDShaderBytecode>>::Element *E = versions.front(); E; E = E->next()) {
  280. for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {
  281. String error = E->get()->get_stage_compile_error(RD::ShaderStage(i));
  282. if (error != String()) {
  283. static const char *stage_str[RD::SHADER_STAGE_MAX] = {
  284. "vertex",
  285. "fragment",
  286. "tesselation_control",
  287. "tesselation_evaluation",
  288. "compute"
  289. };
  290. ERR_PRINT("Error parsing shader '" + p_file + "', version '" + String(E->key()) + "', stage '" + stage_str[i] + "':\n\n" + error);
  291. }
  292. }
  293. }
  294. }
  295. }
  296. typedef String (*OpenIncludeFunction)(const String &, void *userdata);
  297. Error parse_versions_from_text(const String &p_text, const String p_defines = String(), OpenIncludeFunction p_include_func = nullptr, void *p_include_func_userdata = nullptr);
  298. protected:
  299. Dictionary _get_versions() const {
  300. Vector<StringName> vnames = get_version_list();
  301. Dictionary ret;
  302. for (int i = 0; i < vnames.size(); i++) {
  303. ret[vnames[i]] = versions[vnames[i]];
  304. }
  305. return ret;
  306. }
  307. void _set_versions(const Dictionary &p_versions) {
  308. versions.clear();
  309. List<Variant> keys;
  310. p_versions.get_key_list(&keys);
  311. for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
  312. StringName name = E->get();
  313. Ref<RDShaderBytecode> bc = p_versions[E->get()];
  314. ERR_CONTINUE(bc.is_null());
  315. versions[name] = bc;
  316. }
  317. emit_changed();
  318. }
  319. static void _bind_methods() {
  320. ClassDB::bind_method(D_METHOD("set_bytecode", "bytecode", "version"), &RDShaderFile::set_bytecode, DEFVAL(StringName()));
  321. ClassDB::bind_method(D_METHOD("get_bytecode", "version"), &RDShaderFile::get_bytecode, DEFVAL(StringName()));
  322. ClassDB::bind_method(D_METHOD("get_version_list"), &RDShaderFile::get_version_list);
  323. ClassDB::bind_method(D_METHOD("set_base_error", "error"), &RDShaderFile::set_base_error);
  324. ClassDB::bind_method(D_METHOD("get_base_error"), &RDShaderFile::get_base_error);
  325. ClassDB::bind_method(D_METHOD("_set_versions", "versions"), &RDShaderFile::_set_versions);
  326. ClassDB::bind_method(D_METHOD("_get_versions"), &RDShaderFile::_get_versions);
  327. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_versions", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_versions", "_get_versions");
  328. ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_error"), "set_base_error", "get_base_error");
  329. }
  330. };
  331. class RDUniform : public Reference {
  332. GDCLASS(RDUniform, Reference)
  333. friend class RenderingDevice;
  334. RD::Uniform base;
  335. public:
  336. RD_SETGET(RD::UniformType, uniform_type)
  337. RD_SETGET(int32_t, binding)
  338. void add_id(const RID &p_id) { base.ids.push_back(p_id); }
  339. void clear_ids() { base.ids.clear(); }
  340. Array get_ids() const {
  341. Array ids;
  342. for (int i = 0; i < base.ids.size(); i++) {
  343. ids.push_back(base.ids[i]);
  344. }
  345. return ids;
  346. }
  347. protected:
  348. void _set_ids(const Array &p_ids) {
  349. base.ids.clear();
  350. for (int i = 0; i < p_ids.size(); i++) {
  351. RID id = p_ids[i];
  352. ERR_FAIL_COND(id.is_null());
  353. base.ids.push_back(id);
  354. }
  355. }
  356. static void _bind_methods() {
  357. RD_BIND(Variant::INT, RDUniform, uniform_type);
  358. RD_BIND(Variant::INT, RDUniform, binding);
  359. ClassDB::bind_method(D_METHOD("add_id", "id"), &RDUniform::add_id);
  360. ClassDB::bind_method(D_METHOD("clear_ids"), &RDUniform::clear_ids);
  361. ClassDB::bind_method(D_METHOD("_set_ids", "ids"), &RDUniform::_set_ids);
  362. ClassDB::bind_method(D_METHOD("get_ids"), &RDUniform::get_ids);
  363. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_ids", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_ids", "get_ids");
  364. }
  365. };
  366. class RDPipelineRasterizationState : public Reference {
  367. GDCLASS(RDPipelineRasterizationState, Reference)
  368. friend class RenderingDevice;
  369. RD::PipelineRasterizationState base;
  370. public:
  371. RD_SETGET(bool, enable_depth_clamp)
  372. RD_SETGET(bool, discard_primitives)
  373. RD_SETGET(bool, wireframe)
  374. RD_SETGET(RD::PolygonCullMode, cull_mode)
  375. RD_SETGET(RD::PolygonFrontFace, front_face)
  376. RD_SETGET(bool, depth_bias_enable)
  377. RD_SETGET(float, depth_bias_constant_factor)
  378. RD_SETGET(float, depth_bias_clamp)
  379. RD_SETGET(float, depth_bias_slope_factor)
  380. RD_SETGET(float, line_width)
  381. RD_SETGET(uint32_t, patch_control_points)
  382. protected:
  383. static void _bind_methods() {
  384. RD_BIND(Variant::BOOL, RDPipelineRasterizationState, enable_depth_clamp);
  385. RD_BIND(Variant::BOOL, RDPipelineRasterizationState, discard_primitives);
  386. RD_BIND(Variant::BOOL, RDPipelineRasterizationState, wireframe);
  387. RD_BIND(Variant::INT, RDPipelineRasterizationState, cull_mode);
  388. RD_BIND(Variant::INT, RDPipelineRasterizationState, front_face);
  389. RD_BIND(Variant::BOOL, RDPipelineRasterizationState, depth_bias_enable);
  390. RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_constant_factor);
  391. RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_clamp);
  392. RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_slope_factor);
  393. RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, line_width);
  394. RD_BIND(Variant::INT, RDPipelineRasterizationState, patch_control_points);
  395. }
  396. };
  397. class RDPipelineMultisampleState : public Reference {
  398. GDCLASS(RDPipelineMultisampleState, Reference)
  399. friend class RenderingDevice;
  400. RD::PipelineMultisampleState base;
  401. TypedArray<int64_t> sample_masks;
  402. public:
  403. RD_SETGET(RD::TextureSamples, sample_count)
  404. RD_SETGET(bool, enable_sample_shading)
  405. RD_SETGET(float, min_sample_shading)
  406. RD_SETGET(bool, enable_alpha_to_coverage)
  407. RD_SETGET(bool, enable_alpha_to_one)
  408. void set_sample_masks(const TypedArray<int64_t> &p_masks) { sample_masks = p_masks; }
  409. TypedArray<int64_t> get_sample_masks() const { return sample_masks; }
  410. protected:
  411. static void _bind_methods() {
  412. RD_BIND(Variant::INT, RDPipelineMultisampleState, sample_count);
  413. RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_sample_shading);
  414. RD_BIND(Variant::FLOAT, RDPipelineMultisampleState, min_sample_shading);
  415. RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_coverage);
  416. RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_one);
  417. ClassDB::bind_method(D_METHOD("set_sample_masks", "masks"), &RDPipelineMultisampleState::set_sample_masks);
  418. ClassDB::bind_method(D_METHOD("get_sample_masks"), &RDPipelineMultisampleState::get_sample_masks);
  419. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "sample_masks", PROPERTY_HINT_ARRAY_TYPE, "int"), "set_sample_masks", "get_sample_masks");
  420. }
  421. };
  422. class RDPipelineDepthStencilState : public Reference {
  423. GDCLASS(RDPipelineDepthStencilState, Reference)
  424. friend class RenderingDevice;
  425. RD::PipelineDepthStencilState base;
  426. public:
  427. RD_SETGET(bool, enable_depth_test)
  428. RD_SETGET(bool, enable_depth_write)
  429. RD_SETGET(RD::CompareOperator, depth_compare_operator)
  430. RD_SETGET(bool, enable_depth_range)
  431. RD_SETGET(float, depth_range_min)
  432. RD_SETGET(float, depth_range_max)
  433. RD_SETGET(bool, enable_stencil)
  434. RD_SETGET_SUB(RD::StencilOperation, front_op, fail)
  435. RD_SETGET_SUB(RD::StencilOperation, front_op, pass)
  436. RD_SETGET_SUB(RD::StencilOperation, front_op, depth_fail)
  437. RD_SETGET_SUB(RD::CompareOperator, front_op, compare)
  438. RD_SETGET_SUB(uint32_t, front_op, compare_mask)
  439. RD_SETGET_SUB(uint32_t, front_op, write_mask)
  440. RD_SETGET_SUB(uint32_t, front_op, reference)
  441. RD_SETGET_SUB(RD::StencilOperation, back_op, fail)
  442. RD_SETGET_SUB(RD::StencilOperation, back_op, pass)
  443. RD_SETGET_SUB(RD::StencilOperation, back_op, depth_fail)
  444. RD_SETGET_SUB(RD::CompareOperator, back_op, compare)
  445. RD_SETGET_SUB(uint32_t, back_op, compare_mask)
  446. RD_SETGET_SUB(uint32_t, back_op, write_mask)
  447. RD_SETGET_SUB(uint32_t, back_op, reference)
  448. protected:
  449. static void _bind_methods() {
  450. RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_test);
  451. RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_write);
  452. RD_BIND(Variant::INT, RDPipelineDepthStencilState, depth_compare_operator);
  453. RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_range);
  454. RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_min);
  455. RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_max);
  456. RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_stencil);
  457. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, fail);
  458. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, pass);
  459. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, depth_fail);
  460. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare);
  461. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare_mask);
  462. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, write_mask);
  463. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, reference);
  464. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, fail);
  465. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, pass);
  466. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, depth_fail);
  467. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare);
  468. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare_mask);
  469. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, write_mask);
  470. RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, reference);
  471. }
  472. };
  473. class RDPipelineColorBlendStateAttachment : public Reference {
  474. GDCLASS(RDPipelineColorBlendStateAttachment, Reference)
  475. friend class RenderingDevice;
  476. RD::PipelineColorBlendState::Attachment base;
  477. public:
  478. RD_SETGET(bool, enable_blend)
  479. RD_SETGET(RD::BlendFactor, src_color_blend_factor)
  480. RD_SETGET(RD::BlendFactor, dst_color_blend_factor)
  481. RD_SETGET(RD::BlendOperation, color_blend_op)
  482. RD_SETGET(RD::BlendFactor, src_alpha_blend_factor)
  483. RD_SETGET(RD::BlendFactor, dst_alpha_blend_factor)
  484. RD_SETGET(RD::BlendOperation, alpha_blend_op)
  485. RD_SETGET(bool, write_r)
  486. RD_SETGET(bool, write_g)
  487. RD_SETGET(bool, write_b)
  488. RD_SETGET(bool, write_a)
  489. void set_as_mix() {
  490. base = RD::PipelineColorBlendState::Attachment();
  491. base.enable_blend = true;
  492. base.src_color_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
  493. base.dst_color_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  494. base.src_alpha_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
  495. base.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  496. }
  497. protected:
  498. static void _bind_methods() {
  499. ClassDB::bind_method(D_METHOD("set_as_mix"), &RDPipelineColorBlendStateAttachment::set_as_mix);
  500. RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, enable_blend);
  501. RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_color_blend_factor);
  502. RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_color_blend_factor);
  503. RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, color_blend_op);
  504. RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_alpha_blend_factor);
  505. RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_alpha_blend_factor);
  506. RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, alpha_blend_op);
  507. RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_r);
  508. RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_g);
  509. RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_b);
  510. RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_a);
  511. }
  512. };
  513. class RDPipelineColorBlendState : public Reference {
  514. GDCLASS(RDPipelineColorBlendState, Reference)
  515. friend class RenderingDevice;
  516. RD::PipelineColorBlendState base;
  517. TypedArray<RDPipelineColorBlendStateAttachment> attachments;
  518. public:
  519. RD_SETGET(bool, enable_logic_op)
  520. RD_SETGET(RD::LogicOperation, logic_op)
  521. RD_SETGET(Color, blend_constant)
  522. void set_attachments(const TypedArray<RDPipelineColorBlendStateAttachment> &p_attachments) {
  523. attachments.push_back(p_attachments);
  524. }
  525. TypedArray<RDPipelineColorBlendStateAttachment> get_attachments() const {
  526. return attachments;
  527. }
  528. protected:
  529. static void _bind_methods() {
  530. RD_BIND(Variant::BOOL, RDPipelineColorBlendState, enable_logic_op);
  531. RD_BIND(Variant::INT, RDPipelineColorBlendState, logic_op);
  532. RD_BIND(Variant::COLOR, RDPipelineColorBlendState, blend_constant);
  533. ClassDB::bind_method(D_METHOD("set_attachments", "attachments"), &RDPipelineColorBlendState::set_attachments);
  534. ClassDB::bind_method(D_METHOD("get_attachments"), &RDPipelineColorBlendState::get_attachments);
  535. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "attachments", PROPERTY_HINT_ARRAY_TYPE, "RDPipelineColorBlendStateAttachment"), "set_attachments", "get_attachments");
  536. }
  537. };
  538. #endif // RENDERING_DEVICE_BINDS_H