Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also implement AsUniformValue for textures directly #1956

Merged
merged 2 commits into from Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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