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
use super::{Bitmap, Context, PixelFormat, Texture, TextureLoader};
use std::{fmt, ptr};
// @extends Object, @implements Texture;
pub struct Texture2D {
// Texture _parent;
// The internal format of the GL texture represented as a
// PixelFormat */
// PixelFormat internal_format;
// Bool auto_mipmap;
// Bool mipmaps_dirty;
// Bool is_foreign;
// 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_internal_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;
// TexturePixel first_pixel;
}
impl Texture2D {
/// Wraps an existing GL_TEXTURE_2D texture object as a `Texture2D`.
/// This can be used for integrating with software using OpenGL
/// directly.
///
/// The texture is still configurable until it has been allocated so
/// for example you can declare whether the texture is premultiplied
/// with `Texture::set_premultiplied`.
///
/// The results are undefined for passing an invalid `gl_handle`
/// or if `width` or `height` don't have the correct texture
/// geometry.
///
/// ## `ctx`
/// A `Context`
/// ## `gl_handle`
/// A GL handle for a GL_TEXTURE_2D texture object
/// ## `width`
/// Width of the foreign GL texture
/// ## `height`
/// Height of the foreign GL texture
/// ## `format`
/// The format of the texture
///
/// # Returns
///
/// A newly allocated `Texture2D`
pub fn gl_new_from_foreign(
ctx: &Context,
gl_handle: u32,
width: i32,
height: i32,
format: PixelFormat,
) -> Texture2D {
// ffi::texture_2d_gl_new_from_foreign
unimplemented!()
}
pub fn from_bitmap(bitmap: &Bitmap) -> Texture2D {
// _RETURN_VAL_IF_FAIL (bmp != NULL, NULL);
let loader = TextureLoader::Bitmap {
bitmap: bitmap.clone(),
can_convert_in_place: false,
height: 0,
depth: 0,
};
Self::create_base(
&Context::global(),
bitmap.width(),
bitmap.height(),
bitmap.format(),
&loader,
)
}
pub fn from_data(
ctx: &Context,
width: u32,
height: u32,
format: PixelFormat,
rowstride: u32,
data: &[u8],
) -> Texture2D {
// Bitmap *bmp;
// Texture2D *tex_2d;
// _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);
// tex_2d = texture_2d_new_from_bitmap (bmp);
// object_unref (bmp);
// if (tex_2d &&
// !texture_allocate (TEXTURE (tex_2d), error))
// {
// object_unref (tex_2d);
// return NULL;
// }
// return tex_2d;
unimplemented!()
}
pub fn from_file(ctx: &Context, filename: &str) -> Texture2D {
// Bitmap *bmp;
// Texture2D *tex_2d = NULL;
// _RETURN_VAL_IF_FAIL (error == NULL || *error == NULL, NULL);
// bmp = _bitmap_from_file (ctx, filename, error);
// if (bmp == NULL)
// return NULL;
// tex_2d = _texture_2d_new_from_bitmap (bmp,
// true); /* can convert in-place */
// object_unref (bmp);
// return tex_2d;
unimplemented!()
}
pub fn with_size(context: &Context, width: u32, height: u32) -> Texture2D {
let loader = TextureLoader::Sized {
depth: 0,
width: 0,
height: 0,
};
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 Texture2D {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Texture2D")
}
}