Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/rendering_device_binds.h
10277 views
1
/**************************************************************************/
2
/* rendering_device_binds.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 "servers/rendering/rendering_device.h"
34
35
#define RD_SETGET(m_type, m_member) \
36
void set_##m_member(m_type p_##m_member) { \
37
base.m_member = p_##m_member; \
38
} \
39
m_type get_##m_member() const { \
40
return base.m_member; \
41
}
42
43
#define RD_BIND(m_variant_type, m_class, m_member) \
44
ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_member); \
45
ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_member)), &m_class::get_##m_member); \
46
ADD_PROPERTY(PropertyInfo(m_variant_type, #m_member), "set_" _MKSTR(m_member), "get_" _MKSTR(m_member))
47
48
#define RD_SETGET_SUB(m_type, m_sub, m_member) \
49
void set_##m_sub##_##m_member(m_type p_##m_member) { \
50
base.m_sub.m_member = p_##m_member; \
51
} \
52
m_type get_##m_sub##_##m_member() const { \
53
return base.m_sub.m_member; \
54
}
55
56
#define RD_BIND_SUB(m_variant_type, m_class, m_sub, m_member) \
57
ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_sub) "_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_sub##_##m_member); \
58
ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_sub) "_" _MKSTR(m_member)), &m_class::get_##m_sub##_##m_member); \
59
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))
60
61
class RDTextureFormat : public RefCounted {
62
GDCLASS(RDTextureFormat, RefCounted)
63
64
friend class RenderingDevice;
65
friend class RenderSceneBuffersRD;
66
67
RD::TextureFormat base;
68
69
public:
70
RD_SETGET(RD::DataFormat, format)
71
RD_SETGET(uint32_t, width)
72
RD_SETGET(uint32_t, height)
73
RD_SETGET(uint32_t, depth)
74
RD_SETGET(uint32_t, array_layers)
75
RD_SETGET(uint32_t, mipmaps)
76
RD_SETGET(RD::TextureType, texture_type)
77
RD_SETGET(RD::TextureSamples, samples)
78
RD_SETGET(BitField<RenderingDevice::TextureUsageBits>, usage_bits)
79
RD_SETGET(bool, is_resolve_buffer)
80
RD_SETGET(bool, is_discardable)
81
82
void add_shareable_format(RD::DataFormat p_format) { base.shareable_formats.push_back(p_format); }
83
void remove_shareable_format(RD::DataFormat p_format) { base.shareable_formats.erase(p_format); }
84
85
protected:
86
static void _bind_methods() {
87
RD_BIND(Variant::INT, RDTextureFormat, format);
88
RD_BIND(Variant::INT, RDTextureFormat, width);
89
RD_BIND(Variant::INT, RDTextureFormat, height);
90
RD_BIND(Variant::INT, RDTextureFormat, depth);
91
RD_BIND(Variant::INT, RDTextureFormat, array_layers);
92
RD_BIND(Variant::INT, RDTextureFormat, mipmaps);
93
RD_BIND(Variant::INT, RDTextureFormat, texture_type);
94
RD_BIND(Variant::INT, RDTextureFormat, samples);
95
RD_BIND(Variant::INT, RDTextureFormat, usage_bits);
96
RD_BIND(Variant::BOOL, RDTextureFormat, is_resolve_buffer);
97
RD_BIND(Variant::BOOL, RDTextureFormat, is_discardable);
98
99
ClassDB::bind_method(D_METHOD("add_shareable_format", "format"), &RDTextureFormat::add_shareable_format);
100
ClassDB::bind_method(D_METHOD("remove_shareable_format", "format"), &RDTextureFormat::remove_shareable_format);
101
}
102
};
103
104
class RDTextureView : public RefCounted {
105
GDCLASS(RDTextureView, RefCounted)
106
107
friend class RenderingDevice;
108
friend class RenderSceneBuffersRD;
109
110
RD::TextureView base;
111
112
public:
113
RD_SETGET(RD::DataFormat, format_override)
114
RD_SETGET(RD::TextureSwizzle, swizzle_r)
115
RD_SETGET(RD::TextureSwizzle, swizzle_g)
116
RD_SETGET(RD::TextureSwizzle, swizzle_b)
117
RD_SETGET(RD::TextureSwizzle, swizzle_a)
118
protected:
119
static void _bind_methods() {
120
RD_BIND(Variant::INT, RDTextureView, format_override);
121
RD_BIND(Variant::INT, RDTextureView, swizzle_r);
122
RD_BIND(Variant::INT, RDTextureView, swizzle_g);
123
RD_BIND(Variant::INT, RDTextureView, swizzle_b);
124
RD_BIND(Variant::INT, RDTextureView, swizzle_a);
125
}
126
};
127
128
class RDAttachmentFormat : public RefCounted {
129
GDCLASS(RDAttachmentFormat, RefCounted)
130
friend class RenderingDevice;
131
132
RD::AttachmentFormat base;
133
134
public:
135
RD_SETGET(RD::DataFormat, format)
136
RD_SETGET(RD::TextureSamples, samples)
137
RD_SETGET(uint32_t, usage_flags)
138
protected:
139
static void _bind_methods() {
140
RD_BIND(Variant::INT, RDAttachmentFormat, format);
141
RD_BIND(Variant::INT, RDAttachmentFormat, samples);
142
RD_BIND(Variant::INT, RDAttachmentFormat, usage_flags);
143
}
144
};
145
146
class RDFramebufferPass : public RefCounted {
147
GDCLASS(RDFramebufferPass, RefCounted)
148
friend class RenderingDevice;
149
friend class FramebufferCacheRD;
150
151
RD::FramebufferPass base;
152
153
public:
154
RD_SETGET(PackedInt32Array, color_attachments)
155
RD_SETGET(PackedInt32Array, input_attachments)
156
RD_SETGET(PackedInt32Array, resolve_attachments)
157
RD_SETGET(PackedInt32Array, preserve_attachments)
158
RD_SETGET(int32_t, depth_attachment)
159
protected:
160
enum {
161
ATTACHMENT_UNUSED = -1
162
};
163
164
static void _bind_methods() {
165
RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, color_attachments);
166
RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, input_attachments);
167
RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, resolve_attachments);
168
RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, preserve_attachments);
169
RD_BIND(Variant::INT, RDFramebufferPass, depth_attachment);
170
171
BIND_CONSTANT(ATTACHMENT_UNUSED);
172
}
173
};
174
175
class RDSamplerState : public RefCounted {
176
GDCLASS(RDSamplerState, RefCounted)
177
friend class RenderingDevice;
178
179
RD::SamplerState base;
180
181
public:
182
RD_SETGET(RD::SamplerFilter, mag_filter)
183
RD_SETGET(RD::SamplerFilter, min_filter)
184
RD_SETGET(RD::SamplerFilter, mip_filter)
185
RD_SETGET(RD::SamplerRepeatMode, repeat_u)
186
RD_SETGET(RD::SamplerRepeatMode, repeat_v)
187
RD_SETGET(RD::SamplerRepeatMode, repeat_w)
188
RD_SETGET(float, lod_bias)
189
RD_SETGET(bool, use_anisotropy)
190
RD_SETGET(float, anisotropy_max)
191
RD_SETGET(bool, enable_compare)
192
RD_SETGET(RD::CompareOperator, compare_op)
193
RD_SETGET(float, min_lod)
194
RD_SETGET(float, max_lod)
195
RD_SETGET(RD::SamplerBorderColor, border_color)
196
RD_SETGET(bool, unnormalized_uvw)
197
198
protected:
199
static void _bind_methods() {
200
RD_BIND(Variant::INT, RDSamplerState, mag_filter);
201
RD_BIND(Variant::INT, RDSamplerState, min_filter);
202
RD_BIND(Variant::INT, RDSamplerState, mip_filter);
203
RD_BIND(Variant::INT, RDSamplerState, repeat_u);
204
RD_BIND(Variant::INT, RDSamplerState, repeat_v);
205
RD_BIND(Variant::INT, RDSamplerState, repeat_w);
206
RD_BIND(Variant::FLOAT, RDSamplerState, lod_bias);
207
RD_BIND(Variant::BOOL, RDSamplerState, use_anisotropy);
208
RD_BIND(Variant::FLOAT, RDSamplerState, anisotropy_max);
209
RD_BIND(Variant::BOOL, RDSamplerState, enable_compare);
210
RD_BIND(Variant::INT, RDSamplerState, compare_op);
211
RD_BIND(Variant::FLOAT, RDSamplerState, min_lod);
212
RD_BIND(Variant::FLOAT, RDSamplerState, max_lod);
213
RD_BIND(Variant::INT, RDSamplerState, border_color);
214
RD_BIND(Variant::BOOL, RDSamplerState, unnormalized_uvw);
215
}
216
};
217
218
class RDVertexAttribute : public RefCounted {
219
GDCLASS(RDVertexAttribute, RefCounted)
220
friend class RenderingDevice;
221
RD::VertexAttribute base;
222
223
public:
224
RD_SETGET(uint32_t, location)
225
RD_SETGET(uint32_t, offset)
226
RD_SETGET(RD::DataFormat, format)
227
RD_SETGET(uint32_t, stride)
228
RD_SETGET(RD::VertexFrequency, frequency)
229
230
protected:
231
static void _bind_methods() {
232
RD_BIND(Variant::INT, RDVertexAttribute, location);
233
RD_BIND(Variant::INT, RDVertexAttribute, offset);
234
RD_BIND(Variant::INT, RDVertexAttribute, format);
235
RD_BIND(Variant::INT, RDVertexAttribute, stride);
236
RD_BIND(Variant::INT, RDVertexAttribute, frequency);
237
}
238
};
239
class RDShaderSource : public RefCounted {
240
GDCLASS(RDShaderSource, RefCounted)
241
String source[RD::SHADER_STAGE_MAX];
242
RD::ShaderLanguage language = RD::SHADER_LANGUAGE_GLSL;
243
244
public:
245
void set_stage_source(RD::ShaderStage p_stage, const String &p_source) {
246
ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);
247
source[p_stage] = p_source;
248
}
249
250
String get_stage_source(RD::ShaderStage p_stage) const {
251
ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String());
252
return source[p_stage];
253
}
254
255
void set_language(RD::ShaderLanguage p_language) {
256
language = p_language;
257
}
258
259
RD::ShaderLanguage get_language() const {
260
return language;
261
}
262
263
protected:
264
static void _bind_methods() {
265
ClassDB::bind_method(D_METHOD("set_stage_source", "stage", "source"), &RDShaderSource::set_stage_source);
266
ClassDB::bind_method(D_METHOD("get_stage_source", "stage"), &RDShaderSource::get_stage_source);
267
268
ClassDB::bind_method(D_METHOD("set_language", "language"), &RDShaderSource::set_language);
269
ClassDB::bind_method(D_METHOD("get_language"), &RDShaderSource::get_language);
270
271
ADD_GROUP("Source", "source_");
272
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_vertex"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_VERTEX);
273
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_fragment"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_FRAGMENT);
274
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_control"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_CONTROL);
275
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_evaluation"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_EVALUATION);
276
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_compute"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_COMPUTE);
277
ADD_GROUP("Syntax", "source_");
278
ADD_PROPERTY(PropertyInfo(Variant::INT, "language", PROPERTY_HINT_RANGE, "GLSL,HLSL"), "set_language", "get_language");
279
}
280
};
281
282
class RDShaderSPIRV : public Resource {
283
GDCLASS(RDShaderSPIRV, Resource)
284
285
Vector<uint8_t> bytecode[RD::SHADER_STAGE_MAX];
286
String compile_error[RD::SHADER_STAGE_MAX];
287
288
public:
289
void set_stage_bytecode(RD::ShaderStage p_stage, const Vector<uint8_t> &p_bytecode) {
290
ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);
291
bytecode[p_stage] = p_bytecode;
292
}
293
294
Vector<uint8_t> get_stage_bytecode(RD::ShaderStage p_stage) const {
295
ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, Vector<uint8_t>());
296
return bytecode[p_stage];
297
}
298
299
Vector<RD::ShaderStageSPIRVData> get_stages() const {
300
Vector<RD::ShaderStageSPIRVData> stages;
301
for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {
302
if (bytecode[i].size()) {
303
RD::ShaderStageSPIRVData stage;
304
stage.shader_stage = RD::ShaderStage(i);
305
stage.spirv = bytecode[i];
306
stages.push_back(stage);
307
}
308
}
309
return stages;
310
}
311
312
void set_stage_compile_error(RD::ShaderStage p_stage, const String &p_compile_error) {
313
ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);
314
compile_error[p_stage] = p_compile_error;
315
}
316
317
String get_stage_compile_error(RD::ShaderStage p_stage) const {
318
ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String());
319
return compile_error[p_stage];
320
}
321
322
protected:
323
static void _bind_methods() {
324
ClassDB::bind_method(D_METHOD("set_stage_bytecode", "stage", "bytecode"), &RDShaderSPIRV::set_stage_bytecode);
325
ClassDB::bind_method(D_METHOD("get_stage_bytecode", "stage"), &RDShaderSPIRV::get_stage_bytecode);
326
327
ClassDB::bind_method(D_METHOD("set_stage_compile_error", "stage", "compile_error"), &RDShaderSPIRV::set_stage_compile_error);
328
ClassDB::bind_method(D_METHOD("get_stage_compile_error", "stage"), &RDShaderSPIRV::get_stage_compile_error);
329
330
ADD_GROUP("Bytecode", "bytecode_");
331
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_vertex"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_VERTEX);
332
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_fragment"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_FRAGMENT);
333
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_control"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_CONTROL);
334
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_evaluation"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_EVALUATION);
335
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_compute"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_COMPUTE);
336
ADD_GROUP("Compile Error", "compile_error_");
337
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_vertex"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_VERTEX);
338
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_fragment"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_FRAGMENT);
339
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_control"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_CONTROL);
340
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_evaluation"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_EVALUATION);
341
ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_compute"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_COMPUTE);
342
}
343
};
344
345
class RDShaderFile : public Resource {
346
GDCLASS(RDShaderFile, Resource)
347
348
HashMap<StringName, Ref<RDShaderSPIRV>> versions;
349
String base_error;
350
351
public:
352
void set_bytecode(const Ref<RDShaderSPIRV> &p_bytecode, const StringName &p_version = StringName()) {
353
ERR_FAIL_COND(p_bytecode.is_null());
354
versions[p_version] = p_bytecode;
355
emit_changed();
356
}
357
358
Ref<RDShaderSPIRV> get_spirv(const StringName &p_version = StringName()) const {
359
ERR_FAIL_COND_V(!versions.has(p_version), Ref<RDShaderSPIRV>());
360
return versions[p_version];
361
}
362
363
Vector<RD::ShaderStageSPIRVData> get_spirv_stages(const StringName &p_version = StringName()) const {
364
ERR_FAIL_COND_V(!versions.has(p_version), Vector<RD::ShaderStageSPIRVData>());
365
return versions[p_version]->get_stages();
366
}
367
368
TypedArray<StringName> get_version_list() const {
369
Vector<StringName> vnames;
370
for (const KeyValue<StringName, Ref<RDShaderSPIRV>> &E : versions) {
371
vnames.push_back(E.key);
372
}
373
vnames.sort_custom<StringName::AlphCompare>();
374
TypedArray<StringName> ret;
375
ret.resize(vnames.size());
376
for (int i = 0; i < vnames.size(); i++) {
377
ret[i] = vnames[i];
378
}
379
return ret;
380
}
381
382
void set_base_error(const String &p_error) {
383
base_error = p_error;
384
emit_changed();
385
}
386
387
String get_base_error() const {
388
return base_error;
389
}
390
391
void print_errors(const String &p_file) {
392
if (!base_error.is_empty()) {
393
ERR_PRINT("Error parsing shader '" + p_file + "':\n\n" + base_error);
394
} else {
395
for (KeyValue<StringName, Ref<RDShaderSPIRV>> &E : versions) {
396
for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {
397
String error = E.value->get_stage_compile_error(RD::ShaderStage(i));
398
if (!error.is_empty()) {
399
static const char *stage_str[RD::SHADER_STAGE_MAX] = {
400
"vertex",
401
"fragment",
402
"tesselation_control",
403
"tesselation_evaluation",
404
"compute"
405
};
406
407
print_error("Error parsing shader '" + p_file + "', version '" + String(E.key) + "', stage '" + stage_str[i] + "':\n\n" + error);
408
}
409
}
410
}
411
}
412
}
413
414
typedef String (*OpenIncludeFunction)(const String &, void *userdata);
415
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);
416
417
protected:
418
Dictionary _get_versions() const {
419
TypedArray<StringName> vnames = get_version_list();
420
Dictionary ret;
421
for (int i = 0; i < vnames.size(); i++) {
422
ret[vnames[i]] = versions[vnames[i]];
423
}
424
return ret;
425
}
426
void _set_versions(const Dictionary &p_versions) {
427
versions.clear();
428
for (const KeyValue<Variant, Variant> &kv : p_versions) {
429
StringName vname = kv.key;
430
Ref<RDShaderSPIRV> bc = kv.value;
431
ERR_CONTINUE(bc.is_null());
432
versions[vname] = bc;
433
}
434
435
emit_changed();
436
}
437
438
static void _bind_methods() {
439
ClassDB::bind_method(D_METHOD("set_bytecode", "bytecode", "version"), &RDShaderFile::set_bytecode, DEFVAL(StringName()));
440
ClassDB::bind_method(D_METHOD("get_spirv", "version"), &RDShaderFile::get_spirv, DEFVAL(StringName()));
441
ClassDB::bind_method(D_METHOD("get_version_list"), &RDShaderFile::get_version_list);
442
443
ClassDB::bind_method(D_METHOD("set_base_error", "error"), &RDShaderFile::set_base_error);
444
ClassDB::bind_method(D_METHOD("get_base_error"), &RDShaderFile::get_base_error);
445
446
ClassDB::bind_method(D_METHOD("_set_versions", "versions"), &RDShaderFile::_set_versions);
447
ClassDB::bind_method(D_METHOD("_get_versions"), &RDShaderFile::_get_versions);
448
449
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_versions", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_versions", "_get_versions");
450
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_error"), "set_base_error", "get_base_error");
451
}
452
};
453
454
class RDUniform : public RefCounted {
455
GDCLASS(RDUniform, RefCounted)
456
friend class RenderingDevice;
457
friend class UniformSetCacheRD;
458
RD::Uniform base;
459
460
public:
461
RD_SETGET(RD::UniformType, uniform_type)
462
RD_SETGET(int32_t, binding)
463
464
void add_id(const RID &p_id) { base.append_id(p_id); }
465
void clear_ids() { base.clear_ids(); }
466
TypedArray<RID> get_ids() const {
467
TypedArray<RID> ids;
468
for (uint32_t i = 0; i < base.get_id_count(); i++) {
469
ids.push_back(base.get_id(i));
470
}
471
return ids;
472
}
473
474
protected:
475
void _set_ids(const TypedArray<RID> &p_ids) {
476
base.clear_ids();
477
for (int i = 0; i < p_ids.size(); i++) {
478
RID id = p_ids[i];
479
ERR_FAIL_COND(id.is_null());
480
base.append_id(id);
481
}
482
}
483
static void _bind_methods() {
484
RD_BIND(Variant::INT, RDUniform, uniform_type);
485
RD_BIND(Variant::INT, RDUniform, binding);
486
ClassDB::bind_method(D_METHOD("add_id", "id"), &RDUniform::add_id);
487
ClassDB::bind_method(D_METHOD("clear_ids"), &RDUniform::clear_ids);
488
ClassDB::bind_method(D_METHOD("_set_ids", "ids"), &RDUniform::_set_ids);
489
ClassDB::bind_method(D_METHOD("get_ids"), &RDUniform::get_ids);
490
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_ids", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_ids", "get_ids");
491
}
492
};
493
494
class RDPipelineSpecializationConstant : public RefCounted {
495
GDCLASS(RDPipelineSpecializationConstant, RefCounted)
496
friend class RenderingDevice;
497
498
Variant value = false;
499
uint32_t constant_id = 0;
500
501
public:
502
void set_value(const Variant &p_value) {
503
ERR_FAIL_COND(p_value.get_type() != Variant::BOOL && p_value.get_type() != Variant::INT && p_value.get_type() != Variant::FLOAT);
504
value = p_value;
505
}
506
Variant get_value() const { return value; }
507
508
void set_constant_id(uint32_t p_id) {
509
constant_id = p_id;
510
}
511
uint32_t get_constant_id() const {
512
return constant_id;
513
}
514
515
protected:
516
static void _bind_methods() {
517
ClassDB::bind_method(D_METHOD("set_value", "value"), &RDPipelineSpecializationConstant::set_value);
518
ClassDB::bind_method(D_METHOD("get_value"), &RDPipelineSpecializationConstant::get_value);
519
520
ClassDB::bind_method(D_METHOD("set_constant_id", "constant_id"), &RDPipelineSpecializationConstant::set_constant_id);
521
ClassDB::bind_method(D_METHOD("get_constant_id"), &RDPipelineSpecializationConstant::get_constant_id);
522
523
ADD_PROPERTY(PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_value", "get_value");
524
ADD_PROPERTY(PropertyInfo(Variant::INT, "constant_id", PROPERTY_HINT_RANGE, "0,65535,0"), "set_constant_id", "get_constant_id");
525
}
526
};
527
528
class RDPipelineRasterizationState : public RefCounted {
529
GDCLASS(RDPipelineRasterizationState, RefCounted)
530
friend class RenderingDevice;
531
532
RD::PipelineRasterizationState base;
533
534
public:
535
RD_SETGET(bool, enable_depth_clamp)
536
RD_SETGET(bool, discard_primitives)
537
RD_SETGET(bool, wireframe)
538
RD_SETGET(RD::PolygonCullMode, cull_mode)
539
RD_SETGET(RD::PolygonFrontFace, front_face)
540
RD_SETGET(bool, depth_bias_enabled)
541
RD_SETGET(float, depth_bias_constant_factor)
542
RD_SETGET(float, depth_bias_clamp)
543
RD_SETGET(float, depth_bias_slope_factor)
544
RD_SETGET(float, line_width)
545
RD_SETGET(uint32_t, patch_control_points)
546
547
protected:
548
static void _bind_methods() {
549
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, enable_depth_clamp);
550
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, discard_primitives);
551
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, wireframe);
552
RD_BIND(Variant::INT, RDPipelineRasterizationState, cull_mode);
553
RD_BIND(Variant::INT, RDPipelineRasterizationState, front_face);
554
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, depth_bias_enabled);
555
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_constant_factor);
556
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_clamp);
557
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_slope_factor);
558
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, line_width);
559
RD_BIND(Variant::INT, RDPipelineRasterizationState, patch_control_points);
560
}
561
};
562
563
class RDPipelineMultisampleState : public RefCounted {
564
GDCLASS(RDPipelineMultisampleState, RefCounted)
565
friend class RenderingDevice;
566
567
RD::PipelineMultisampleState base;
568
TypedArray<int64_t> sample_masks;
569
570
public:
571
RD_SETGET(RD::TextureSamples, sample_count)
572
RD_SETGET(bool, enable_sample_shading)
573
RD_SETGET(float, min_sample_shading)
574
RD_SETGET(bool, enable_alpha_to_coverage)
575
RD_SETGET(bool, enable_alpha_to_one)
576
577
void set_sample_masks(const TypedArray<int64_t> &p_masks) { sample_masks = p_masks; }
578
TypedArray<int64_t> get_sample_masks() const { return sample_masks; }
579
580
protected:
581
static void _bind_methods() {
582
RD_BIND(Variant::INT, RDPipelineMultisampleState, sample_count);
583
RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_sample_shading);
584
RD_BIND(Variant::FLOAT, RDPipelineMultisampleState, min_sample_shading);
585
RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_coverage);
586
RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_one);
587
588
ClassDB::bind_method(D_METHOD("set_sample_masks", "masks"), &RDPipelineMultisampleState::set_sample_masks);
589
ClassDB::bind_method(D_METHOD("get_sample_masks"), &RDPipelineMultisampleState::get_sample_masks);
590
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "sample_masks", PROPERTY_HINT_ARRAY_TYPE, "int"), "set_sample_masks", "get_sample_masks");
591
}
592
};
593
594
class RDPipelineDepthStencilState : public RefCounted {
595
GDCLASS(RDPipelineDepthStencilState, RefCounted)
596
friend class RenderingDevice;
597
598
RD::PipelineDepthStencilState base;
599
600
public:
601
RD_SETGET(bool, enable_depth_test)
602
RD_SETGET(bool, enable_depth_write)
603
RD_SETGET(RD::CompareOperator, depth_compare_operator)
604
RD_SETGET(bool, enable_depth_range)
605
RD_SETGET(float, depth_range_min)
606
RD_SETGET(float, depth_range_max)
607
RD_SETGET(bool, enable_stencil)
608
609
RD_SETGET_SUB(RD::StencilOperation, front_op, fail)
610
RD_SETGET_SUB(RD::StencilOperation, front_op, pass)
611
RD_SETGET_SUB(RD::StencilOperation, front_op, depth_fail)
612
RD_SETGET_SUB(RD::CompareOperator, front_op, compare)
613
RD_SETGET_SUB(uint32_t, front_op, compare_mask)
614
RD_SETGET_SUB(uint32_t, front_op, write_mask)
615
RD_SETGET_SUB(uint32_t, front_op, reference)
616
617
RD_SETGET_SUB(RD::StencilOperation, back_op, fail)
618
RD_SETGET_SUB(RD::StencilOperation, back_op, pass)
619
RD_SETGET_SUB(RD::StencilOperation, back_op, depth_fail)
620
RD_SETGET_SUB(RD::CompareOperator, back_op, compare)
621
RD_SETGET_SUB(uint32_t, back_op, compare_mask)
622
RD_SETGET_SUB(uint32_t, back_op, write_mask)
623
RD_SETGET_SUB(uint32_t, back_op, reference)
624
625
protected:
626
static void _bind_methods() {
627
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_test);
628
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_write);
629
RD_BIND(Variant::INT, RDPipelineDepthStencilState, depth_compare_operator);
630
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_range);
631
RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_min);
632
RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_max);
633
RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_stencil);
634
635
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, fail);
636
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, pass);
637
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, depth_fail);
638
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare);
639
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare_mask);
640
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, write_mask);
641
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, reference);
642
643
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, fail);
644
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, pass);
645
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, depth_fail);
646
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare);
647
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare_mask);
648
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, write_mask);
649
RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, reference);
650
}
651
};
652
653
class RDPipelineColorBlendStateAttachment : public RefCounted {
654
GDCLASS(RDPipelineColorBlendStateAttachment, RefCounted)
655
friend class RenderingDevice;
656
RD::PipelineColorBlendState::Attachment base;
657
658
public:
659
RD_SETGET(bool, enable_blend)
660
RD_SETGET(RD::BlendFactor, src_color_blend_factor)
661
RD_SETGET(RD::BlendFactor, dst_color_blend_factor)
662
RD_SETGET(RD::BlendOperation, color_blend_op)
663
RD_SETGET(RD::BlendFactor, src_alpha_blend_factor)
664
RD_SETGET(RD::BlendFactor, dst_alpha_blend_factor)
665
RD_SETGET(RD::BlendOperation, alpha_blend_op)
666
RD_SETGET(bool, write_r)
667
RD_SETGET(bool, write_g)
668
RD_SETGET(bool, write_b)
669
RD_SETGET(bool, write_a)
670
671
void set_as_mix() {
672
base = RD::PipelineColorBlendState::Attachment();
673
base.enable_blend = true;
674
base.src_color_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
675
base.dst_color_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
676
base.src_alpha_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;
677
base.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
678
}
679
680
protected:
681
static void _bind_methods() {
682
ClassDB::bind_method(D_METHOD("set_as_mix"), &RDPipelineColorBlendStateAttachment::set_as_mix);
683
684
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, enable_blend);
685
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_color_blend_factor);
686
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_color_blend_factor);
687
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, color_blend_op);
688
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_alpha_blend_factor);
689
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_alpha_blend_factor);
690
RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, alpha_blend_op);
691
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_r);
692
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_g);
693
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_b);
694
RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_a);
695
}
696
};
697
698
class RDPipelineColorBlendState : public RefCounted {
699
GDCLASS(RDPipelineColorBlendState, RefCounted)
700
friend class RenderingDevice;
701
RD::PipelineColorBlendState base;
702
703
TypedArray<RDPipelineColorBlendStateAttachment> attachments;
704
705
public:
706
RD_SETGET(bool, enable_logic_op)
707
RD_SETGET(RD::LogicOperation, logic_op)
708
RD_SETGET(Color, blend_constant)
709
710
void set_attachments(const TypedArray<RDPipelineColorBlendStateAttachment> &p_attachments) {
711
attachments = p_attachments;
712
}
713
714
TypedArray<RDPipelineColorBlendStateAttachment> get_attachments() const {
715
return attachments;
716
}
717
718
protected:
719
static void _bind_methods() {
720
RD_BIND(Variant::BOOL, RDPipelineColorBlendState, enable_logic_op);
721
RD_BIND(Variant::INT, RDPipelineColorBlendState, logic_op);
722
RD_BIND(Variant::COLOR, RDPipelineColorBlendState, blend_constant);
723
724
ClassDB::bind_method(D_METHOD("set_attachments", "attachments"), &RDPipelineColorBlendState::set_attachments);
725
ClassDB::bind_method(D_METHOD("get_attachments"), &RDPipelineColorBlendState::get_attachments);
726
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "attachments", PROPERTY_HINT_ARRAY_TYPE, "RDPipelineColorBlendStateAttachment"), "set_attachments", "get_attachments");
727
}
728
};
729
730