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

Shared clip source for the shaders #444

Merged
merged 3 commits into from Oct 14, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Refactored shader path formation and includes

  • Loading branch information
kvark committed Oct 14, 2016
commit bc1689f95904c081fb306e4db67371ff09acd70f
@@ -1155,37 +1155,33 @@ impl Device {
pub fn create_program(&mut self,
base_filename: &str,
include_filename: &str) -> ProgramId {
self.create_program_with_prefix(base_filename, include_filename, None)
self.create_program_with_prefix(base_filename, &[include_filename], None)
}

pub fn create_program_with_prefix(&mut self,
base_filename: &str,
include_filename: &str,
include_filenames: &[&str],
prefix: Option<String>) -> ProgramId {
debug_assert!(self.inside_frame);

let pid = gl::create_program();
let base_path = self.resource_path.join(base_filename);

let mut vs_path = self.resource_path.clone();
vs_path.push(&format!("{}.vs.glsl", base_filename));
let vs_path = base_path.with_extension("vs.glsl");
//self.file_watcher.add_watch(vs_path.clone());

let mut fs_path = self.resource_path.clone();
fs_path.push(&format!("{}.fs.glsl", base_filename));
let fs_path = base_path.with_extension("fs.glsl");
//self.file_watcher.add_watch(fs_path.clone());

let mut include_path = self.resource_path.clone();
include_path.push(&format!("{}.glsl", include_filename));
let mut f = File::open(&include_path).unwrap();
let mut include = String::new();
f.read_to_string(&mut include).unwrap();
for inc_filename in include_filenames {
let include_path = self.resource_path.join(inc_filename).with_extension("glsl");
File::open(&include_path).unwrap().read_to_string(&mut include).unwrap();
}

let mut shared_path = self.resource_path.clone();
shared_path.push(&format!("{}.glsl", base_filename));
let shared_path = base_path.with_extension("glsl");
if let Ok(mut f) = File::open(&shared_path) {
let mut shared_code = String::new();
f.read_to_string(&mut shared_code).unwrap();
include.push_str(&shared_code);
f.read_to_string(&mut include).unwrap();
}

let program = Program {
@@ -269,8 +269,9 @@ fn create_prim_shader(name: &'static str,
prefix.push_str(&format!("#define WR_FEATURE_{}\n", feature));
}

let includes = &["prim_shared"];
let program_id = device.create_program_with_prefix(name,
"prim_shared",
includes,
Some(prefix));

let data_index = gl::get_uniform_block_index(program_id.0, "Data");
@@ -288,8 +289,9 @@ fn create_clear_shader(name: &'static str,
max_ubo_vectors: usize) -> ProgramId {
let prefix = format!("#define WR_MAX_UBO_VECTORS {}", max_ubo_vectors);

let includes = &["shared_other"];
let program_id = device.create_program_with_prefix(name,
"shared_other",
includes,
Some(prefix));

let data_index = gl::get_uniform_block_index(program_id.0, "Data");
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.