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
279
280
#![allow(
clippy::too_many_arguments,
clippy::let_and_return,
clippy::from_over_into
)]
use super::{Bitmap, Context, PixelFormat, Texture, TextureLoader};
use std::{fmt, ptr};
// @extends Object, @implements Texture;
pub struct Texture3D {
// Texture _parent;
// The internal format of the texture represented as a
// PixelFormat */
// PixelFormat internal_format;
// int depth;
// Bool auto_mipmap;
// Bool mipmaps_dirty;
// TODO: factor out these OpenGL specific members into some form
// of driver private state. */
// The internal format of the GL texture represented as a GL enum */
// GLenum gl_format;
// The texture object number */
// GLuint gl_texture;
// GLenum gl_legacy_texobj_min_filter;
// GLenum gl_legacy_texobj_mag_filter;
// GLint gl_legacy_texobj_wrap_mode_s;
// GLint gl_legacy_texobj_wrap_mode_t;
// GLint gl_legacy_texobj_wrap_mode_p;
// TexturePixel first_pixel;
}
impl Texture3D {
// texture_3d_new_from_bitmap:
// @bitmap: A #Bitmap object::
// @height: height of the texture in pixels.
// @depth: depth of the texture in pixels.
//
// Creates a low-level 3D texture and initializes it with the images
// in @bitmap. The images are assumed to be packed together after one
// another in the increasing y axis. The height of individual image is
// given as @height and the number of images is given in @depth. The
// actual height of the bitmap can be larger than @height × @depth. In
// this case it assumes there is padding between the images.
//
// 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 going to be 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().
//
// This texture will fail to allocate later if
// %FEATURE_ID_TEXTURE_3D is not advertised. Allocation can also
// fail if the requested dimensions are not supported by the
// GPU.
//
// Return value: (transfer full): a newly created #Texture3D
// Since: 2.0
// Stability: unstable
pub fn from_bitmap(bitmap: &Bitmap, height: u32, depth: u32) -> Texture3D {
// _RETURN_VAL_IF_FAIL (bmp, NULL);
let loader = TextureLoader::Bitmap {
bitmap: bitmap.clone(),
can_convert_in_place: false, // TODO add api for this
depth,
height,
};
Self::create_base(
&Context::global(),
bitmap.width(),
height,
depth,
bitmap.format(),
&loader,
)
}
// texture_3d_new_from_data:
// @context: a #Context
// @width: width of the texture in pixels.
// @height: height of the texture in pixels.
// @depth: depth of the texture in pixels.
// @format: the #PixelFormat the buffer is stored in in RAM
// @rowstride: the memory offset in bytes between the starts of
// scanlines in @data or 0 to infer it from the width and format
// @image_stride: the number of bytes from one image to the next. This
// can be used to add padding between the images in a similar way
// that the rowstride can be used to add padding between
// rows. Alternatively 0 can be passed to infer the @image_stride
// from the @height.
// @data: pointer the memory region where the source buffer resides
// @error: A Error return location.
//
// Creates a low-level 3D texture and initializes it with @data. The
// data is assumed to be packed array of @depth images. There can be
// padding between the images using @image_stride.
//
// 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
// texture_3d_new_from_bitmap().
//
// Return value: (transfer full): the newly created #Texture3D or
// %NULL if there was an error and an exception will be
// returned through @error.
// Since: 1.10
// Stability: Unstable
pub fn from_data(
context: &Context,
width: u32,
height: u32,
depth: u32,
format: PixelFormat,
rowstride: u32,
image_stride: u32,
data: &[u8],
) -> Texture3D {
// Bitmap *bitmap;
// Texture3D *ret;
// _RETURN_VAL_IF_FAIL (data, NULL);
// _RETURN_VAL_IF_FAIL (format != PIXEL_FORMAT_ANY, NULL);
// Rowstride from width if not given
let rowstride = match rowstride {
0 => width * format.bytes_per_pixel(),
_ => rowstride,
};
// Image stride from height and rowstride if not given
// if (image_stride == 0)
// image_stride = height * rowstride;
// if (image_stride < rowstride * height)
// return NULL;
// GL doesn't support uploading when the image_stride isn't a
// multiple of the rowstride. If this happens we'll just pack the
// image into a new bitmap. The documentation for this function
// recommends avoiding this situation.
// if (image_stride % rowstride != 0)
// {
// uint8_t *bmp_data;
// int bmp_rowstride;
// int z, y;
// bitmap = _bitmap_new_with_malloc_buffer (context,
// width,
// depth * height,
// format,
// error);
// if (!bitmap)
// return NULL;
// bmp_data = _bitmap_map (bitmap,
// BUFFER_ACCESS_WRITE,
// BUFFER_MAP_HINT_DISCARD,
// error);
// if (bmp_data == NULL)
// {
// object_unref (bitmap);
// return NULL;
// }
// bmp_rowstride = bitmap_get_rowstride (bitmap);
// /* Copy all of the images in */
// for (z = 0; z < depth; z++)
// for (y = 0; y < height; y++)
// memcpy (bmp_data + (z * bmp_rowstride * height +
// bmp_rowstride * y),
// data + z * image_stride + rowstride * y,
// bmp_rowstride);
// _bitmap_unmap (bitmap);
// } else {
// bitmap = bitmap_new_for_data (context,
// width,
// image_stride / rowstride * depth,
// format,
// rowstride,
// (uint8_t *) data);
// }
// ret = texture_3d_new_from_bitmap (bitmap,
// height,
// depth);
// object_unref (bitmap);
// if ret && !texture_allocate (TEXTURE (ret), error) {
// object_unref (ret);
// return NULL;
// }
// return ret;
unimplemented!()
}
// texture_3d_new_with_size:
// @context: a #Context
// @width: width of the texture in pixels.
// @height: height of the texture in pixels.
// @depth: depth of the texture in pixels.
//
// Creates a low-level #Texture3D texture with the specified
// dimensions and pixel format.
//
// 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 going to be 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().
//
// This texture will fail to allocate later if
// %FEATURE_ID_TEXTURE_3D is not advertised. Allocation can also
// fail if the requested dimensions are not supported by the
// GPU.
//
// Returns: (transfer full): A new #Texture3D object with no storage yet allocated.
// Since: 1.10
// Stability: Unstable
pub fn with_size(context: &Context, width: u32, height: u32, depth: u32) -> Texture3D {
let loader = TextureLoader::Sized {
depth,
width,
height,
};
Self::create_base(
context,
width,
height,
depth,
PixelFormat::Rgba8888Pre,
&loader,
)
}
fn create_base(
context: &Context,
width: u32,
height: u32,
depth: u32,
internal_format: PixelFormat,
loader: &TextureLoader,
) -> Self {
unimplemented!()
}
}
impl fmt::Display for Texture3D {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Texture3D")
}
}