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
use super::BufferUpdateHint;
use bytes::Bytes;
// SECTION:buffer
// @short_description: Common buffer functions, including data upload APIs
// @stability: unstable
//
// The CoglBuffer API provides a common interface to manipulate
// buffers that have been allocated either via pixel_buffer_new()
// or attribute_buffer_new(). The API allows you to upload data
// to these buffers and define usage hints that help Cogl manage your
// buffer optimally.
//
// Data can either be uploaded by supplying a pointer and size so Cogl
// can copy your data, or you can mmap() a CoglBuffer and then you can
// copy data to the buffer directly.
//
// One of the most common uses for CoglBuffers is to upload texture
// data asynchronously since the ability to mmap the buffers into
// the CPU makes it possible for another thread to handle the IO
// of loading an image file and unpacking it into the mapped buffer
// without blocking other Cogl operations.
#[derive(Debug, Clone)]
pub enum BufferFlags {
None = 0,
BufferObject = 1 << 0, // real openGL buffer object
Mapped = 1 << 1,
MappedFallback = 1 << 2,
}
impl Default for BufferFlags {
fn default() -> Self {
Self::None
}
}
#[derive(Debug, Clone)]
pub enum BufferUsageHint {
Texture,
AttributeBuffer,
IndexBuffer,
}
impl Default for BufferUsageHint {
fn default() -> Self {
Self::Texture
}
}
#[derive(Debug, Clone)]
pub enum BufferBindTarget {
PixelPack,
PixelUnpack,
AttributeBuffer,
IndexBuffer,
Count,
}
impl Default for BufferBindTarget {
fn default() -> Self {
Self::PixelPack
}
}
#[derive(Default, Debug, Clone)]
pub struct Buffer {
// vtable: BufferVtable,
last_target: BufferBindTarget,
flags: BufferFlags,
// OpenGL handle
// GLuint gl_handle;
// size of the buffer, in bytes
size: u32,
usage_hint: BufferUsageHint,
update_hint: BufferUpdateHint,
// points to the mapped memory when the CoglBuffer is a VBO, PBO,
// ... or points to allocated memory in the fallback paths
data: Bytes, //&[u8],
immutable_ref: i32,
store_created: bool,
}