Skip to content

Commit

Permalink
Add .sampled() methods to textures
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed May 9, 2015
1 parent 1f3d0df commit 84f393c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Change Log

## Unreleased

- Textures now have a `sampled()` method to make it easier to create a `Sampler`.

## Version 0.3.6 (2015-05-09)

- Added `SamplesPassedQuery` and `TimeElapsedQuery` types. They can be passed to the draw parameters.
Expand Down
21 changes: 21 additions & 0 deletions build/textures.rs
Expand Up @@ -317,6 +317,27 @@ fn build_texture<W: Write>(mut dest: &mut W, ty: TextureType, dimensions: Textur
UniformValue::{myname}(self.0, Some(self.1))
}}
}}
impl {myname} {{
/// Builds a `Sampler` marker object that allows you to indicate
/// how the texture should be sampled from inside a shader.
///
/// # Example
///
/// ```no_run
/// # #[macro_use] extern crate glium;
/// # fn main() {{
/// # let texture: glium::textures::Texture2d = unsafe {{
/// # ::std::mem::uninitialized() }};
/// let uniforms = uniform! {{
/// color_texture: texture.sampled().magnify_filter(glium::uniforms::MagnifySamplerFilter::Nearest)
/// }};
/// # }}
/// ```
pub fn sampled(&self) -> Sampler<{myname}> {{
Sampler(self, Default::default())
}}
}}
", myname = name)).unwrap();
},
_ => ()
Expand Down
3 changes: 1 addition & 2 deletions tests/samplers.rs
Expand Up @@ -63,8 +63,7 @@ fn magnify_nearest_filtering() {
let texture = glium::texture::Texture2d::new(&display, texture_data);

let uniforms = uniform! {
texture: glium::uniforms::Sampler::new(&texture)
.magnify_filter(glium::uniforms::MagnifySamplerFilter::Nearest)
texture: texture.sampled().magnify_filter(glium::uniforms::MagnifySamplerFilter::Nearest)
};

let output = support::build_renderable_texture(&display);
Expand Down

0 comments on commit 84f393c

Please sign in to comment.