1 /** 2 A custom shader program. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.shader; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.resource; 25 import godot.reference; 26 import godot.texture; 27 /** 28 A custom shader program. 29 30 This class allows you to define a custom shader program that can be used by a $(D ShaderMaterial). Shaders allow you to write your own custom behavior for rendering objects or updating particle information. For a detailed explanation and usage, please see the tutorials linked below. 31 */ 32 @GodotBaseClass struct Shader 33 { 34 package(godot) enum string _GODOT_internal_name = "Shader"; 35 public: 36 @nogc nothrow: 37 union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct GDNativeClassBinding 42 { 43 __gshared: 44 @GodotName("get_code") GodotMethod!(String) getCode; 45 @GodotName("get_custom_defines") GodotMethod!(String) getCustomDefines; 46 @GodotName("get_default_texture_param") GodotMethod!(Texture, String) getDefaultTextureParam; 47 @GodotName("get_mode") GodotMethod!(Shader.Mode) getMode; 48 @GodotName("has_param") GodotMethod!(bool, String) hasParam; 49 @GodotName("set_code") GodotMethod!(void, String) setCode; 50 @GodotName("set_custom_defines") GodotMethod!(void, String) setCustomDefines; 51 @GodotName("set_default_texture_param") GodotMethod!(void, String, Texture) setDefaultTextureParam; 52 } 53 /// 54 pragma(inline, true) bool opEquals(in Shader other) const 55 { return _godot_object.ptr is other._godot_object.ptr; } 56 /// 57 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 58 { _godot_object.ptr = n; return null; } 59 /// 60 pragma(inline, true) bool opEquals(typeof(null) n) const 61 { return _godot_object.ptr is n; } 62 /// 63 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 64 mixin baseCasts; 65 /// Construct a new instance of Shader. 66 /// Note: use `memnew!Shader` instead. 67 static Shader _new() 68 { 69 static godot_class_constructor constructor; 70 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Shader"); 71 if(constructor is null) return typeof(this).init; 72 return cast(Shader)(constructor()); 73 } 74 @disable new(size_t s); 75 /// 76 enum Mode : int 77 { 78 /** 79 Mode used to draw all 3D objects. 80 */ 81 modeSpatial = 0, 82 /** 83 Mode used to draw all 2D objects. 84 */ 85 modeCanvasItem = 1, 86 /** 87 Mode used to calculate particle information on a per-particle basis. Not used for drawing. 88 */ 89 modeParticles = 2, 90 } 91 /// 92 enum Constants : int 93 { 94 modeSpatial = 0, 95 modeCanvasItem = 1, 96 modeParticles = 2, 97 } 98 /** 99 100 */ 101 String getCode() const 102 { 103 checkClassBinding!(typeof(this))(); 104 return ptrcall!(String)(GDNativeClassBinding.getCode, _godot_object); 105 } 106 /** 107 108 */ 109 String getCustomDefines() const 110 { 111 checkClassBinding!(typeof(this))(); 112 return ptrcall!(String)(GDNativeClassBinding.getCustomDefines, _godot_object); 113 } 114 /** 115 Returns the texture that is set as default for the specified parameter. 116 $(B Note:) `param` must match the name of the uniform in the code exactly. 117 */ 118 Ref!Texture getDefaultTextureParam(in String param) const 119 { 120 checkClassBinding!(typeof(this))(); 121 return ptrcall!(Texture)(GDNativeClassBinding.getDefaultTextureParam, _godot_object, param); 122 } 123 /** 124 Returns the shader mode for the shader, either $(D constant MODE_CANVAS_ITEM), $(D constant MODE_SPATIAL) or $(D constant MODE_PARTICLES). 125 */ 126 Shader.Mode getMode() const 127 { 128 checkClassBinding!(typeof(this))(); 129 return ptrcall!(Shader.Mode)(GDNativeClassBinding.getMode, _godot_object); 130 } 131 /** 132 Returns `true` if the shader has this param defined as a uniform in its code. 133 $(B Note:) `param` must match the name of the uniform in the code exactly. 134 */ 135 bool hasParam(in String name) const 136 { 137 checkClassBinding!(typeof(this))(); 138 return ptrcall!(bool)(GDNativeClassBinding.hasParam, _godot_object, name); 139 } 140 /** 141 142 */ 143 void setCode(in String code) 144 { 145 checkClassBinding!(typeof(this))(); 146 ptrcall!(void)(GDNativeClassBinding.setCode, _godot_object, code); 147 } 148 /** 149 150 */ 151 void setCustomDefines(in String custom_defines) 152 { 153 checkClassBinding!(typeof(this))(); 154 ptrcall!(void)(GDNativeClassBinding.setCustomDefines, _godot_object, custom_defines); 155 } 156 /** 157 Sets the default texture to be used with a texture uniform. The default is used if a texture is not set in the $(D ShaderMaterial). 158 $(B Note:) `param` must match the name of the uniform in the code exactly. 159 */ 160 void setDefaultTextureParam(in String param, Texture texture) 161 { 162 checkClassBinding!(typeof(this))(); 163 ptrcall!(void)(GDNativeClassBinding.setDefaultTextureParam, _godot_object, param, texture); 164 } 165 /** 166 Returns the shader's code as the user has written it, not the full generated code used internally. 167 */ 168 @property String code() 169 { 170 return getCode(); 171 } 172 /// ditto 173 @property void code(String v) 174 { 175 setCode(v); 176 } 177 /** 178 Returns the shader's custom defines. Custom defines can be used in Godot to add GLSL preprocessor directives (e.g: extensions) required for the shader logic. 179 $(B Note:) Custom defines are not validated by the Godot shader parser, so care should be taken when using them. 180 */ 181 @property String customDefines() 182 { 183 return getCustomDefines(); 184 } 185 /// ditto 186 @property void customDefines(String v) 187 { 188 setCustomDefines(v); 189 } 190 }