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
/*!
A uniform is a global variable in your program. In order to draw something, you will need to
give `glium` the values of all your uniforms. Objects that implement the `Uniform` trait are
here to do that.
There are two primarly ways to do this. The first one is to create your own structure and put
the `#[uniforms]` attribute on it. See the `glium_macros` crate for more infos.
The second way is to use the `uniform!` macro provided by glium:
```no_run
#[macro_use]
extern crate glium;
# fn main() {
# let display: glium::Display = unsafe { std::mem::uninitialized() };
# let tex: f32 = unsafe { std::mem::uninitialized() };
# let matrix: f32 = unsafe { std::mem::uninitialized() };
let uniforms = uniform! {
texture: tex,
matrix: matrix
};
# }
```
In both situations, each field must implement the `UniformValue` trait.
## Samplers
In order to customize the way a texture is being sampled, you must use a `Sampler`.
```no_run
#[macro_use]
extern crate glium;
# fn main() {
use std::default::Default;
# let display: glium::Display = unsafe { std::mem::uninitialized() };
# let texture: glium::texture::Texture2d = unsafe { std::mem::uninitialized() };
let uniforms = uniform! {
texture: glium::uniforms::Sampler::new(&texture)
.magnify_filter(glium::uniforms::MagnifySamplerFilter::Nearest)
};
# }
```
## Blocks
In GLSL, you can choose to use a uniform *block*. When you use a block, you first need to
upload the content of this block in the video memory thanks to a `UniformBuffer`. Then you
can link the buffer to the name of the block, just like any other uniform.
```no_run
#[macro_use]
extern crate glium;
# fn main() {
# let display: glium::Display = unsafe { std::mem::uninitialized() };
# let texture: glium::texture::Texture2d = unsafe { std::mem::uninitialized() };
let program = glium::Program::from_source(&display,
"
#version 110
attribute vec2 position;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
}
",
"
#version 330
uniform layout(std140);
uniform MyBlock {
vec3 color;
};
void main() {
gl_FragColor = vec4(color, 1.0);
}
",
None);
let buffer = glium::uniforms::UniformBuffer::new_if_supported(&display,
(0.5f32, 0.5f32, 0.5f32)).unwrap();
let uniforms = uniform! {
MyBlock: &buffer
};
# }
```
*/
pub use UniformBuffer;
pub use ;
pub use ;
pub use ;
pub use ;
use program;
/// Object that contains the values of all the uniforms to bind to a program.
/// Objects that are suitable for being binded to a uniform block.