Skip to content

Commit

Permalink
Merge pull request #1956 from strohel/asuniformvalue-for-textures-dir…
Browse files Browse the repository at this point in the history
…ectly

Also implement AsUniformValue for textures directly
  • Loading branch information
est31 committed Aug 12, 2021
2 parents a4e0b55 + 3e3365e commit 710dba0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build/textures.rs
Expand Up @@ -425,6 +425,13 @@ fn build_texture<W: Write>(dest: &mut W, ty: TextureType, dimensions: TextureDim
}}
}}
impl AsUniformValue for {myname} {{
#[inline]
fn as_uniform_value(&self) -> UniformValue {{
UniformValue::{myname}(self, None)
}}
}}
impl<'a> AsUniformValue for Sampler<'a, {myname}> {{
#[inline]
fn as_uniform_value(&self) -> UniformValue {{
Expand Down
23 changes: 23 additions & 0 deletions tests/texture_creation.rs
Expand Up @@ -86,6 +86,29 @@ fn texture_2d_creation() {
display.assert_no_error(None);
}

#[test]
fn texture_2d_as_uniform_value_lifetime() {
let display = support::build_display();

let texture = glium::texture::Texture2d::new(&display, vec![
vec![(0, 0, 0, 0), (0, 0, 0, 0)],
vec![(0, 0, 0, 0), (0, 0, 0, 0)],
vec![(0, 0, 0, 0), (0, 0, 0, 0u8)],
]).unwrap();

// A function that takes texture reference should be able to return UniformValue (with lifetime
// inherited from the reference).
fn get_uniforms(texture: &glium::texture::Texture2d) -> glium::uniforms::UniformValue {
use glium::uniforms::AsUniformValue;
texture.as_uniform_value()
}

let uniforms = get_uniforms(&texture);
assert!(matches!(uniforms, glium::uniforms::UniformValue::Texture2d(..)));

display.assert_no_error(None);
}

#[test]
fn empty_texture2d_u8u8u8u8() {
let display = support::build_display();
Expand Down

0 comments on commit 710dba0

Please sign in to comment.