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

Remove Bytes enum from ShaderSource #359

Closed
kvark opened this issue Sep 4, 2014 · 6 comments
Closed

Remove Bytes enum from ShaderSource #359

kvark opened this issue Sep 4, 2014 · 6 comments

Comments

@kvark
Copy link
Member

kvark commented Sep 4, 2014

http://www.rust-ci.org/gfx-rs/gfx-rs/doc/device/shade/type.Bytes.html

It was needed when we had an explicit task boundary. No need to wrap owned stuff now.

As a bonus, make sure shaders! macro accepts a trailing comma in the parameters.

cc @Kimundi

@Kimundi
Copy link
Contributor

Kimundi commented Sep 7, 2014

I'm not sure what exactly is supposed to change here.

I thought we had the Bytes enum to allow both static construction with the macro, and dynamic loading of shader sources?

@kvark
Copy link
Member Author

kvark commented Sep 7, 2014

@Kimundi We don't need to send it now, so we can instead just have a &'a str for every variant of the shader.

emberian added a commit to emberian/gfx-rs that referenced this issue Nov 6, 2014
Since the Device isn't behind a task anymore, these don't need to be owned
ever.

Closes gfx-rs#359
@gaudecker
Copy link
Contributor

How could I adapt my function to this change? I get lifetime error if I try to give src.as_bytes() to ShaderSource.

fn load_shader_source(filename: &str) -> IoResult<gfx::ShaderSource> {
    let mut f = match File::open(&Path::new(filename)) {
        Err(why) => panic!("Could not open {}: {}", filename, why.desc),
        Ok(file) => file
    };
    let mut src = match f.read_to_string() {
        Err(why) => panic!("Could not read shader from {}: {}", filename, why.desc),
        Ok(src) => src
    };

    Ok(gfx::ShaderSource {
        glsl_120: None,
        glsl_130: None,
        glsl_140: None,
        glsl_150: Some(gfx::OwnedBytes(src.into_bytes()))
    })
}

@kvark
Copy link
Member Author

kvark commented Nov 10, 2014

@gaudecker it's not going to be a one liner for you. As far as I see, you want to (reasonably) detach the shader code reading from shader creation, in which case there needs to be some sort of container with owned data (provided by you).

The simplest you could do is to return a String from this function, and then only create gl::ShaderSource when you are uploading the shader code.

@brendanzab
Copy link
Contributor

@gaudecker ooh - you are making this? https://github.com/gaudecker/rust-theft-auto

@gaudecker
Copy link
Contributor

@kvark That's what I was thinking of as well. Thanks.
@bjz Yeah, trying at least. :)

adamnemecek pushed a commit to adamnemecek/gfx that referenced this issue Apr 1, 2021
359: Make examples work again r=kvark a=GabrielMajeri

This PR fixes the C example code to not crash and actually run.

I've also added a few assertions to ensure a warning is emitted next time somebody forgots to increase `max_bind_groups` to something non-zero on device creation.

To help with debugging the examples, I've configured CMake to include debug info in the builds. Some new Makefile targets for the examples have been added to automate running them.

Co-authored-by: Gabriel Majeri <gabriel.majeri6@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants