1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
use super::{Atlas, Bitmap, Context, PixelFormat, Texture, TextureLoader};
use std::fmt;
// @short_description: Functions for managing textures in 's global
// set of texture atlases
//
// A texture atlas is a texture that contains many smaller images that
// an application is interested in. These are packed together as a way
// of optimizing drawing with those images by avoiding the costs of
// repeatedly telling the hardware to change what texture it should
// sample from. This can enable more geometry to be batched together
// into few draw calls.
//
// Each #Context has an shared, pool of texture atlases that are
// are managed by .
//
// This api lets applications upload texture data into one of 's
// shared texture atlases using a high-level #AtlasTexture which
// represents a sub-region of one of these atlases.
//
// A #AtlasTexture is a high-level meta texture which has
// some limitations to be aware of. Please see the documentation for
// #MetaTexture for more details.
pub struct AtlasTexture {
parent: Texture,
// The format that the texture is in. This isn't necessarily the
// same format as the atlas texture because we can store
// pre-multiplied and non-pre-multiplied textures together
internal_format: PixelFormat,
// The rectangle that was used to add this texture to the
// atlas. This includes the 1-pixel border
// rectangle: RectangleMapEntry,
// The atlas that this texture is in. If the texture is no longer in
// an atlas then this will be NULL. A reference is taken on the
// atlas by the texture (but not vice versa so there is no cycle)
atlas: Option<Atlas>,
// Either a SubTexture representing the atlas region for easy
// rendering or if the texture has been migrated out of the atlas it
// may be some other texture type such as Texture2D
sub_texture: Option<Texture>,
}
impl AtlasTexture {
// atlas_texture_new_from_bitmap:
// @bitmap: A #Bitmap
//
// Creates a new #AtlasTexture texture based on data residing in a
// @bitmap. A #AtlasTexture represents a sub-region within one of
// 's shared texture atlases.
//
// The storage for the texture is not allocated before this function
// returns. You can call texture_allocate() to explicitly
// allocate the underlying storage or preferably let
// automatically allocate storage lazily when it may know more about
// how the texture is being used and can optimize how it is allocated.
//
// The texture is still configurable until it has been allocated so
// for example you can influence the internal format of the texture
// using texture_set_components() and
// texture_set_premultiplied().
//
// Allocate call can fail if considers the internal
// format to be incompatible with the format of its internal
// atlases.
//
// The returned #AtlasTexture is a high-level meta-texture
// with some limitations. See the documentation for #MetaTexture
// for more details.
//
// Returns: (transfer full): A new #AtlasTexture object::
// Since: 1.16
// Stability: unstable
pub fn from_bitmap(bitmap: &Bitmap) -> AtlasTexture {
// _RETURN_VAL_IF_FAIL (is_bitmap (bmp), NULL);
// TODO: fix bitmap
let loader = TextureLoader::Bitmap {
bitmap: bitmap.clone(),
can_convert_in_place: true,
height: 0,
depth: 0,
};
Self::create_base(
&Context::global(),
bitmap.width(),
bitmap.height(),
bitmap.format(),
&loader,
)
}
// atlas_texture_new_from_data:
// @ctx: A #Context
// @width: width of texture in pixels
// @height: height of texture in pixels
// @format: the #PixelFormat the buffer is stored in in RAM
// @rowstride: the memory offset in bytes between the start of each
// row in @data. A value of 0 will make automatically
// calculate @rowstride from @width and @format.
// @data: pointer to the memory region where the source buffer resides
// @error: A #Error to catch exceptional errors or %NULL
//
// Creates a new #AtlasTexture texture based on data residing in
// memory. A #AtlasTexture represents a sub-region within one of
// 's shared texture atlases.
//
// This api will always immediately allocate GPU memory for the
// texture and upload the given data so that the @data pointer does
// not need to remain valid once this fn returns. This means it
// is not possible to configure the texture before it is allocated. If
// you do need to configure the texture before allocation (to specify
// constraints on the internal format for example) then you can
// instead create a #Bitmap for your data and use
// atlas_texture_new_from_bitmap() or use
// atlas_texture_new_with_size() and then upload data using
// texture_set_data()
//
// Allocate call can fail if considers the internal
// format to be incompatible with the format of its internal
// atlases.
//
// The returned #AtlasTexture is a high-level
// meta-texture with some limitations. See the documentation for
// #MetaTexture for more details.
//
// Return value: (transfer full): A new #AtlasTexture object or
// %NULL on failure and @error will be updated.
// Since: 1.16
// Stability: unstable
pub fn from_data(
ctx: &Context,
width: u32,
height: u32,
format: PixelFormat,
rowstride: u32,
data: &[u8],
) -> AtlasTexture {
// Bitmap *bmp;
// AtlasTexture *atlas_tex;
// _RETURN_VAL_IF_FAIL (format != PIXEL_FORMAT_ANY, NULL);
// _RETURN_VAL_IF_FAIL (data != NULL, NULL);
// Rowstride from width if not given
let rowstride = match rowstride {
0 => width * format.bytes_per_pixel(),
_ => rowstride,
};
// Wrap the data into a bitmap
// bmp = bitmap_new_for_data (ctx,
// width, height,
// format,
// rowstride,
// (uint8_t *) data);
// atlas_tex = atlas_texture_new_from_bitmap (bmp);
// object_unref (bmp);
// if atlas_tex && !texture_allocate (TEXTURE (atlas_tex), error) {
// object_unref (atlas_tex);
// return NULL;
// }
// return atlas_tex;
unimplemented!()
}
// atlas_texture_new_from_file:
// @ctx: A #Context
// @filename: the file to load
// @error: A #Error to catch exceptional errors or %NULL
//
// Creates a #AtlasTexture from an image file. A #AtlasTexture
// represents a sub-region within one of 's shared texture
// atlases.
//
// The storage for the texture is not allocated before this function
// returns. You can call texture_allocate() to explicitly
// allocate the underlying storage or let automatically allocate
// storage lazily.
//
// The texture is still configurable until it has been allocated so
// for example you can influence the internal format of the texture
// using texture_set_components() and
// texture_set_premultiplied().
//
// Allocate call can fail if considers the internal
// format to be incompatible with the format of its internal
// atlases.
//
// The returned #AtlasTexture is a high-level meta-texture
// with some limitations. See the documentation for #MetaTexture
// for more details.
//
// Return value: (transfer full): A new #AtlasTexture object or
// %NULL on failure and @error will be updated.
// Since: 1.16
// Stability: unstable
pub fn from_file(ctx: &Context, filename: &str) -> AtlasTexture {
// Bitmap *bmp;
// AtlasTexture *atlas_tex = NULL;
// _RETURN_VAL_IF_FAIL (error == NULL || *error == NULL, NULL);
// bmp = bitmap_new_from_file (filename, error);
// if (bmp == NULL)
// return NULL;
// atlas_tex = _atlas_texture_new_from_bitmap (bmp, true); // convert in-place
// object_unref (bmp);
// return atlas_tex;
unimplemented!()
}
// atlas_texture_new_with_size:
// @ctx: A #Context
// @width: The width of your atlased texture.
// @height: The height of your atlased texture.
//
// Creates a #AtlasTexture with a given @width and @height. A
// #AtlasTexture represents a sub-region within one of 's
// shared texture atlases.
//
// The storage for the texture is not allocated before this function
// returns. You can call texture_allocate() to explicitly
// allocate the underlying storage or let automatically allocate
// storage lazily.
//
// The texture is still configurable until it has been allocated so
// for example you can influence the internal format of the texture
// using texture_set_components() and
// texture_set_premultiplied().
//
// Allocate call can fail if considers the internal
// format to be incompatible with the format of its internal
// atlases.
//
// The returned #AtlasTexture is a high-level meta-texture
// with some limitations. See the documentation for #MetaTexture
// for more details.
pub fn with_size(context: &Context, width: u32, height: u32) -> AtlasTexture {
// We can't atlas zero-sized textures because it breaks the atlas
// data structure
let loader = TextureLoader::Sized {
depth: 0,
width,
height,
};
Self::create_base(context, width, height, PixelFormat::Rgba8888Pre, &loader)
}
fn create_base(
context: &Context,
width: u32,
height: u32,
internal_format: PixelFormat,
loader: &TextureLoader,
) -> Self {
unimplemented!()
}
}
impl fmt::Display for AtlasTexture {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "AtlasTexture")
}
}