Closed Gatsby23 closed 2 years ago
That's a good question and I'm still happy about the solution, even if it is a little bit of magic involved.
First, the cmake command COMPILE_SHADER takes the code in the text file and copies it into a class CacheInitializer
(see the corresponding cpp files in the build folder). There the constructor gets an instance of the GlShaderCache
and adds the corresponding shader sources from the COMPILE_SHADER macro.
Now comes the magic: the CacheInitializer
is used as a static variable: static CacheInitalizer __init__;
inside the same cpp file. :tada:
The static variable will be initialized as you define it using the constructor. Thus it will add the shader sources to the cache, et voila. The shaders are added without explicitly calling ever some initialization code!
You just have to now link the cpp into the binary and that's it. Real magic! :tophat: :sparkle:
Hi, I'm impressed by your work SuMa. It's a great work of lidar mapping in large-environment. But I'm confused about the function GlShader::fromCache(ShaderType::VERTEX_SHADER, "shader/gen_vertexmap.vert"). I'm sorry I can't figure out how to find the file "gen_vertexmap.vert" in this function. I have noticed that the COMPILE_SHADER in your CMakeLists.txt and some other tricks. Could you please give me some help about how to implment this function and how it works? I really need your help. Thank you very much