Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd support for shader includes. #1588
Conversation
|
I like the idea. I am not super found of hard-coding that imports need to be on the first line (if you don't know it's easy to trip on this, and the imports kinda get hidden behind the license block). but I suppose we can improve this later if turns out to be a significant annoyance. |
| const SHADER_KIND_VERTEX: &str = "#define WR_VERTEX_SHADER\n"; | ||
| const SHADER_KIND_FRAGMENT: &str = "#define WR_FRAGMENT_SHADER\n"; | ||
| const SHADER_IMPORT: &str = "//import "; | ||
| const SHADER_LINE_MARKER: &str = "#line 1\n"; |
This comment has been minimized.
This comment has been minimized.
|
This is very similar to what I ended up using in three-rs: #version 150 core
#include locals lights
...Except for:
@glennw would you agree to make these two improvements in this PR? |
| let mut source = Vec::new(); | ||
| source.extend_from_slice(s.as_bytes()); | ||
| gl.shader_source(id, &[&source[..]]); | ||
| let sources: Vec<&[u8]> = sources.iter().map(|s| s.as_bytes()).collect(); |
This comment has been minimized.
This comment has been minimized.
kvark
Aug 18, 2017
Member
I'd prefer us building a single source chunk per shader (as opposed to having an array of chunks), because OpenGL is the only API supporting multiple sources.
| let mut shared_strings = Vec::new(); | ||
| if let Some(shared_source) = get_shader_source(base_filename, &self.resource_override_path) { | ||
| parse_shader_source(shared_source, | ||
| &self.resource_override_path, |
This comment has been minimized.
This comment has been minimized.
If the first line of a shader is //import followed by a comma separated list of glsl filenames, prepend those as includes for the shader. The idea here is that we'll start splitting up prim_shared.glsl etc into smaller blocks that are faster to parse and compile, and just generally more manageable. This also supports having the VS and FS in the same glsl file. This commit ports the debug_font and debug_color shaders to this style. If we go ahead with this format, we'll incrementally port other shaders to use this style, which requires only one file per shader.
* Use #include. * Support includes on any line. * Update validation test to be closer to what we actually compile.
|
OK, updated to use |
|
Thank you! |
|
|
Add support for shader includes. If the first line of a shader is //import followed by a comma separated list of glsl filenames, prepend those as includes for the shader. The idea here is that we'll start splitting up prim_shared.glsl etc into smaller blocks that are faster to parse and compile, and just generally more manageable. This also supports having the VS and FS in the same glsl file. This commit ports the debug_font and debug_color shaders to this style. If we go ahead with this format, we'll incrementally port other shaders to use this style, which requires only one file per shader. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/1588) <!-- Reviewable:end -->
|
|
glennw commentedAug 18, 2017
•
edited by larsbergstrom
If the first line of a shader is //import followed by a comma
separated list of glsl filenames, prepend those as includes
for the shader. The idea here is that we'll start splitting
up prim_shared.glsl etc into smaller blocks that are faster
to parse and compile, and just generally more manageable.
This also supports having the VS and FS in the same glsl file. This
commit ports the debug_font and debug_color shaders to this style.
If we go ahead with this format, we'll incrementally port other
shaders to use this style, which requires only one file per shader.
This change is