My code approaches GLSL shader management in the way, that it creates each shader and the associated program and deletes each shader and program. I recently read http://www.opengl.org/wiki/GLSL_Object and there it is stated that:
The shader object, due to being attached to the program object, will continue to exist even if you delete the shader object. It will only be deleted by the system when it is no longer attached to any program object (and when the user has asked to delete it, of course).
Do I get this correctly, if I call glDeleteShader()
on the shader object after linking to the program, I only need to track the program? Is it safe to assume this is always true?
One way to speed up GLSL code, is by marking some variables constant at compile-time. This way the compiler may optimize code (e.g. unroll loops) and remove unused code (e.g. if hard shadows are disabled). The drawback is that changing these constant variables requires that the GLSL code is compiled again.
Shaders use GLSL (OpenGL Shading Language), a special OpenGL Shading Language with syntax similar to C. GLSL is executed directly by the graphics pipeline. There are several kinds of shaders, but two are commonly used to create graphics on the web: Vertex Shaders and Fragment (Pixel) Shaders.
GLSL is the shading language for OpenGL, therefore GLSL code is executed on the GPU. Why GLSL is better at rendering than normal c/c++? It's not better or worse; you cannot use one for the other. You cannot just throw random C-code at a GPU as part of the rendering pipeline.
You can also open and edit GLSL files with source code editors, such as Microsoft Visual Studio Code (multiplatform). Since GLSL files are saved in plain text, you can use any text editor, such as Microsoft Notepad (bundled with Windows), Apple TextEdit (bundled with macOS), or gedit (Linux) to open and edit them.
Yes -- in fact it is highly desireable to detach and delete your shader objects as soon as possible. That way the driver can free up all the memory it is using to hold a copy of the shader source and unlinked object code, which can be quite substantial. Measurements I have done indicate that NOT deleting the shader objects increases the incremental memory use per shader by 5-10x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With