1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
/*************************************************************************/
/* rendering_device_binds.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef RENDERING_DEVICE_BINDS_H
#define RENDERING_DEVICE_BINDS_H
#include "servers/rendering/rendering_device.h"
#define RD_SETGET(m_type, m_member) \
void set_##m_member(m_type p_##m_member) { base.m_member = p_##m_member; } \
m_type get_##m_member() const { return base.m_member; }
#define RD_BIND(m_variant_type, m_class, m_member) \
ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_member); \
ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_member)), &m_class::get_##m_member); \
ADD_PROPERTY(PropertyInfo(m_variant_type, #m_member), "set_" _MKSTR(m_member), "get_" _MKSTR(m_member))
#define RD_SETGET_SUB(m_type, m_sub, m_member) \
void set_##m_sub##_##m_member(m_type p_##m_member) { base.m_sub.m_member = p_##m_member; } \
m_type get_##m_sub##_##m_member() const { return base.m_sub.m_member; }
#define RD_BIND_SUB(m_variant_type, m_class, m_sub, m_member) \
ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_sub) "_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_sub##_##m_member); \
ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_sub) "_" _MKSTR(m_member)), &m_class::get_##m_sub##_##m_member); \
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))
class RDTextureFormat : public Reference {
GDCLASS(RDTextureFormat, Reference)
friend class RenderingDevice;
RD::TextureFormat base;
public:
RD_SETGET(RD::DataFormat, format)
RD_SETGET(uint32_t, width)
RD_SETGET(uint32_t, height)
RD_SETGET(uint32_t, depth)
RD_SETGET(uint32_t, array_layers)
RD_SETGET(uint32_t, mipmaps)
RD_SETGET(RD::TextureType, type)
RD_SETGET(RD::TextureSamples, samples)
RD_SETGET(uint32_t, usage_bits)
void add_shareable_format(RD::DataFormat p_format) { base.shareable_formats.push_back(p_format); }
void remove_shareable_format(RD::DataFormat p_format) { base.shareable_formats.erase(p_format); }
protected:
static void _bind_methods() {
RD_BIND(Variant::INT, RDTextureFormat, format);
RD_BIND(Variant::INT, RDTextureFormat, width);
RD_BIND(Variant::INT, RDTextureFormat, height);
RD_BIND(Variant::INT, RDTextureFormat, depth);
RD_BIND(Variant::INT, RDTextureFormat, array_layers);
RD_BIND(Variant::INT, RDTextureFormat, mipmaps);
RD_BIND(Variant::INT, RDTextureFormat, type);
RD_BIND(Variant::INT, RDTextureFormat, samples);
RD_BIND(Variant::INT, RDTextureFormat, usage_bits);
ClassDB::bind_method(D_METHOD("add_shareable_format", "format"), &RDTextureFormat::add_shareable_format);
ClassDB::bind_method(D_METHOD("remove_shareable_format", "format"), &RDTextureFormat::remove_shareable_format);
}
};
class RDTextureView : public Reference {
GDCLASS(RDTextureView, Reference)
friend class RenderingDevice;
RD::TextureView base;
public:
RD_SETGET(RD::DataFormat, format_override)
RD_SETGET(RD::TextureSwizzle, swizzle_r)
RD_SETGET(RD::TextureSwizzle, swizzle_g)
RD_SETGET(RD::TextureSwizzle, swizzle_b)
RD_SETGET(RD::TextureSwizzle, swizzle_a)
protected:
static void _bind_methods() {
RD_BIND(Variant::INT, RDTextureView, format_override);
RD_BIND(Variant::INT, RDTextureView, swizzle_r);
RD_BIND(Variant::INT, RDTextureView, swizzle_g);
RD_BIND(Variant::INT, RDTextureView, swizzle_b);
RD_BIND(Variant::INT, RDTextureView, swizzle_a);
}
};
class RDAttachmentFormat : public Reference {
GDCLASS(RDAttachmentFormat, Reference)
friend class RenderingDevice;
RD::AttachmentFormat base;
public:
RD_SETGET(RD::DataFormat, format)
RD_SETGET(RD::TextureSamples, samples)
RD_SETGET(uint32_t, usage_flags)
protected:
static void _bind_methods() {
RD_BIND(Variant::INT, RDAttachmentFormat, format);
RD_BIND(Variant::INT, RDAttachmentFormat, samples);
RD_BIND(Variant::INT, RDAttachmentFormat, usage_flags);
}
};
class RDSamplerState : public Reference {
GDCLASS(RDSamplerState, Reference)
friend class RenderingDevice;
RD::SamplerState base;
public:
RD_SETGET(RD::SamplerFilter, mag_filter)
RD_SETGET(RD::SamplerFilter, min_filter)
RD_SETGET(RD::SamplerFilter, mip_filter)
RD_SETGET(RD::SamplerRepeatMode, repeat_u)
RD_SETGET(RD::SamplerRepeatMode, repeat_v)
RD_SETGET(RD::SamplerRepeatMode, repeat_w)
RD_SETGET(float, lod_bias)
RD_SETGET(bool, use_anisotropy)
RD_SETGET(float, anisotropy_max)
RD_SETGET(bool, enable_compare)
RD_SETGET(RD::CompareOperator, compare_op)
RD_SETGET(float, min_lod)
RD_SETGET(float, max_lod)
RD_SETGET(RD::SamplerBorderColor, border_color)
RD_SETGET(bool, unnormalized_uvw)
protected:
static void _bind_methods() {
RD_BIND(Variant::INT, RDSamplerState, mag_filter);
RD_BIND(Variant::INT, RDSamplerState, min_filter);
RD_BIND(Variant::INT, RDSamplerState, mip_filter);
RD_BIND(Variant::INT, RDSamplerState, repeat_u);
RD_BIND(Variant::INT, RDSamplerState, repeat_v);
RD_BIND(Variant::INT, RDSamplerState, repeat_w);
RD_BIND(Variant::FLOAT, RDSamplerState, lod_bias);
RD_BIND(Variant::BOOL, RDSamplerState, use_anisotropy);
RD_BIND(Variant::FLOAT, RDSamplerState, anisotropy_max);
RD_BIND(Variant::BOOL, RDSamplerState, enable_compare);
RD_BIND(Variant::INT, RDSamplerState, compare_op);
RD_BIND(Variant::FLOAT, RDSamplerState, min_lod);
RD_BIND(Variant::FLOAT, RDSamplerState, max_lod);
RD_BIND(Variant::INT, RDSamplerState, border_color);
RD_BIND(Variant::BOOL, RDSamplerState, unnormalized_uvw);
}
};
class RDVertexAttribute : public Reference {
GDCLASS(RDVertexAttribute, Reference)
friend class RenderingDevice;
RD::VertexAttribute base;
public:
RD_SETGET(uint32_t, location)
RD_SETGET(uint32_t, offset)
RD_SETGET(RD::DataFormat, format)
RD_SETGET(uint32_t, stride)
RD_SETGET(RD::VertexFrequency, frequency)
protected:
static void _bind_methods() {
RD_BIND(Variant::INT, RDVertexAttribute, location);
RD_BIND(Variant::INT, RDVertexAttribute, offset);
RD_BIND(Variant::INT, RDVertexAttribute, format);
RD_BIND(Variant::INT, RDVertexAttribute, stride);
RD_BIND(Variant::INT, RDVertexAttribute, frequency);
}
};
class RDShaderSource : public Reference {
GDCLASS(RDShaderSource, Reference)
String source[RD::SHADER_STAGE_MAX];
RD::ShaderLanguage language = RD::SHADER_LANGUAGE_GLSL;
public:
void set_stage_source(RD::ShaderStage p_stage, const String &p_source) {
ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);
source[p_stage] = p_source;
}
String get_stage_source(RD::ShaderStage p_stage) const {
ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String());
return source[p_stage];
}
void set_language(RD::ShaderLanguage p_language) {
language = p_language;
}
RD::ShaderLanguage get_language() const {
return language;
}
protected:
static void _bind_methods() {
ClassDB::bind_method(D_METHOD("set_stage_source", "stage", "source"), &RDShaderSource::set_stage_source);
ClassDB::bind_method(D_METHOD("get_stage_source", "stage"), &RDShaderSource::get_stage_source);
ClassDB::bind_method(D_METHOD("set_language", "language"), &RDShaderSource::set_language);
ClassDB::bind_method(D_METHOD("get_language"), &RDShaderSource::get_language);
ADD_GROUP("Source", "source_");
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_vertex"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_VERTEX);
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_fragment"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_FRAGMENT);
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_control"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_CONTROL);
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_evaluation"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_EVALUATION);
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_compute"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_COMPUTE);
ADD_GROUP("Syntax", "source_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "language", PROPERTY_HINT_RANGE, "GLSL,HLSL"), "set_language", "get_language");
}
};
class RDShaderBytecode : public Resource {
GDCLASS(RDShaderBytecode, Resource)
Vector<uint8_t> bytecode[RD::SHADER_STAGE_MAX];
String compile_error[RD::SHADER_STAGE_MAX];
public:
void set_stage_bytecode(RD::ShaderStage p_stage, const Vector<uint8_t> &p_bytecode) {
ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);
bytecode[p_stage] = p_bytecode;
}
Vector<uint8_t> get_stage_bytecode(RD::ShaderStage p_stage) const {
ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, Vector<uint8_t>());
return bytecode[p_stage];
}
void set_stage_compile_error(RD::ShaderStage p_stage, const String &p_compile_error) {
ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);
compile_error[p_stage] = p_compile_error;
}
String get_stage_compile_error(RD::ShaderStage p_stage) const {
ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String());
return compile_error[p_stage];
}
protected:
static void _bind_methods() {
ClassDB::bind_method(D_METHOD("set_stage_bytecode", "stage", "bytecode"), &RDShaderBytecode::set_stage_bytecode);
ClassDB::bind_method(D_METHOD("get_stage_bytecode", "stage"), &RDShaderBytecode::get_stage_bytecode);
ClassDB::bind_method(D_METHOD("set_stage_compile_error", "stage", "compile_error"), &RDShaderBytecode::set_stage_compile_error);
ClassDB::bind_method(D_METHOD("get_stage_compile_error", "stage"), &RDShaderBytecode::get_stage_compile_error);
ADD_GROUP("Bytecode", "bytecode_");
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_vertex"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_VERTEX);
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_fragment"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_FRAGMENT);
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_control"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_CONTROL);
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_evaluation"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_EVALUATION);
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_compute"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_COMPUTE);
ADD_GROUP("Compile Error", "compile_error_");
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_vertex"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_VERTEX);
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_fragment"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_FRAGMENT);
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_control"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_CONTROL);
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_evaluation"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_EVALUATION);
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_compute"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_COMPUTE);
}
};
class RDShaderFile : public Resource {
GDCLASS(RDShaderFile, Resource)
Map<StringName, Ref<RDShaderBytecode>> versions;
String base_error;
public:
void set_bytecode(const Ref<RDShaderBytecode> &p_bytecode, const StringName &p_version = StringName()) {
ERR_FAIL_COND(p_bytecode.is_null());
versions[p_version] = p_bytecode;
emit_changed();
}
Ref<RDShaderBytecode> get_bytecode(const StringName &p_version = StringName()) const {
ERR_FAIL_COND_V(!versions.has(p_version), Ref<RDShaderBytecode>());
return versions[p_version];
}
Vector<StringName> get_version_list() const {
Vector<StringName> vnames;
for (Map<StringName, Ref<RDShaderBytecode>>::Element *E = versions.front(); E; E = E->next()) {
vnames.push_back(E->key());
}
vnames.sort_custom<StringName::AlphCompare>();
return vnames;
}
void set_base_error(const String &p_error) {
base_error = p_error;
emit_changed();
}
String get_base_error() const {
return base_error;
}
void print_errors(const String &p_file) {
if (base_error != "") {
ERR_PRINT("Error parsing shader '" + p_file + "':\n\n" + base_error);
} else {
for (Map<StringName, Ref<RDShaderBytecode>>::Element *E = versions.front(); E; E = E->next()) {
for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {
String error = E->get()->get_stage_compile_error(RD::ShaderStage(i));
if (error != String()) {
static const char *stage_str[RD::SHADER_STAGE_MAX] = {
"vertex",
"fragment",
"tesselation_control",
"tesselation_evaluation",
"compute"
};
ERR_PRINT("Error parsing shader '" + p_file + "', version '" + String(E->key()) + "', stage '" + stage_str[i] + "':\n\n" + error);
}
}
}
}
}
typedef String (*OpenIncludeFunction)(const String &, void *userdata);
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);
protected:
Dictionary _get_versions() const {
Vector<StringName> vnames = get_version_list();
Dictionary ret;
for (int i = 0; i < vnames.size(); i++) {
ret[vnames[i]] = versions[vnames[i]];
}
return ret;
}
void _set_versions(const Dictionary &p_versions) {
versions.clear();
List<Variant> keys;
p_versions.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
StringName name = E->get();
Ref<RDShaderBytecode> bc = p_versions[E->get()];
ERR_CONTINUE(bc.is_null());
versions[name] = bc;
}
emit_changed();
}
static void _bind_methods() {
ClassDB::bind_method(D_METHOD("set_bytecode", "bytecode", "version"), &RDShaderFile::set_bytecode, DEFVAL(StringName()));
ClassDB::bind_method(D_METHOD("get_bytecode", "version"), &RDShaderFile::get_bytecode, DEFVAL(StringName()));
ClassDB::bind_method(D_METHOD("get_version_list"), &RDShaderFile::get_version_list);
ClassDB::bind_method(D_METHOD("set_base_error", "error"), &RDShaderFile::set_base_error);
ClassDB::bind_method(D_METHOD("get_base_error"), &RDShaderFile::get_base_error);
ClassDB::bind_method(D_METHOD("_set_versions", "versions"), &RDShaderFile::_set_versions);
ClassDB::bind_method(D_METHOD("_get_versions"), &RDShaderFile::_get_versions);
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_versions", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_versions", "_get_versions");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_error"), "set_base_error", "get_base_error");
}
};
class RDUniform : public Reference {
GDCLASS(RDUniform, Reference)
friend class RenderingDevice;
RD::Uniform base;
public:
RD_SETGET(RD::UniformType, type)
RD_SETGET(int32_t, binding)
void add_id(const RID &p_id) { base.ids.push_back(p_id); }
void clear_ids() { base.ids.clear(); }
Array get_ids() const {
Array ids;
for (int i = 0; i < base.ids.size(); i++) {
ids.push_back(base.ids[i]);
}
return ids;
}
protected:
void _set_ids(const Array &p_ids) {
base.ids.clear();
for (int i = 0; i < p_ids.size(); i++) {
RID id = p_ids[i];
ERR_FAIL_COND(id.is_null());
base.ids.push_back(id);
}
}
static void _bind_methods() {
RD_BIND(Variant::INT, RDUniform, type);
RD_BIND(Variant::INT, RDUniform, binding);
ClassDB::bind_method(D_METHOD("add_id", "id"), &RDUniform::add_id);
ClassDB::bind_method(D_METHOD("clear_ids"), &RDUniform::clear_ids);
ClassDB::bind_method(D_METHOD("_set_ids", "ids"), &RDUniform::_set_ids);
ClassDB::bind_method(D_METHOD("get_ids"), &RDUniform::get_ids);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_ids", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_ids", "get_ids");
}
};
class RDPipelineRasterizationState : public Reference {
GDCLASS(RDPipelineRasterizationState, Reference)
friend class RenderingDevice;
RD::PipelineRasterizationState base;
public:
RD_SETGET(bool, enable_depth_clamp)
RD_SETGET(bool, discard_primitives)
RD_SETGET(bool, wireframe)
RD_SETGET(RD::PolygonCullMode, cull_mode)
RD_SETGET(RD::PolygonFrontFace, front_face)
RD_SETGET(bool, depth_bias_enable)
RD_SETGET(float, depth_bias_constant_factor)
RD_SETGET(float, depth_bias_clamp)
RD_SETGET(float, depth_bias_slope_factor)
RD_SETGET(float, line_width)
RD_SETGET(uint32_t, patch_control_points)
protected:
static void _bind_methods() {
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, enable_depth_clamp);
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, discard_primitives);
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, wireframe);
RD_BIND(Variant::INT, RDPipelineRasterizationState, cull_mode);
RD_BIND(Variant::INT, RDPipelineRasterizationState, front_face);
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, depth_bias_enable);
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_constant_factor);
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_clamp);
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_slope_factor);
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, line_width);
RD_BIND(Variant::INT, RDPipelineRasterizationState, patch_control_points);
}
};
class RDPipelineMultisampleState : public Reference {
GDCLASS(RDPipelineMultisampleState, Reference)
friend class RenderingDevice;
RD::PipelineMultisampleState base;
TypedArray<int64_t> sample_masks;
public:
RD_SETGET(RD::TextureSamples, sample_count)
RD_SETGET(bool, enable_sample_shading)
RD_SETGET(float, min_sample_shading)
RD_SETGET(bool, enable_alpha_to_coverage)
RD_SETGET(bool, enable_alpha_to_one)
void set_sample_masks(const TypedArray<int64_t> &p_masks) { sample_masks = p_masks; }
TypedArray<int64_t> get_sample_masks() const { return sample_masks; }
protected:
static void _bind_methods() {
RD_BIND(Variant::INT, RDPipelineMultisampleState, sample_count);
RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_sample_shading);
RD_BIND(Variant::FLOAT, RDPipelineMultisampleState, min_sample_shading);
RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_coverage);
RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_one);
ClassDB::bind_method(D_METHOD("set_sample_masks", "masks"), &RDPipelineMultisampleState::set_sample_masks);
ClassDB::bind_method(D_METHOD("get_sample_masks"), &RDPipelineMultisampleState::get_sample_masks);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "sample_masks", PROPERTY_HINT_ARRAY_TYPE, "int"), "set_sample_masks", "get_sample_masks");
}
};
class RDPipelineDepthStencilState : public Reference {
GDCLASS(RDPipelineDepthStencilState, Reference)
friend class RenderingDevice;
RD::PipelineDepthStencilState base;
public:
RD_SETGET(bool, enable_depth_test)
RD_SETGET(bool, enable_depth_write)
RD_SETGET(RD::CompareOperator, depth_compare_operator)
RD_SETGET(bool, enable_depth_range)
RD_SETGET(float, depth_range_min)
RD_SETGET(float, depth_range_max)
RD_SETGET(bool, enable_stencil)
RD_SETGET_SUB(RD::StencilOperation, front_op, fail)
RD_SETGET_SUB(RD::StencilOperation, front_op, pass)
RD_SETGET_SUB(RD::StencilOperation, front_op, depth_fail)
RD_SETGET_SUB(RD::CompareOperator, front_op, compare)
RD_SETGET_SUB(uint32_t, front_op, compare_mask)
RD_SETGET_SUB(uint32_t, front_op, write_mask)
RD_SETGET_SUB(uint32_t, front_op, reference)
RD_SETGET_SUB(RD::StencilOperation, back_op, fail)
RD_SETGET_SUB(RD::StencilOperation, back_op, pass)
RD_SETGET_SUB(RD::StencilOperation, back_op, depth_fail)
RD_SETGET_SUB(RD::CompareOperator, back_op, compare)
RD_SETGET_SUB(uint32_t, back_op, compare_mask)
RD_SETGET_SUB(uint32_t, back_op, write_mask)
RD_SETGET_SUB(uint32_t, back_op, reference)
protected:
static void _bind_methods() {
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_test);
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_write);
RD_BIND(Variant::INT, RDPipelineDepthStencilState, depth_compare_operator);
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_range);
RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_min);
RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_max);
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_stencil);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, fail);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, pass);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, depth_fail);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare_mask);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, write_mask);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, reference);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, fail);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, pass);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, depth_fail);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare_mask);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, write_mask);
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, reference);
}
};
class RDPipelineColorBlendStateAttachment : public Reference {
GDCLASS(RDPipelineColorBlendStateAttachment, Reference)
friend class RenderingDevice;
RD::PipelineColorBlendState::Attachment base;
public:
RD_SETGET(bool, enable_blend)
RD_SETGET(RD::BlendFactor, src_color_blend_factor)
RD_SETGET(RD::BlendFactor, dst_color_blend_factor)
RD_SETGET(RD::BlendOperation, color_blend_op)
RD_SETGET(RD::BlendFactor, src_alpha_blend_factor)
RD_SETGET(RD::BlendFactor, dst_alpha_blend_factor)
RD_SETGET(RD::BlendOperation, alpha_blend_op)
RD_SETGET(bool, write_r)
RD_SETGET(bool, write_g)
RD_SETGET(bool, write_b)
RD_SETGET(bool, write_a)
void set_as_mix() {
base = RD::PipelineColorBlendState::Attachment();
base.enable_blend = true;
base.src_color_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
base.dst_color_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
base.src_alpha_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
base.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
}
protected:
static void _bind_methods() {
ClassDB::bind_method(D_METHOD("set_as_mix"), &RDPipelineColorBlendStateAttachment::set_as_mix);
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, enable_blend);
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_color_blend_factor);
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_color_blend_factor);
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, color_blend_op);
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_alpha_blend_factor);
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_alpha_blend_factor);
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, alpha_blend_op);
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_r);
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_g);
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_b);
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_a);
}
};
class RDPipelineColorBlendState : public Reference {
GDCLASS(RDPipelineColorBlendState, Reference)
friend class RenderingDevice;
RD::PipelineColorBlendState base;
TypedArray<RDPipelineColorBlendStateAttachment> attachments;
public:
RD_SETGET(bool, enable_logic_op)
RD_SETGET(RD::LogicOperation, logic_op)
RD_SETGET(Color, blend_constant)
void set_attachments(const TypedArray<RDPipelineColorBlendStateAttachment> &p_attachments) {
attachments.push_back(p_attachments);
}
TypedArray<RDPipelineColorBlendStateAttachment> get_attachments() const {
return attachments;
}
protected:
static void _bind_methods() {
RD_BIND(Variant::BOOL, RDPipelineColorBlendState, enable_logic_op);
RD_BIND(Variant::INT, RDPipelineColorBlendState, logic_op);
RD_BIND(Variant::COLOR, RDPipelineColorBlendState, blend_constant);
ClassDB::bind_method(D_METHOD("set_attachments", "atachments"), &RDPipelineColorBlendState::set_attachments);
ClassDB::bind_method(D_METHOD("get_attachments"), &RDPipelineColorBlendState::get_attachments);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "attachments", PROPERTY_HINT_ARRAY_TYPE, "RDPipelineColorBlendStateAttachment"), "set_attachments", "get_attachments");
}
};
#endif // RENDERING_DEVICE_BINDS_H
|