-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add #insert directive for glsl shaders #1124
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the feature at least once in some shader. That way we can see how it is supposed to be used and verify that it really works.
src/engine/renderer/gl_shader.cpp
Outdated
std::string line; | ||
|
||
while ( std::getline( shaderTextStream, line, '\n' ) ) { | ||
std::string::size_type position = line.find( "#insert" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't match anywhere in the line, only at the beginning (maybe preceded by whitespace). It would be annoying if commenting it out like //#insert blah
didn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree on both. The extensions thing is something that's used throught gl_shaders.cpp IIRC, so changing all of those should probably be its own pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it will only match if #insert
is directly following whitespace characters or at the start of the line, no more fixed suffix as well. I've left the extension there because that's what we use everywhere, so having it suddenly different in one place would be confusing, plus I don't really see the benefit of dropping the extension if we're gonna put all shader code into .glsl
files anyway.
The existing "include" method (vertexInlines/fragmentInlines) uses the |
Usage is expected to be done when merging the material branch: This is simply a process of splitting that branch in smaller chunks to review and to merge separately when possible. I will not oppose at merging this as a structural foundation for what's coming. |
I agree with the idea of just writing the file name with the suffix I'm not sure for the requirement about also writing I also agree with the remark about being able to comment out an |
Like illwieckz said, it is just a smaller part of #1105. I don't support adding useless things just for the sake of an "example", this on the other hand is just something that has a proper use in another pr (that pr also shows that this works). |
I can add that, though personally I found it annoying rather than useful, because some errors didn't make sense with that directive (I had to comment it out at some points while working on #1105). |
Agreed on that, I thought the same when writing the changes in this pr, I only went with the suffixes because that's what the rest of the code that was already there was doing. |
I think it's helpful to split up a large PR even if all the work isn't used in each PR. |
OK, I thought it would be easy to add an example since once of the fragmentInlines/vertexInlines could be trivially replaced with a |
Actually, this seems like a bad idea to me now. If there's some error we'll suddenly have a line count restart in the middle of |
Done now. |
It would be trivial to do so, but I just don't see the point of it. The shaders we had worked fine with the inlines thing, so why change them just for the sake of changing? #1105 works as the example IMO. |
What do you mean? |
For example if there's:
in a shader, then you're gonna see something like this if there's an error:
I think that'd be annoying. (or whatever other order of resetting line count there) |
I was thinking mainly to have the line directive after the insertion, to maintain correct line numbers for the main file. So Additionally adding line directives at the beginning of the insertion is also possible, but it seems there is no way to set the file name to that of the included shader, so maybe there is no point. |
Actually if you have an insert on line 60, maybe the best thing would be to put |
Just an idea that crosses my mind, but I wonder if that's doable, even if ugly, to assume we will never have GLSL files of 10k lines, and then we may prefix insert with Let's imagine we have this:
We would do:
So we would get:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good enough for now, we can improve over it later.
LGTM.
Lol, that doesn't sound too bad. Something better in general than just doing #line 0 everywhere would be great, e. g. keep a table that matches the non-reset line count to filename + line, then if an error occurs try to get the reported line and lookup in that table... The problem is I don't think shader compiler errors are standardized in any way. |
This looks like a good idea to me. |
Ah, I see. To me personally either of those would look annoying though :p The other problem we have with reporting shader compiler errors is that the log gets spammed with the license text for every included file. I suppose at least it serves as a way to separate each file there lol. |
Adds the ability to insert text from a specified glsl shader file into an arbitrary place in another shader.
Squashed the small fix, no actual changes. |
Picked from #1105.
Adds the ability to insert text from a specified glsl shader file into an arbitrary place in another shader.