Path: blob/master/servers/rendering/rendering_device_binds.h
10277 views
/**************************************************************************/1/* rendering_device_binds.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "servers/rendering/rendering_device.h"3334#define RD_SETGET(m_type, m_member) \35void set_##m_member(m_type p_##m_member) { \36base.m_member = p_##m_member; \37} \38m_type get_##m_member() const { \39return base.m_member; \40}4142#define RD_BIND(m_variant_type, m_class, m_member) \43ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_member); \44ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_member)), &m_class::get_##m_member); \45ADD_PROPERTY(PropertyInfo(m_variant_type, #m_member), "set_" _MKSTR(m_member), "get_" _MKSTR(m_member))4647#define RD_SETGET_SUB(m_type, m_sub, m_member) \48void set_##m_sub##_##m_member(m_type p_##m_member) { \49base.m_sub.m_member = p_##m_member; \50} \51m_type get_##m_sub##_##m_member() const { \52return base.m_sub.m_member; \53}5455#define RD_BIND_SUB(m_variant_type, m_class, m_sub, m_member) \56ClassDB::bind_method(D_METHOD("set_" _MKSTR(m_sub) "_" _MKSTR(m_member), "p_" _MKSTR(member)), &m_class::set_##m_sub##_##m_member); \57ClassDB::bind_method(D_METHOD("get_" _MKSTR(m_sub) "_" _MKSTR(m_member)), &m_class::get_##m_sub##_##m_member); \58ADD_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))5960class RDTextureFormat : public RefCounted {61GDCLASS(RDTextureFormat, RefCounted)6263friend class RenderingDevice;64friend class RenderSceneBuffersRD;6566RD::TextureFormat base;6768public:69RD_SETGET(RD::DataFormat, format)70RD_SETGET(uint32_t, width)71RD_SETGET(uint32_t, height)72RD_SETGET(uint32_t, depth)73RD_SETGET(uint32_t, array_layers)74RD_SETGET(uint32_t, mipmaps)75RD_SETGET(RD::TextureType, texture_type)76RD_SETGET(RD::TextureSamples, samples)77RD_SETGET(BitField<RenderingDevice::TextureUsageBits>, usage_bits)78RD_SETGET(bool, is_resolve_buffer)79RD_SETGET(bool, is_discardable)8081void add_shareable_format(RD::DataFormat p_format) { base.shareable_formats.push_back(p_format); }82void remove_shareable_format(RD::DataFormat p_format) { base.shareable_formats.erase(p_format); }8384protected:85static void _bind_methods() {86RD_BIND(Variant::INT, RDTextureFormat, format);87RD_BIND(Variant::INT, RDTextureFormat, width);88RD_BIND(Variant::INT, RDTextureFormat, height);89RD_BIND(Variant::INT, RDTextureFormat, depth);90RD_BIND(Variant::INT, RDTextureFormat, array_layers);91RD_BIND(Variant::INT, RDTextureFormat, mipmaps);92RD_BIND(Variant::INT, RDTextureFormat, texture_type);93RD_BIND(Variant::INT, RDTextureFormat, samples);94RD_BIND(Variant::INT, RDTextureFormat, usage_bits);95RD_BIND(Variant::BOOL, RDTextureFormat, is_resolve_buffer);96RD_BIND(Variant::BOOL, RDTextureFormat, is_discardable);9798ClassDB::bind_method(D_METHOD("add_shareable_format", "format"), &RDTextureFormat::add_shareable_format);99ClassDB::bind_method(D_METHOD("remove_shareable_format", "format"), &RDTextureFormat::remove_shareable_format);100}101};102103class RDTextureView : public RefCounted {104GDCLASS(RDTextureView, RefCounted)105106friend class RenderingDevice;107friend class RenderSceneBuffersRD;108109RD::TextureView base;110111public:112RD_SETGET(RD::DataFormat, format_override)113RD_SETGET(RD::TextureSwizzle, swizzle_r)114RD_SETGET(RD::TextureSwizzle, swizzle_g)115RD_SETGET(RD::TextureSwizzle, swizzle_b)116RD_SETGET(RD::TextureSwizzle, swizzle_a)117protected:118static void _bind_methods() {119RD_BIND(Variant::INT, RDTextureView, format_override);120RD_BIND(Variant::INT, RDTextureView, swizzle_r);121RD_BIND(Variant::INT, RDTextureView, swizzle_g);122RD_BIND(Variant::INT, RDTextureView, swizzle_b);123RD_BIND(Variant::INT, RDTextureView, swizzle_a);124}125};126127class RDAttachmentFormat : public RefCounted {128GDCLASS(RDAttachmentFormat, RefCounted)129friend class RenderingDevice;130131RD::AttachmentFormat base;132133public:134RD_SETGET(RD::DataFormat, format)135RD_SETGET(RD::TextureSamples, samples)136RD_SETGET(uint32_t, usage_flags)137protected:138static void _bind_methods() {139RD_BIND(Variant::INT, RDAttachmentFormat, format);140RD_BIND(Variant::INT, RDAttachmentFormat, samples);141RD_BIND(Variant::INT, RDAttachmentFormat, usage_flags);142}143};144145class RDFramebufferPass : public RefCounted {146GDCLASS(RDFramebufferPass, RefCounted)147friend class RenderingDevice;148friend class FramebufferCacheRD;149150RD::FramebufferPass base;151152public:153RD_SETGET(PackedInt32Array, color_attachments)154RD_SETGET(PackedInt32Array, input_attachments)155RD_SETGET(PackedInt32Array, resolve_attachments)156RD_SETGET(PackedInt32Array, preserve_attachments)157RD_SETGET(int32_t, depth_attachment)158protected:159enum {160ATTACHMENT_UNUSED = -1161};162163static void _bind_methods() {164RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, color_attachments);165RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, input_attachments);166RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, resolve_attachments);167RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, preserve_attachments);168RD_BIND(Variant::INT, RDFramebufferPass, depth_attachment);169170BIND_CONSTANT(ATTACHMENT_UNUSED);171}172};173174class RDSamplerState : public RefCounted {175GDCLASS(RDSamplerState, RefCounted)176friend class RenderingDevice;177178RD::SamplerState base;179180public:181RD_SETGET(RD::SamplerFilter, mag_filter)182RD_SETGET(RD::SamplerFilter, min_filter)183RD_SETGET(RD::SamplerFilter, mip_filter)184RD_SETGET(RD::SamplerRepeatMode, repeat_u)185RD_SETGET(RD::SamplerRepeatMode, repeat_v)186RD_SETGET(RD::SamplerRepeatMode, repeat_w)187RD_SETGET(float, lod_bias)188RD_SETGET(bool, use_anisotropy)189RD_SETGET(float, anisotropy_max)190RD_SETGET(bool, enable_compare)191RD_SETGET(RD::CompareOperator, compare_op)192RD_SETGET(float, min_lod)193RD_SETGET(float, max_lod)194RD_SETGET(RD::SamplerBorderColor, border_color)195RD_SETGET(bool, unnormalized_uvw)196197protected:198static void _bind_methods() {199RD_BIND(Variant::INT, RDSamplerState, mag_filter);200RD_BIND(Variant::INT, RDSamplerState, min_filter);201RD_BIND(Variant::INT, RDSamplerState, mip_filter);202RD_BIND(Variant::INT, RDSamplerState, repeat_u);203RD_BIND(Variant::INT, RDSamplerState, repeat_v);204RD_BIND(Variant::INT, RDSamplerState, repeat_w);205RD_BIND(Variant::FLOAT, RDSamplerState, lod_bias);206RD_BIND(Variant::BOOL, RDSamplerState, use_anisotropy);207RD_BIND(Variant::FLOAT, RDSamplerState, anisotropy_max);208RD_BIND(Variant::BOOL, RDSamplerState, enable_compare);209RD_BIND(Variant::INT, RDSamplerState, compare_op);210RD_BIND(Variant::FLOAT, RDSamplerState, min_lod);211RD_BIND(Variant::FLOAT, RDSamplerState, max_lod);212RD_BIND(Variant::INT, RDSamplerState, border_color);213RD_BIND(Variant::BOOL, RDSamplerState, unnormalized_uvw);214}215};216217class RDVertexAttribute : public RefCounted {218GDCLASS(RDVertexAttribute, RefCounted)219friend class RenderingDevice;220RD::VertexAttribute base;221222public:223RD_SETGET(uint32_t, location)224RD_SETGET(uint32_t, offset)225RD_SETGET(RD::DataFormat, format)226RD_SETGET(uint32_t, stride)227RD_SETGET(RD::VertexFrequency, frequency)228229protected:230static void _bind_methods() {231RD_BIND(Variant::INT, RDVertexAttribute, location);232RD_BIND(Variant::INT, RDVertexAttribute, offset);233RD_BIND(Variant::INT, RDVertexAttribute, format);234RD_BIND(Variant::INT, RDVertexAttribute, stride);235RD_BIND(Variant::INT, RDVertexAttribute, frequency);236}237};238class RDShaderSource : public RefCounted {239GDCLASS(RDShaderSource, RefCounted)240String source[RD::SHADER_STAGE_MAX];241RD::ShaderLanguage language = RD::SHADER_LANGUAGE_GLSL;242243public:244void set_stage_source(RD::ShaderStage p_stage, const String &p_source) {245ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);246source[p_stage] = p_source;247}248249String get_stage_source(RD::ShaderStage p_stage) const {250ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String());251return source[p_stage];252}253254void set_language(RD::ShaderLanguage p_language) {255language = p_language;256}257258RD::ShaderLanguage get_language() const {259return language;260}261262protected:263static void _bind_methods() {264ClassDB::bind_method(D_METHOD("set_stage_source", "stage", "source"), &RDShaderSource::set_stage_source);265ClassDB::bind_method(D_METHOD("get_stage_source", "stage"), &RDShaderSource::get_stage_source);266267ClassDB::bind_method(D_METHOD("set_language", "language"), &RDShaderSource::set_language);268ClassDB::bind_method(D_METHOD("get_language"), &RDShaderSource::get_language);269270ADD_GROUP("Source", "source_");271ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_vertex"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_VERTEX);272ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_fragment"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_FRAGMENT);273ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_control"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_CONTROL);274ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_tesselation_evaluation"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_TESSELATION_EVALUATION);275ADD_PROPERTYI(PropertyInfo(Variant::STRING, "source_compute"), "set_stage_source", "get_stage_source", RD::SHADER_STAGE_COMPUTE);276ADD_GROUP("Syntax", "source_");277ADD_PROPERTY(PropertyInfo(Variant::INT, "language", PROPERTY_HINT_RANGE, "GLSL,HLSL"), "set_language", "get_language");278}279};280281class RDShaderSPIRV : public Resource {282GDCLASS(RDShaderSPIRV, Resource)283284Vector<uint8_t> bytecode[RD::SHADER_STAGE_MAX];285String compile_error[RD::SHADER_STAGE_MAX];286287public:288void set_stage_bytecode(RD::ShaderStage p_stage, const Vector<uint8_t> &p_bytecode) {289ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);290bytecode[p_stage] = p_bytecode;291}292293Vector<uint8_t> get_stage_bytecode(RD::ShaderStage p_stage) const {294ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, Vector<uint8_t>());295return bytecode[p_stage];296}297298Vector<RD::ShaderStageSPIRVData> get_stages() const {299Vector<RD::ShaderStageSPIRVData> stages;300for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {301if (bytecode[i].size()) {302RD::ShaderStageSPIRVData stage;303stage.shader_stage = RD::ShaderStage(i);304stage.spirv = bytecode[i];305stages.push_back(stage);306}307}308return stages;309}310311void set_stage_compile_error(RD::ShaderStage p_stage, const String &p_compile_error) {312ERR_FAIL_INDEX(p_stage, RD::SHADER_STAGE_MAX);313compile_error[p_stage] = p_compile_error;314}315316String get_stage_compile_error(RD::ShaderStage p_stage) const {317ERR_FAIL_INDEX_V(p_stage, RD::SHADER_STAGE_MAX, String());318return compile_error[p_stage];319}320321protected:322static void _bind_methods() {323ClassDB::bind_method(D_METHOD("set_stage_bytecode", "stage", "bytecode"), &RDShaderSPIRV::set_stage_bytecode);324ClassDB::bind_method(D_METHOD("get_stage_bytecode", "stage"), &RDShaderSPIRV::get_stage_bytecode);325326ClassDB::bind_method(D_METHOD("set_stage_compile_error", "stage", "compile_error"), &RDShaderSPIRV::set_stage_compile_error);327ClassDB::bind_method(D_METHOD("get_stage_compile_error", "stage"), &RDShaderSPIRV::get_stage_compile_error);328329ADD_GROUP("Bytecode", "bytecode_");330ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_vertex"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_VERTEX);331ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_fragment"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_FRAGMENT);332ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_control"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_CONTROL);333ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_tesselation_evaluation"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_TESSELATION_EVALUATION);334ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytecode_compute"), "set_stage_bytecode", "get_stage_bytecode", RD::SHADER_STAGE_COMPUTE);335ADD_GROUP("Compile Error", "compile_error_");336ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_vertex"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_VERTEX);337ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_fragment"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_FRAGMENT);338ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_control"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_CONTROL);339ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_tesselation_evaluation"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_TESSELATION_EVALUATION);340ADD_PROPERTYI(PropertyInfo(Variant::STRING, "compile_error_compute"), "set_stage_compile_error", "get_stage_compile_error", RD::SHADER_STAGE_COMPUTE);341}342};343344class RDShaderFile : public Resource {345GDCLASS(RDShaderFile, Resource)346347HashMap<StringName, Ref<RDShaderSPIRV>> versions;348String base_error;349350public:351void set_bytecode(const Ref<RDShaderSPIRV> &p_bytecode, const StringName &p_version = StringName()) {352ERR_FAIL_COND(p_bytecode.is_null());353versions[p_version] = p_bytecode;354emit_changed();355}356357Ref<RDShaderSPIRV> get_spirv(const StringName &p_version = StringName()) const {358ERR_FAIL_COND_V(!versions.has(p_version), Ref<RDShaderSPIRV>());359return versions[p_version];360}361362Vector<RD::ShaderStageSPIRVData> get_spirv_stages(const StringName &p_version = StringName()) const {363ERR_FAIL_COND_V(!versions.has(p_version), Vector<RD::ShaderStageSPIRVData>());364return versions[p_version]->get_stages();365}366367TypedArray<StringName> get_version_list() const {368Vector<StringName> vnames;369for (const KeyValue<StringName, Ref<RDShaderSPIRV>> &E : versions) {370vnames.push_back(E.key);371}372vnames.sort_custom<StringName::AlphCompare>();373TypedArray<StringName> ret;374ret.resize(vnames.size());375for (int i = 0; i < vnames.size(); i++) {376ret[i] = vnames[i];377}378return ret;379}380381void set_base_error(const String &p_error) {382base_error = p_error;383emit_changed();384}385386String get_base_error() const {387return base_error;388}389390void print_errors(const String &p_file) {391if (!base_error.is_empty()) {392ERR_PRINT("Error parsing shader '" + p_file + "':\n\n" + base_error);393} else {394for (KeyValue<StringName, Ref<RDShaderSPIRV>> &E : versions) {395for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) {396String error = E.value->get_stage_compile_error(RD::ShaderStage(i));397if (!error.is_empty()) {398static const char *stage_str[RD::SHADER_STAGE_MAX] = {399"vertex",400"fragment",401"tesselation_control",402"tesselation_evaluation",403"compute"404};405406print_error("Error parsing shader '" + p_file + "', version '" + String(E.key) + "', stage '" + stage_str[i] + "':\n\n" + error);407}408}409}410}411}412413typedef String (*OpenIncludeFunction)(const String &, void *userdata);414Error parse_versions_from_text(const String &p_text, const String p_defines = String(), OpenIncludeFunction p_include_func = nullptr, void *p_include_func_userdata = nullptr);415416protected:417Dictionary _get_versions() const {418TypedArray<StringName> vnames = get_version_list();419Dictionary ret;420for (int i = 0; i < vnames.size(); i++) {421ret[vnames[i]] = versions[vnames[i]];422}423return ret;424}425void _set_versions(const Dictionary &p_versions) {426versions.clear();427for (const KeyValue<Variant, Variant> &kv : p_versions) {428StringName vname = kv.key;429Ref<RDShaderSPIRV> bc = kv.value;430ERR_CONTINUE(bc.is_null());431versions[vname] = bc;432}433434emit_changed();435}436437static void _bind_methods() {438ClassDB::bind_method(D_METHOD("set_bytecode", "bytecode", "version"), &RDShaderFile::set_bytecode, DEFVAL(StringName()));439ClassDB::bind_method(D_METHOD("get_spirv", "version"), &RDShaderFile::get_spirv, DEFVAL(StringName()));440ClassDB::bind_method(D_METHOD("get_version_list"), &RDShaderFile::get_version_list);441442ClassDB::bind_method(D_METHOD("set_base_error", "error"), &RDShaderFile::set_base_error);443ClassDB::bind_method(D_METHOD("get_base_error"), &RDShaderFile::get_base_error);444445ClassDB::bind_method(D_METHOD("_set_versions", "versions"), &RDShaderFile::_set_versions);446ClassDB::bind_method(D_METHOD("_get_versions"), &RDShaderFile::_get_versions);447448ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_versions", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_versions", "_get_versions");449ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_error"), "set_base_error", "get_base_error");450}451};452453class RDUniform : public RefCounted {454GDCLASS(RDUniform, RefCounted)455friend class RenderingDevice;456friend class UniformSetCacheRD;457RD::Uniform base;458459public:460RD_SETGET(RD::UniformType, uniform_type)461RD_SETGET(int32_t, binding)462463void add_id(const RID &p_id) { base.append_id(p_id); }464void clear_ids() { base.clear_ids(); }465TypedArray<RID> get_ids() const {466TypedArray<RID> ids;467for (uint32_t i = 0; i < base.get_id_count(); i++) {468ids.push_back(base.get_id(i));469}470return ids;471}472473protected:474void _set_ids(const TypedArray<RID> &p_ids) {475base.clear_ids();476for (int i = 0; i < p_ids.size(); i++) {477RID id = p_ids[i];478ERR_FAIL_COND(id.is_null());479base.append_id(id);480}481}482static void _bind_methods() {483RD_BIND(Variant::INT, RDUniform, uniform_type);484RD_BIND(Variant::INT, RDUniform, binding);485ClassDB::bind_method(D_METHOD("add_id", "id"), &RDUniform::add_id);486ClassDB::bind_method(D_METHOD("clear_ids"), &RDUniform::clear_ids);487ClassDB::bind_method(D_METHOD("_set_ids", "ids"), &RDUniform::_set_ids);488ClassDB::bind_method(D_METHOD("get_ids"), &RDUniform::get_ids);489ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_ids", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_ids", "get_ids");490}491};492493class RDPipelineSpecializationConstant : public RefCounted {494GDCLASS(RDPipelineSpecializationConstant, RefCounted)495friend class RenderingDevice;496497Variant value = false;498uint32_t constant_id = 0;499500public:501void set_value(const Variant &p_value) {502ERR_FAIL_COND(p_value.get_type() != Variant::BOOL && p_value.get_type() != Variant::INT && p_value.get_type() != Variant::FLOAT);503value = p_value;504}505Variant get_value() const { return value; }506507void set_constant_id(uint32_t p_id) {508constant_id = p_id;509}510uint32_t get_constant_id() const {511return constant_id;512}513514protected:515static void _bind_methods() {516ClassDB::bind_method(D_METHOD("set_value", "value"), &RDPipelineSpecializationConstant::set_value);517ClassDB::bind_method(D_METHOD("get_value"), &RDPipelineSpecializationConstant::get_value);518519ClassDB::bind_method(D_METHOD("set_constant_id", "constant_id"), &RDPipelineSpecializationConstant::set_constant_id);520ClassDB::bind_method(D_METHOD("get_constant_id"), &RDPipelineSpecializationConstant::get_constant_id);521522ADD_PROPERTY(PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_value", "get_value");523ADD_PROPERTY(PropertyInfo(Variant::INT, "constant_id", PROPERTY_HINT_RANGE, "0,65535,0"), "set_constant_id", "get_constant_id");524}525};526527class RDPipelineRasterizationState : public RefCounted {528GDCLASS(RDPipelineRasterizationState, RefCounted)529friend class RenderingDevice;530531RD::PipelineRasterizationState base;532533public:534RD_SETGET(bool, enable_depth_clamp)535RD_SETGET(bool, discard_primitives)536RD_SETGET(bool, wireframe)537RD_SETGET(RD::PolygonCullMode, cull_mode)538RD_SETGET(RD::PolygonFrontFace, front_face)539RD_SETGET(bool, depth_bias_enabled)540RD_SETGET(float, depth_bias_constant_factor)541RD_SETGET(float, depth_bias_clamp)542RD_SETGET(float, depth_bias_slope_factor)543RD_SETGET(float, line_width)544RD_SETGET(uint32_t, patch_control_points)545546protected:547static void _bind_methods() {548RD_BIND(Variant::BOOL, RDPipelineRasterizationState, enable_depth_clamp);549RD_BIND(Variant::BOOL, RDPipelineRasterizationState, discard_primitives);550RD_BIND(Variant::BOOL, RDPipelineRasterizationState, wireframe);551RD_BIND(Variant::INT, RDPipelineRasterizationState, cull_mode);552RD_BIND(Variant::INT, RDPipelineRasterizationState, front_face);553RD_BIND(Variant::BOOL, RDPipelineRasterizationState, depth_bias_enabled);554RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_constant_factor);555RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_clamp);556RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_slope_factor);557RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, line_width);558RD_BIND(Variant::INT, RDPipelineRasterizationState, patch_control_points);559}560};561562class RDPipelineMultisampleState : public RefCounted {563GDCLASS(RDPipelineMultisampleState, RefCounted)564friend class RenderingDevice;565566RD::PipelineMultisampleState base;567TypedArray<int64_t> sample_masks;568569public:570RD_SETGET(RD::TextureSamples, sample_count)571RD_SETGET(bool, enable_sample_shading)572RD_SETGET(float, min_sample_shading)573RD_SETGET(bool, enable_alpha_to_coverage)574RD_SETGET(bool, enable_alpha_to_one)575576void set_sample_masks(const TypedArray<int64_t> &p_masks) { sample_masks = p_masks; }577TypedArray<int64_t> get_sample_masks() const { return sample_masks; }578579protected:580static void _bind_methods() {581RD_BIND(Variant::INT, RDPipelineMultisampleState, sample_count);582RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_sample_shading);583RD_BIND(Variant::FLOAT, RDPipelineMultisampleState, min_sample_shading);584RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_coverage);585RD_BIND(Variant::BOOL, RDPipelineMultisampleState, enable_alpha_to_one);586587ClassDB::bind_method(D_METHOD("set_sample_masks", "masks"), &RDPipelineMultisampleState::set_sample_masks);588ClassDB::bind_method(D_METHOD("get_sample_masks"), &RDPipelineMultisampleState::get_sample_masks);589ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "sample_masks", PROPERTY_HINT_ARRAY_TYPE, "int"), "set_sample_masks", "get_sample_masks");590}591};592593class RDPipelineDepthStencilState : public RefCounted {594GDCLASS(RDPipelineDepthStencilState, RefCounted)595friend class RenderingDevice;596597RD::PipelineDepthStencilState base;598599public:600RD_SETGET(bool, enable_depth_test)601RD_SETGET(bool, enable_depth_write)602RD_SETGET(RD::CompareOperator, depth_compare_operator)603RD_SETGET(bool, enable_depth_range)604RD_SETGET(float, depth_range_min)605RD_SETGET(float, depth_range_max)606RD_SETGET(bool, enable_stencil)607608RD_SETGET_SUB(RD::StencilOperation, front_op, fail)609RD_SETGET_SUB(RD::StencilOperation, front_op, pass)610RD_SETGET_SUB(RD::StencilOperation, front_op, depth_fail)611RD_SETGET_SUB(RD::CompareOperator, front_op, compare)612RD_SETGET_SUB(uint32_t, front_op, compare_mask)613RD_SETGET_SUB(uint32_t, front_op, write_mask)614RD_SETGET_SUB(uint32_t, front_op, reference)615616RD_SETGET_SUB(RD::StencilOperation, back_op, fail)617RD_SETGET_SUB(RD::StencilOperation, back_op, pass)618RD_SETGET_SUB(RD::StencilOperation, back_op, depth_fail)619RD_SETGET_SUB(RD::CompareOperator, back_op, compare)620RD_SETGET_SUB(uint32_t, back_op, compare_mask)621RD_SETGET_SUB(uint32_t, back_op, write_mask)622RD_SETGET_SUB(uint32_t, back_op, reference)623624protected:625static void _bind_methods() {626RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_test);627RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_write);628RD_BIND(Variant::INT, RDPipelineDepthStencilState, depth_compare_operator);629RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_depth_range);630RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_min);631RD_BIND(Variant::FLOAT, RDPipelineDepthStencilState, depth_range_max);632RD_BIND(Variant::BOOL, RDPipelineDepthStencilState, enable_stencil);633634RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, fail);635RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, pass);636RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, depth_fail);637RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare);638RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, compare_mask);639RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, write_mask);640RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, front_op, reference);641642RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, fail);643RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, pass);644RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, depth_fail);645RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare);646RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, compare_mask);647RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, write_mask);648RD_BIND_SUB(Variant::INT, RDPipelineDepthStencilState, back_op, reference);649}650};651652class RDPipelineColorBlendStateAttachment : public RefCounted {653GDCLASS(RDPipelineColorBlendStateAttachment, RefCounted)654friend class RenderingDevice;655RD::PipelineColorBlendState::Attachment base;656657public:658RD_SETGET(bool, enable_blend)659RD_SETGET(RD::BlendFactor, src_color_blend_factor)660RD_SETGET(RD::BlendFactor, dst_color_blend_factor)661RD_SETGET(RD::BlendOperation, color_blend_op)662RD_SETGET(RD::BlendFactor, src_alpha_blend_factor)663RD_SETGET(RD::BlendFactor, dst_alpha_blend_factor)664RD_SETGET(RD::BlendOperation, alpha_blend_op)665RD_SETGET(bool, write_r)666RD_SETGET(bool, write_g)667RD_SETGET(bool, write_b)668RD_SETGET(bool, write_a)669670void set_as_mix() {671base = RD::PipelineColorBlendState::Attachment();672base.enable_blend = true;673base.src_color_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;674base.dst_color_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;675base.src_alpha_blend_factor = RD::BLEND_FACTOR_SRC_ALPHA;676base.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;677}678679protected:680static void _bind_methods() {681ClassDB::bind_method(D_METHOD("set_as_mix"), &RDPipelineColorBlendStateAttachment::set_as_mix);682683RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, enable_blend);684RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_color_blend_factor);685RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_color_blend_factor);686RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, color_blend_op);687RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, src_alpha_blend_factor);688RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, dst_alpha_blend_factor);689RD_BIND(Variant::INT, RDPipelineColorBlendStateAttachment, alpha_blend_op);690RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_r);691RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_g);692RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_b);693RD_BIND(Variant::BOOL, RDPipelineColorBlendStateAttachment, write_a);694}695};696697class RDPipelineColorBlendState : public RefCounted {698GDCLASS(RDPipelineColorBlendState, RefCounted)699friend class RenderingDevice;700RD::PipelineColorBlendState base;701702TypedArray<RDPipelineColorBlendStateAttachment> attachments;703704public:705RD_SETGET(bool, enable_logic_op)706RD_SETGET(RD::LogicOperation, logic_op)707RD_SETGET(Color, blend_constant)708709void set_attachments(const TypedArray<RDPipelineColorBlendStateAttachment> &p_attachments) {710attachments = p_attachments;711}712713TypedArray<RDPipelineColorBlendStateAttachment> get_attachments() const {714return attachments;715}716717protected:718static void _bind_methods() {719RD_BIND(Variant::BOOL, RDPipelineColorBlendState, enable_logic_op);720RD_BIND(Variant::INT, RDPipelineColorBlendState, logic_op);721RD_BIND(Variant::COLOR, RDPipelineColorBlendState, blend_constant);722723ClassDB::bind_method(D_METHOD("set_attachments", "attachments"), &RDPipelineColorBlendState::set_attachments);724ClassDB::bind_method(D_METHOD("get_attachments"), &RDPipelineColorBlendState::get_attachments);725ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "attachments", PROPERTY_HINT_ARRAY_TYPE, "RDPipelineColorBlendStateAttachment"), "set_attachments", "get_attachments");726}727};728729730