Switch to one shader at a time in glsl-to-spirv

This commit is contained in:
Pierre Krieger 2016-02-16 20:01:45 +01:00
parent ea138fc79d
commit 9af3aa371f
2 changed files with 14 additions and 5 deletions

View File

@ -6,7 +6,13 @@ use std::process::Command;
pub type SpirvOutput = File;
pub fn compile<'a, I>(shaders: I) -> Result<SpirvOutput, String>
pub fn compile(code: &str, ty: ShaderType) -> Result<SpirvOutput, String> {
compile_inner(Some((code, ty)))
}
// Eventually the API will look like this, with an iterator for multiple shader stages.
// However for the moment GLSLang doesn't like that, so we only pass one shader at a time.
fn compile_inner<'a, I>(shaders: I) -> Result<SpirvOutput, String>
where I: IntoIterator<Item = (&'a str, ShaderType)>
{
let temp_dir = tempdir::TempDir::new("glslang-compile").unwrap();

View File

@ -11,22 +11,25 @@ struct S {
};
uniform sampler2D u_texture;
uniform S u_data;
uniform Block {
S u_data;
} block;
in vec2 v_texcoords;
out vec4 f_color;
void main() {
if (u_data.val2[4]) {
if (block.u_data.val2[3]) {
f_color = texture(u_texture, v_texcoords);
} else {
f_color = vec4(u_data.val1, 1.0);
f_color = vec4(1.0);
}
}
"#;
let content = glsl_to_spirv::compile(Some((shader, glsl_to_spirv::ShaderType::Fragment))).unwrap();
let content = glsl_to_spirv::compile(shader, glsl_to_spirv::ShaderType::Fragment).unwrap();
let output = vulkano_shaders::reflect("Shader", content).unwrap();
println!("{}", output);
}