Module glium::uniforms [] [src]

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:

#[macro_use]
extern crate glium;

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.

#[macro_use]
extern crate glium;

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.

#[macro_use]
extern crate glium;

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(&display, (0.5f32, 0.5f32, 0.5f32)).unwrap();

let uniforms = uniform! {
    MyBlock: &buffer
};

Structs

EmptyUniforms

Object that can be used when you don't have any uniforms.

Sampler

A sampler.

SamplerBehavior

Behavior of a sampler.

UniformBuffer

Buffer that contains a uniform block.

UniformsStorage

Stores uniforms.

Enums

LayoutMismatchError

Error about a block layout mismatch.

MagnifySamplerFilter

The function that the GPU will use when loading the value of a texel.

MinifySamplerFilter

The function that the GPU will use when loading the value of a texel.

SamplerWrapFunction

Function to use for out-of-bounds samples.

UniformType

Type of a uniform in a program.

UniformValue

Represents a value to bind to a uniform.

Traits

AsUniformValue

Value that can be used as the value of a uniform.

UniformBlock

Objects that are suitable for being inside a uniform block or a SSBO.

Uniforms

Object that contains the values of all the uniforms to bind to a program.