1 /** 2 Base class for 3D texture types. 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.texturelayered; 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.resource; 24 import godot.reference; 25 import godot.image; 26 /** 27 Base class for 3D texture types. 28 29 Base class for $(D Texture3D) and $(D TextureArray). Cannot be used directly, but contains all the functions necessary for accessing and using $(D Texture3D) and $(D TextureArray). Data is set on a per-layer basis. For $(D Texture3D)s, the layer specifies the depth or Z-index, they can be treated as a bunch of 2D slices. Similarly, for $(D TextureArray)s, the layer specifies the array layer. 30 */ 31 @GodotBaseClass struct TextureLayered 32 { 33 package(godot) enum string _GODOT_internal_name = "TextureLayered"; 34 public: 35 @nogc nothrow: 36 union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; } 37 alias _GODOT_base this; 38 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 39 package(godot) __gshared bool _classBindingInitialized = false; 40 package(godot) static struct GDNativeClassBinding 41 { 42 __gshared: 43 @GodotName("_get_data") GodotMethod!(Dictionary) _getData; 44 @GodotName("_set_data") GodotMethod!(void, Dictionary) _setData; 45 @GodotName("create") GodotMethod!(void, long, long, long, long, long) create; 46 @GodotName("get_depth") GodotMethod!(long) getDepth; 47 @GodotName("get_flags") GodotMethod!(long) getFlags; 48 @GodotName("get_format") GodotMethod!(Image.Format) getFormat; 49 @GodotName("get_height") GodotMethod!(long) getHeight; 50 @GodotName("get_layer_data") GodotMethod!(Image, long) getLayerData; 51 @GodotName("get_width") GodotMethod!(long) getWidth; 52 @GodotName("set_data_partial") GodotMethod!(void, Image, long, long, long, long) setDataPartial; 53 @GodotName("set_flags") GodotMethod!(void, long) setFlags; 54 @GodotName("set_layer_data") GodotMethod!(void, Image, long) setLayerData; 55 } 56 /// 57 pragma(inline, true) bool opEquals(in TextureLayered other) const 58 { return _godot_object.ptr is other._godot_object.ptr; } 59 /// 60 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 61 { _godot_object.ptr = n; return null; } 62 /// 63 pragma(inline, true) bool opEquals(typeof(null) n) const 64 { return _godot_object.ptr is n; } 65 /// 66 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 67 mixin baseCasts; 68 /// Construct a new instance of TextureLayered. 69 /// Note: use `memnew!TextureLayered` instead. 70 static TextureLayered _new() 71 { 72 static godot_class_constructor constructor; 73 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("TextureLayered"); 74 if(constructor is null) return typeof(this).init; 75 return cast(TextureLayered)(constructor()); 76 } 77 @disable new(size_t s); 78 /// 79 enum Flags : int 80 { 81 /** 82 Texture will generate mipmaps on creation. 83 */ 84 flagMipmaps = 1, 85 /** 86 Texture will repeat when UV used is outside the 0-1 range. 87 */ 88 flagRepeat = 2, 89 /** 90 Use filtering when reading from texture. Filtering smooths out pixels. Turning filtering off is slightly faster and more appropriate when you need access to individual pixels. 91 */ 92 flagFilter = 4, 93 /** 94 Equivalent to $(D constant FLAG_FILTER). 95 */ 96 flagsDefault = 4, 97 } 98 /// 99 enum Constants : int 100 { 101 flagMipmaps = 1, 102 flagRepeat = 2, 103 flagFilter = 4, 104 flagsDefault = 4, 105 } 106 /** 107 108 */ 109 Dictionary _getData() const 110 { 111 Array _GODOT_args = Array.make(); 112 String _GODOT_method_name = String("_get_data"); 113 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Dictionary); 114 } 115 /** 116 117 */ 118 void _setData(in Dictionary data) 119 { 120 Array _GODOT_args = Array.make(); 121 _GODOT_args.append(data); 122 String _GODOT_method_name = String("_set_data"); 123 this.callv(_GODOT_method_name, _GODOT_args); 124 } 125 /** 126 Creates the $(D Texture3D) or $(D TextureArray) with specified `width`, `height`, and `depth`. See $(D Image.format) for `format` options. See $(D flags) enumerator for `flags` options. 127 */ 128 void create(in long width, in long height, in long depth, in long format, in long flags = 4) 129 { 130 checkClassBinding!(typeof(this))(); 131 ptrcall!(void)(GDNativeClassBinding.create, _godot_object, width, height, depth, format, flags); 132 } 133 /** 134 Returns the depth of the texture. Depth is the 3rd dimension (typically Z-axis). 135 */ 136 long getDepth() const 137 { 138 checkClassBinding!(typeof(this))(); 139 return ptrcall!(long)(GDNativeClassBinding.getDepth, _godot_object); 140 } 141 /** 142 143 */ 144 long getFlags() const 145 { 146 checkClassBinding!(typeof(this))(); 147 return ptrcall!(long)(GDNativeClassBinding.getFlags, _godot_object); 148 } 149 /** 150 Returns the current format being used by this texture. See $(D Image.format) for details. 151 */ 152 Image.Format getFormat() const 153 { 154 checkClassBinding!(typeof(this))(); 155 return ptrcall!(Image.Format)(GDNativeClassBinding.getFormat, _godot_object); 156 } 157 /** 158 Returns the height of the texture. Height is typically represented by the Y-axis. 159 */ 160 long getHeight() const 161 { 162 checkClassBinding!(typeof(this))(); 163 return ptrcall!(long)(GDNativeClassBinding.getHeight, _godot_object); 164 } 165 /** 166 Returns an $(D Image) resource with the data from specified `layer`. 167 */ 168 Ref!Image getLayerData(in long layer) const 169 { 170 checkClassBinding!(typeof(this))(); 171 return ptrcall!(Image)(GDNativeClassBinding.getLayerData, _godot_object, layer); 172 } 173 /** 174 Returns the width of the texture. Width is typically represented by the X-axis. 175 */ 176 long getWidth() const 177 { 178 checkClassBinding!(typeof(this))(); 179 return ptrcall!(long)(GDNativeClassBinding.getWidth, _godot_object); 180 } 181 /** 182 Partially sets the data for a specified `layer` by overwriting using the data of the specified `image`. `x_offset` and `y_offset` determine where the $(D Image) is "stamped" over the texture. The `image` must fit within the texture. 183 */ 184 void setDataPartial(Image image, in long x_offset, in long y_offset, in long layer, in long mipmap = 0) 185 { 186 checkClassBinding!(typeof(this))(); 187 ptrcall!(void)(GDNativeClassBinding.setDataPartial, _godot_object, image, x_offset, y_offset, layer, mipmap); 188 } 189 /** 190 191 */ 192 void setFlags(in long flags) 193 { 194 checkClassBinding!(typeof(this))(); 195 ptrcall!(void)(GDNativeClassBinding.setFlags, _godot_object, flags); 196 } 197 /** 198 Sets the data for the specified layer. Data takes the form of a 2-dimensional $(D Image) resource. 199 */ 200 void setLayerData(Image image, in long layer) 201 { 202 checkClassBinding!(typeof(this))(); 203 ptrcall!(void)(GDNativeClassBinding.setLayerData, _godot_object, image, layer); 204 } 205 /** 206 Returns a dictionary with all the data used by this texture. 207 */ 208 @property Dictionary data() 209 { 210 return _getData(); 211 } 212 /// ditto 213 @property void data(Dictionary v) 214 { 215 _setData(v); 216 } 217 /** 218 Specifies which $(D flags) apply to this texture. 219 */ 220 @property long flags() 221 { 222 return getFlags(); 223 } 224 /// ditto 225 @property void flags(long v) 226 { 227 setFlags(v); 228 } 229 }