1 /** 2 RenderingDevice texture abstraction. 3 4 Copyright © 2025, Inochi2D Project 5 Distributed under the 2-Clause BSD License, see LICENSE file. 6 7 Authors: Luna Nielsen 8 */ 9 module inochi2d.godot.render.texture; 10 import inochi2d.godot.render; 11 import godot.rendering_device; 12 import godot.variant; 13 import godot; 14 import numem; 15 16 public import godot.rd_texture_format; 17 public import godot.rd_texture_view; 18 19 /** 20 Texture type 21 */ 22 alias TextureType = RenderingDevice.TextureType; 23 24 /** 25 Texture swizzle 26 */ 27 alias TextureSwizzle = RenderingDevice.TextureSwizzle; 28 29 /** 30 Texture usage flags 31 */ 32 alias TextureUsageFlags = RenderingDevice.TextureUsageBits; 33 34 /** 35 Texture samples 36 */ 37 alias TextureSamples = RenderingDevice.TextureSamples; 38 39 /** 40 Texture format. 41 */ 42 alias TextureDataFormat = RenderingDevice.DataFormat; 43 44 /** 45 A 2D texture 46 */ 47 class RDTexture : RDObject { 48 private: 49 @nogc: 50 51 public: 52 53 /** 54 The format of this texture. 55 */ 56 final @property RDTextureFormat format() => device.textureGetFormat(rid); 57 58 /** 59 Creates a new RDTexture2D. 60 61 Params: 62 device = The owning device 63 format = The format of the texture 64 view = The texture view of the texture 65 data = The data to set for the texture's 0th mip-level. 66 */ 67 this(RenderingDevice device, RDTextureFormat format, RDTextureView view, ubyte[] data) { 68 auto p_data_array = TypedArray!(PackedArray!ubyte)(1); 69 p_data_array[0] = PackedArray!ubyte(data.nu_dup()); 70 super(device, device.textureCreate(format, view, p_data_array)); 71 } 72 73 /** 74 Updates the data in the texture. 75 76 Params: 77 layer = The layer to update 78 data = The data to write to the layer. 79 */ 80 void update(int layer, void[] data) { 81 auto p_data = gde_to_packed_array(cast(ubyte[])data); 82 device.textureUpdate(rid, layer, p_data); 83 gd_delete(p_data); 84 } 85 }