1 module bindbc.raylib.bind.texture;
2 
3 import bindbc.raylib.config;
4 import bindbc.raylib.types;
5 
6 version (BindRaylib_Static) {
7    extern (C) @nogc nothrow {
8    }
9 } else {
10    extern (C) @nogc nothrow {
11       /**
12        * Load image from file into CPU memory (RAM)
13        */
14       alias pLoadImage = Image function(const(char)* fileName);
15       /**
16        * Load image from Color array data (RGBA - 32bit)
17        */
18       alias pLoadImageEx = Image function(Color* pixels, int width, int height);
19       /**
20        * Load image from RAW file data
21        */
22       alias pLoadImageRaw = Image function(const(char)* fileName, int width, int height, int format, int headerSize);
23       /**
24        * Export image data to file
25        */
26       alias pExportImage = void function(Image image, const(char)* fileName);
27       /**
28        * Export image as code file defining an array of bytes
29        */
30       alias pExportImageAsCode = void function(Image image, const(char)* fileName);
31       /**
32        * Load texture from file into GPU memory (VRAM)
33        */
34       alias pLoadTexture = Texture2D function(const(char)* fileName);
35       /**
36        * Load texture from image data
37        */
38       alias pLoadTextureFromImage = Texture2D function(Image image);
39       /**
40        * Load cubemap from image, multiple image cubemap layouts supported
41        */
42       alias pLoadTextureCubemap = TextureCubemap function(Image image, int layoutType);
43       /**
44        * Load texture for rendering (framebuffer)
45        */
46       alias pLoadRenderTexture = RenderTexture2D function(int width, int height);
47       /**
48        * Unload image from CPU memory (RAM)
49        */
50       alias pUnloadImage = void function(Image image);
51       /**
52        * Unload texture from GPU memory (VRAM)
53        */
54       alias pUnloadTexture = void function(Texture2D texture);
55       /**
56        * Unload render texture from GPU memory (VRAM)
57        */
58       alias pUnloadRenderTexture = void function(RenderTexture2D target);
59 
60       /**
61        * Get pixel data from image as a Color struct array
62        */
63       alias pGetImageData = Color* function(Image image);
64       /**
65        * Get pixel data from image as Vector4 array (float normalized)
66        */
67       alias pGetImageDataNormalized = Vector4* function(Image image);
68       /**
69        * Get image alpha border rectangle
70        */
71       alias pGetImageAlphaBorder = Rectangle function(Image image, float threshold);
72 
73       // Image drawing functions
74       // NOTE: Image software-rendering functions (CPU)
75       alias pImageClearBackground = void function(Image* dst, Color color);
76 
77       /**
78        * Draw pixel within an image
79        */
80       alias pImageDrawPixel = void function(Image* dst, int posX, int posY, Color color);
81       /**
82        * Draw pixel within an image (Vector version)
83        */
84       alias pImageDrawPixelV = void function(Image* dst, Vector2 position, Color color);
85       /**
86        * Draw line within an image
87        */
88       alias pImageDrawLine = void function(Image* dst, int startPosX, int startPosY, int endPosX, int endPosY, Color color);
89       /**
90        * Draw line within an image (Vector version)
91        */
92       alias pImageDrawLineV = void function(Image* dst, Vector2 start, Vector2 end, Color color);
93       /**
94        * Draw circle within an image
95        */
96       alias pImageDrawCircle = void function(Image* dst, int centerX, int centerY, int radius, Color color);
97       /**
98        * Draw circle within an image (Vector version)
99        */
100       alias pImageDrawCircleV = void function(Image* dst, Vector2 center, int radius, Color color);
101       /**
102        * Draw rectangle within an image (Vector version)
103        */
104       alias pImageDrawRectangleV = void function(Image* dst, Vector2 position, Vector2 size, Color color);
105       /**
106        * Draw rectangle within an image
107        */
108       alias pImageDrawRectangleRec = void function(Image* dst, Rectangle rec, Color color);
109 
110       /**
111        * Get pixel data size in bytes (image or texture)
112        */
113       alias pGetPixelDataSize = int function(int width, int height, int format);
114       /**
115        * Get pixel data from GPU texture and return an Image
116        */
117       alias pGetTextureData = Image function(Texture2D texture);
118       /**
119        * Get pixel data from screen buffer and return an Image (screenshot)
120        */
121       alias pGetScreenData = Image function();
122       /**
123        * Update GPU texture with new data
124        */
125       alias pUpdateTexture = void function(Texture2D texture, const void* pixels);
126       // Image manipulation functions
127 
128       /**
129        * Create an image duplicate (useful for transformations)
130        */
131       alias pImageCopy = Image function(Image image);
132       /**
133        * Create an image from another image piece
134        */
135       alias pImageFromImage = Image function(Image image, Rectangle rec);
136       /**
137        * Convert image to POT (power-of-two)
138        */
139       alias pImageToPOT = void function(Image* image, Color fillColor);
140       /**
141        * Convert image data to desired format
142        */
143       alias pImageFormat = void function(Image* image, int newFormat);
144       /**
145        * Apply alpha mask to image
146        */
147       alias pImageAlphaMask = void function(Image* image, Image alphaMask);
148       /**
149        * Clear alpha channel to desired color
150        */
151       alias pImageAlphaClear = void function(Image* image, Color color, float threshold);
152       /**
153        * Crop image depending on alpha value
154        */
155       alias pImageAlphaCrop = void function(Image* image, float threshold);
156       /**
157        * Premultiply alpha channel
158        */
159       alias pImageAlphaPremultiply = void function(Image* image);
160       /**
161        * Crop an image to a defined rectangle
162        */
163       alias pImageCrop = void function(Image* image, Rectangle crop);
164       /**
165        * Resize image (Bicubic scaling algorithm)
166        */
167       alias pImageResize = void function(Image* image, int newWidth, int newHeight);
168       /**
169        * Resize image (Nearest-Neighbor scaling algorithm)
170        */
171       alias pImageResizeNN = void function(Image* image, int newWidth, int newHeight);
172       /**
173        * Resize canvas and fill with color
174        */
175       alias pImageResizeCanvas = void function(Image* image, int newWidth, int newHeight, int offsetX, int offsetY, Color color);
176       /**
177        * Generate all mipmap levels for a provided image
178        */
179       alias pImageMipmaps = void function(Image* image);
180       /**
181        * Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
182        */
183       alias pImageDither = void function(Image* image, int rBpp, int gBpp, int bBpp, int aBpp);
184       /**
185        * Extract color palette from image to maximum size (memory should be freed)
186        */
187       alias pImageExtractPalette = Color* function(Image image, int maxPaletteSize, int* extractCount);
188       /**
189        * Create an image from text (default font)
190        */
191       alias pImageText = Image function(const(char)* text, int fontSize, Color color);
192       /**
193        * Create an image from text (custom sprite font)
194        */
195       alias pImageTextEx = Image function(Font font, const(char)* text, float fontSize, float spacing, Color tint);
196       /**
197        * Draw a source image within a destination image (tint applied to source)
198        */
199       alias pImageDraw = void function(Image* dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint);
200       /**
201        * Draw rectangle within an image
202        */
203       alias pImageDrawRectangle = void function(Image* dst, Rectangle rec, Color color);
204       /**
205        * Draw rectangle lines within an image
206        */
207       alias pImageDrawRectangleLines = void function(Image* dst, Rectangle rec, int thick, Color color);
208 
209 
210       /**
211        * Flip image vertically
212        */
213       alias pImageFlipVertical = void function(Image* image);
214       /**
215        * Flip image horizontally
216        */
217       alias pImageFlipHorizontal = void function(Image* image);
218       /**
219        * Rotate image clockwise 90deg
220        */
221       alias pImageRotateCW = void function(Image* image);
222       /**
223        * Rotate image counter-clockwise 90deg
224        */
225       alias pImageRotateCCW = void function(Image* image);
226       /**
227        * Modify image color: tint
228        */
229       alias pImageColorTint = void function(Image* image, Color color);
230       /**
231        * Modify image color: invert
232        */
233       alias pImageColorInvert = void function(Image* image);
234       /**
235        * Modify image color: grayscale
236        */
237       alias pImageColorGrayscale = void function(Image* image);
238       /**
239        * Modify image color: contrast (-100 to 100)
240        */
241       alias pImageColorContrast = void function(Image* image, float contrast);
242       /**
243        * Modify image color: brightness (-255 to 255)
244        */
245       alias pImageColorBrightness = void function(Image* image, int brightness);
246       /**
247        * Modify image color: replace color
248        */
249       alias pImageColorReplace = void function(Image* image, Color color, Color replace);
250 
251       // Image generation functions
252       /**
253        * Generate image: plain color
254        */
255       alias pGenImageColor = Image function(int width, int height, Color color);
256       /**
257        * Generate image: vertical gradient
258        */
259       alias pGenImageGradientV = Image function(int width, int height, Color top, Color bottom);
260       /**
261        * Generate image: horizontal gradient
262        */
263       alias pGenImageGradientH = Image function(int width, int height, Color left, Color right);
264       /**
265        * Generate image: radial gradient
266        */
267       alias pGenImageGradientRadial = Image function(int width, int height, float density, Color inner, Color outer);
268       /**
269        * Generate image: checked
270        */
271       alias pGenImageChecked = Image function(int width, int height, int checksX, int checksY, Color col1, Color col2);
272       /**
273        * Generate image: white noise
274        */
275       alias pGenImageWhiteNoise = Image function(int width, int height, float factor);
276       /**
277        * Generate image: perlin noise
278        */
279       alias pGenImagePerlinNoise = Image function(int width, int height, int offsetX, int offsetY, float scale);
280       /**
281        * Generate image: cellular algorithm. Bigger tileSize means bigger cells
282        */
283       alias pGenImageCellular = Image function(int width, int height, int tileSize);
284 
285       // Texture2D configuration functions
286       /**
287        * Generate GPU mipmaps for a texture
288        */
289       alias pGenTextureMipmaps = void function(Texture2D* texture);
290 
291       /**
292        * Set texture scaling filter mode
293        */
294       alias pSetTextureFilter = void function(Texture2D texture, int filterMode);
295       /**
296        * Set texture wrapping mode
297        */
298       alias pSetTextureWrap = void function(Texture2D texture, int wrapMode);
299 
300       // Texture2D drawing functions
301       /**
302        * Draw a Texture2D
303        */
304       alias pDrawTexture = void function(Texture2D texture, int posX, int posY, Color tint);
305       /**
306        * Draw a Texture2D with position defined as Vector2
307        */
308       alias pDrawTextureV = void function(Texture2D texture, Vector2 position, Color tint);
309       /**
310        * Draw a Texture2D with extended parameters
311        */
312       alias pDrawTextureEx = void function(Texture2D texture, Vector2 position, float rotation, float scale, Color tint);
313       /**
314        * Draw a part of a texture defined by a rectangle
315        */
316       alias pDrawTextureRec = void function(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint);
317       /**
318        * Draw texture quad with tiling and offset parameters
319        */
320       alias pDrawTextureQuad = void function(Texture2D texture, Vector2 tiling, Vector2 offset, Rectangle quad, Color tint);
321       /**
322        * Draw a part of a texture defined by a rectangle with 'pro' parameters
323        */
324       alias pDrawTexturePro = void function(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin,
325             float rotation, Color tint);
326       /**
327        * Draws a texture (or part of it) that stretches or shrinks nicely
328        */
329       alias pDrawTextureNPatch = void function(Texture2D texture, NPatchInfo nPatchInfo, Rectangle destRec, Vector2 origin,
330             float rotation, Color tint);
331    }
332    __gshared {
333       pLoadImage LoadImage;
334       pLoadImageEx LoadImageEx;
335       pLoadImageRaw LoadImageRaw;
336       pExportImage ExportImage;
337       pExportImageAsCode ExportImageAsCode;
338       pLoadTexture LoadTexture;
339       pLoadTextureFromImage LoadTextureFromImage;
340       pLoadTextureCubemap LoadTextureCubemap;
341       pLoadRenderTexture LoadRenderTexture;
342       pUnloadImage UnloadImage;
343       pUnloadTexture UnloadTexture;
344       pUnloadRenderTexture UnloadRenderTexture;
345       pGetImageData GetImageData;
346       pGetImageDataNormalized GetImageDataNormalized;
347       pGetImageAlphaBorder GetImageAlphaBorder;
348 
349       pImageClearBackground ImageClearBackground;
350       pImageDrawPixel ImageDrawPixel;
351       pImageDrawPixelV ImageDrawPixelV;
352       pImageDrawLine ImageDrawLine;
353       pImageDrawLineV ImageDrawLineV;
354       pImageDrawCircle ImageDrawCircle;
355       pImageDrawCircleV ImageDrawCircleV;
356       pImageDrawRectangleV ImageDrawRectangleV;
357       pImageDrawRectangleRec ImageDrawRectangleRec;
358 
359       pGetPixelDataSize GetPixelDataSize;
360       pGetTextureData GetTextureData;
361       pGetScreenData GetScreenData;
362       pUpdateTexture UpdateTexture;
363       pImageCopy ImageCopy;
364       pImageFromImage ImageFromImage;
365       pImageToPOT ImageToPOT;
366       pImageFormat ImageFormat;
367       pImageAlphaMask ImageAlphaMask;
368       pImageAlphaClear ImageAlphaClear;
369       pImageAlphaCrop ImageAlphaCrop;
370       pImageAlphaPremultiply ImageAlphaPremultiply;
371       pImageCrop ImageCrop;
372       pImageResize ImageResize;
373       pImageResizeNN ImageResizeNN;
374       pImageResizeCanvas ImageResizeCanvas;
375       pImageMipmaps ImageMipmaps;
376       pImageDither ImageDither;
377       pImageExtractPalette ImageExtractPalette;
378       pImageText ImageText;
379       pImageTextEx ImageTextEx;
380       pImageDraw ImageDraw;
381       pImageDrawRectangle ImageDrawRectangle;
382       pImageDrawRectangleLines ImageDrawRectangleLines;
383       pImageFlipVertical ImageFlipVertical;
384       pImageFlipHorizontal ImageFlipHorizontal;
385       pImageRotateCW ImageRotateCW;
386       pImageRotateCCW ImageRotateCCW;
387       pImageColorTint ImageColorTint;
388       pImageColorInvert ImageColorInvert;
389       pImageColorGrayscale ImageColorGrayscale;
390       pImageColorContrast ImageColorContrast;
391       pImageColorBrightness ImageColorBrightness;
392       pImageColorReplace ImageColorReplace;
393       pGenImageColor GenImageColor;
394       pGenImageGradientV GenImageGradientV;
395       pGenImageGradientH GenImageGradientH;
396       pGenImageGradientRadial GenImageGradientRadial;
397       pGenImageChecked GenImageChecked;
398       pGenImageWhiteNoise GenImageWhiteNoise;
399       pGenImagePerlinNoise GenImagePerlinNoise;
400       pGenImageCellular GenImageCellular;
401 
402       pGenTextureMipmaps GenTextureMipmaps;
403       pSetTextureFilter SetTextureFilter;
404       pSetTextureWrap SetTextureWrap;
405 
406       pDrawTexture DrawTexture;
407       pDrawTextureV DrawTextureV;
408       pDrawTextureEx DrawTextureEx;
409       pDrawTextureRec DrawTextureRec;
410       pDrawTextureQuad DrawTextureQuad;
411       pDrawTexturePro DrawTexturePro;
412       pDrawTextureNPatch DrawTextureNPatch;
413    }
414 
415    static if (raylibSupport == RaylibSupport.raylib300_70) {
416       extern (C) @nogc nothrow {
417          alias pImageDrawText = void function(Image *dst, const(char)* text, int posX, int posY, int fontSize, Color color);
418          alias pImageDrawTextEx = void function(Image *dst, Font font, const(char)* text, Vector2 position, float fontSize, float spacing, Color tint);
419       }
420       __gshared {
421          pImageDrawText ImageDrawText;
422          pImageDrawTextEx ImageDrawTextEx;
423       }
424 
425    } else static if (raylibSupport <= RaylibSupport.raylib300) {
426       extern (C) @nogc nothrow {
427          /**
428           * Load image from raw data with parameters
429           */
430          alias pLoadImagePro = Image function(void* data, int width, int height, int format);
431          /**
432           * Draw text (default font) within an image (destination)
433           */
434          alias pImageDrawText = void function(Image* dst, Vector2 position, const(char)* text, int fontSize, Color color);
435          /**
436           * Draw text (custom sprite font) within an image (destination)
437           */
438          alias pImageDrawTextEx = void function(Image* dst, Vector2 position, Font font, const(char)* text, float fontSize,
439                float spacing, Color color);
440       }
441       __gshared {
442          pLoadImagePro LoadImagePro;
443          pImageDrawText ImageDrawText;
444          pImageDrawTextEx ImageDrawTextEx;
445       }
446    }
447 }