1 /**
2 Texture for 2D and 3D.
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.texture;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.resource;
23 import godot.image;
24 import godot.reference;
25 /**
26 Texture for 2D and 3D.
27 
28 A texture works by registering an image in the video hardware, which then can be used in 3D models or 2D $(D Sprite) or GUI $(D Control).
29 Textures are often created by loading them from a file. See $(D @GDScript.load).
30 */
31 @GodotBaseClass struct Texture
32 {
33 	enum string _GODOT_internal_name = "Texture";
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 _classBinding
41 	{
42 		__gshared:
43 		@GodotName("get_width") GodotMethod!(long) getWidth;
44 		@GodotName("get_height") GodotMethod!(long) getHeight;
45 		@GodotName("get_size") GodotMethod!(Vector2) getSize;
46 		@GodotName("has_alpha") GodotMethod!(bool) hasAlpha;
47 		@GodotName("set_flags") GodotMethod!(void, long) setFlags;
48 		@GodotName("get_flags") GodotMethod!(long) getFlags;
49 		@GodotName("draw") GodotMethod!(void, RID, Vector2, Color, bool, Texture) draw;
50 		@GodotName("draw_rect") GodotMethod!(void, RID, Rect2, bool, Color, bool, Texture) drawRect;
51 		@GodotName("draw_rect_region") GodotMethod!(void, RID, Rect2, Rect2, Color, bool, Texture, bool) drawRectRegion;
52 		@GodotName("get_data") GodotMethod!(Image) getData;
53 	}
54 	bool opEquals(in Texture other) const { return _godot_object.ptr is other._godot_object.ptr; }
55 	Texture opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
56 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
57 	mixin baseCasts;
58 	static Texture _new()
59 	{
60 		static godot_class_constructor constructor;
61 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Texture");
62 		if(constructor is null) return typeof(this).init;
63 		return cast(Texture)(constructor());
64 	}
65 	@disable new(size_t s);
66 	/// 
67 	enum Flags : int
68 	{
69 		/**
70 		Generate mipmaps, which are smaller versions of the same texture to use when zoomed out, keeping the aspect ratio.
71 		*/
72 		flagMipmaps = 1,
73 		/**
74 		Repeats texture (instead of clamp to edge).
75 		*/
76 		flagRepeat = 2,
77 		/**
78 		Magnifying filter, to enable smooth zooming in of the texture.
79 		*/
80 		flagFilter = 4,
81 		/**
82 		Default flags. Generate mipmaps, repeat, and filter are enabled.
83 		*/
84 		flagsDefault = 7,
85 		/**
86 		Anisotropic mipmap filtering. Generates smaller versions of the same texture with different aspect ratios.
87 		More effective on planes often shown going to the horrizon as those textures (Walls or Ground for example) get squashed in the viewport to different aspect ratios and regular mipmaps keep the aspect ratio so they don't optimize storage that well in those cases.
88 		*/
89 		flagAnisotropicFilter = 8,
90 		/**
91 		Converts texture to SRGB color space.
92 		*/
93 		flagConvertToLinear = 16,
94 		/**
95 		Repeats texture with alternate sections mirrored.
96 		*/
97 		flagMirroredRepeat = 32,
98 		/**
99 		Texture is a video surface.
100 		*/
101 		flagVideoSurface = 2048,
102 	}
103 	/// 
104 	enum Constants : int
105 	{
106 		flagMipmaps = 1,
107 		flagRepeat = 2,
108 		flagFilter = 4,
109 		flagsDefault = 7,
110 		flagAnisotropicFilter = 8,
111 		flagConvertToLinear = 16,
112 		flagMirroredRepeat = 32,
113 		flagVideoSurface = 2048,
114 	}
115 	/**
116 	Return the texture width.
117 	*/
118 	long getWidth() const
119 	{
120 		checkClassBinding!(typeof(this))();
121 		return ptrcall!(long)(_classBinding.getWidth, _godot_object);
122 	}
123 	/**
124 	Return the texture height.
125 	*/
126 	long getHeight() const
127 	{
128 		checkClassBinding!(typeof(this))();
129 		return ptrcall!(long)(_classBinding.getHeight, _godot_object);
130 	}
131 	/**
132 	Return the texture size.
133 	*/
134 	Vector2 getSize() const
135 	{
136 		checkClassBinding!(typeof(this))();
137 		return ptrcall!(Vector2)(_classBinding.getSize, _godot_object);
138 	}
139 	/**
140 	
141 	*/
142 	bool hasAlpha() const
143 	{
144 		checkClassBinding!(typeof(this))();
145 		return ptrcall!(bool)(_classBinding.hasAlpha, _godot_object);
146 	}
147 	/**
148 	
149 	*/
150 	void setFlags(in long flags)
151 	{
152 		checkClassBinding!(typeof(this))();
153 		ptrcall!(void)(_classBinding.setFlags, _godot_object, flags);
154 	}
155 	/**
156 	
157 	*/
158 	long getFlags() const
159 	{
160 		checkClassBinding!(typeof(this))();
161 		return ptrcall!(long)(_classBinding.getFlags, _godot_object);
162 	}
163 	/**
164 	
165 	*/
166 	void draw(in RID canvas_item, in Vector2 position, in Color modulate = Color(1,1,1,1), in bool transpose = false, Texture normal_map = Texture.init) const
167 	{
168 		checkClassBinding!(typeof(this))();
169 		ptrcall!(void)(_classBinding.draw, _godot_object, canvas_item, position, modulate, transpose, normal_map);
170 	}
171 	/**
172 	
173 	*/
174 	void drawRect(in RID canvas_item, in Rect2 rect, in bool tile, in Color modulate = Color(1,1,1,1), in bool transpose = false, Texture normal_map = Texture.init) const
175 	{
176 		checkClassBinding!(typeof(this))();
177 		ptrcall!(void)(_classBinding.drawRect, _godot_object, canvas_item, rect, tile, modulate, transpose, normal_map);
178 	}
179 	/**
180 	
181 	*/
182 	void drawRectRegion(in RID canvas_item, in Rect2 rect, in Rect2 src_rect, in Color modulate = Color(1,1,1,1), in bool transpose = false, Texture normal_map = Texture.init, in bool clip_uv = true) const
183 	{
184 		checkClassBinding!(typeof(this))();
185 		ptrcall!(void)(_classBinding.drawRectRegion, _godot_object, canvas_item, rect, src_rect, modulate, transpose, normal_map, clip_uv);
186 	}
187 	/**
188 	
189 	*/
190 	Ref!Image getData() const
191 	{
192 		checkClassBinding!(typeof(this))();
193 		return ptrcall!(Image)(_classBinding.getData, _godot_object);
194 	}
195 	/**
196 	The texture's flags.
197 	*/
198 	@property long flags()
199 	{
200 		return getFlags();
201 	}
202 	/// ditto
203 	@property void flags(long v)
204 	{
205 		setFlags(v);
206 	}
207 }