You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've a shader whose source is a File (obtained via Shader::sourceFromFile).
If I want to update it, I'm calling File::reload. This does not work.
The sequence of operation that this causes is this:
reload call changed (once),
This calls Shader::notifyChanged that calls updateSource
This calls File::string and this triggers File::loadFromFileContent (so far, so good)
This then calls Shader::invalidate that sets compile flags to false
This calls Shader::changed and this triggers Program::invalidate
This set the dirty flag
[Later on, code that use program does this:]
In Program::use it's calling checkDirty (which is true)
It calls Program::link that's not compiling the shaders (but re-linking old compiled shaders)
Solution:
Compile shaders when the program is dirty (seems logical, not all user have a NVidia card that compile shaders when told to link them). Please notice that Program::compileAttachedShaders is protected and thus, not callable from user code. We can still call Shader::compile but this forces to keep a pointer on the shader (and that's exactly what Program is now doing, right?)
Also, I think there is too much abuse of the ChangeListener pattern here so the system is convoluted with many boolean to keep track of states. It would be so much easier if the Program was a listener of the Shader's AbstractStringSource directly, since the double listener triggering is useless in that case.
The only thing that can be modified in a Shader is its source. So why should they be in the Listener callchain instead of the source itself? Typically, Shader::updateSource or invalidate is misleading, since it does not cause reloading the source's text from the AbstractStringSource.
BTW, the error return is not checked in Shader::updateSource implementation, thus any error in the shader code will get silenced is using reload feature (at ShadingLanguageIncludeImplementation_ShadingLanguageIncludeARB.cpp line 26).
I guess you should check it explicitely in updateSources and throw a message upon error.
Or, if the Program is compiling the shader automatically, you'll get the error at that time, that's a good workaround too.
The text was updated successfully, but these errors were encountered:
I've a shader whose source is a
File
(obtained viaShader::sourceFromFile
).If I want to update it, I'm calling
File::reload
. This does not work.The sequence of operation that this causes is this:
reload
callchanged
(once),Shader::notifyChanged
that callsupdateSource
File::string
and this triggersFile::loadFromFileContent
(so far, so good)Shader::invalidate
that sets compile flags to falseShader::changed
and this triggersProgram::invalidate
[Later on, code that
use
program does this:]Program::use
it's callingcheckDirty
(which is true)Program::link
that's not compiling the shaders (but re-linking old compiled shaders)Solution:
Compile shaders when the program is dirty (seems logical, not all user have a NVidia card that compile shaders when told to link them). Please notice that
Program::compileAttachedShaders
is protected and thus, not callable from user code. We can still callShader::compile
but this forces to keep a pointer on the shader (and that's exactly whatProgram
is now doing, right?)Also, I think there is too much abuse of the
ChangeListener
pattern here so the system is convoluted with many boolean to keep track of states. It would be so much easier if the Program was a listener of the Shader's AbstractStringSource directly, since the double listener triggering is useless in that case.The only thing that can be modified in a Shader is its source. So why should they be in the Listener callchain instead of the source itself? Typically,
Shader::updateSource
orinvalidate
is misleading, since it does not cause reloading the source's text from the AbstractStringSource.BTW, the error return is not checked in
Shader::updateSource
implementation, thus any error in the shader code will get silenced is usingreload
feature (atShadingLanguageIncludeImplementation_ShadingLanguageIncludeARB.cpp
line 26).I guess you should check it explicitely in
updateSources
and throw a message upon error.Or, if the Program is compiling the shader automatically, you'll get the error at that time, that's a good workaround too.
The text was updated successfully, but these errors were encountered: