In graphical applications, why are shaders loaded into the application at runtime?

Shaders written, for example, GLSL, are usually loaded into the graphics application at runtime. I'm wondering why not just compile the application with shaders so that they do not need to be downloaded later. Like this:

#define glsl(version, glsl) "#version " #version "\n" #glsl

namespace glsl { namespace vs {
//VERTEX SHADERS
//=========================
// simple VS
//=========================
constexpr GLchar * const simple = glsl(450 core, 
    layout(location = 0) in vec3 position;

    void main() {
        gl_Position = vec4(position, 1.0f);
    }
    );

} namespace fs {
//FRAGMENT SHADERS
//=========================
// simple FS
//=========================
constexpr GLchar * const simple = glsl(450 core,
    out vec4 color;

    void main() {
        color = vec4(1.0f, 0.0f, 0.0f, 1.0f);
    }       
    );

} }

I do not think that this will lead to a too large exe file, and this will speed up the loading time; if I'm not mistaken about how many shaders are used for a typical graphical application. I understand that you can update the shaders after compilation, but is this really happening?

Is there a reason why I do not want to do this?

+4
source share
3

:

  • "" , . , .
  • , (, , GPU ). , , , .
  • , , / , , . .
  • , . , ( , , Windows Resources), . , , , , , . , ( , ), , .
+3

, ? !

, , fopen ( std::ifstream CreateFile - ), , . , , , , ; mmaped , , - .

: http://lkml.iu.edu/hypermail/linux/kernel/0004.0/0728.html

API OpenGL , GLSL . API (glShaderBinary, glProgramBinary), , , , GLSL, , GLSL, OpenGL.

+1

OpenGL glsl, , , .

, , , .. , , 10 , // . hardcoding , , , !

-1

Source: https://habr.com/ru/post/1676301/


All Articles