kidanger / vpv

Image viewer for image processing experts
GNU General Public License v3.0
125 stars 18 forks source link

Refactor the Shader class #58

Closed ronnychevalier closed 3 years ago

ronnychevalier commented 3 years ago

The Shader class contains only the Shader part. It creates a shader and compiles it. A template is present to simplify the construction of a shader.

Shader::Vertex(code);

The Programm class builds a program, attach shaders, and link them. Then, it detaches the shaders. Program is built with a list of Shader as a parameter:

new Shader::Program({
                Shader::Vertex(code_vertex),
                Shader::Fragment(code_fragment)
           });

Both Shader and Program cannot be copied (to avoid use after free), but they implement move semantics (thus allowing the construction above).

They have been but in a namespace since they are all related to shaders, and to avoid duplicating the name Shader everywhere in the class names.

The Program also has a cache of the uniforma locations to avoid calling glGetUniformLocation function.