Multiple Shaders?

Hello everyone… i am working on a project. My doubt is somehow relates to this…
i want to render some entities…some are simple polygons(filled with same color), some have gradient, some have texture, some have both…(see the screenshot A,B,C,D)
I am able to to this…
I prepared different shaders…
like for A--------------- (basic_shader)

    #shader vertex

    #version 130
    in vec3 pos;
    void main() 
    {
       gl_Position = vec4(pos, 1);
    } 

    #shader fragment

    #version 130

    uniform vec4 u_Color;

    void main() 
    {
        gl_FragColor = u_Color;
    } 

for B--------color_vertex_shader–

    #shader vertex

    #version 130
    in vec3 pos;
    in vec3 col;

    out vec3 eachcol;

    void main() 
    {
       gl_Position = vec4(pos, 1);
       eachcol=col;
    } 

    #shader fragment

    #version 130

    out vec4 u_Color;
    in vec3 eachcol;

    void main() 
    {
    u_Color = vec4(eachcol,1.0);
    } 

for C-----------

    #shader vertex

    #version 130
    in vec3 pos;
    in vec2 texCoord;

    out vec2 v_TexCoord;

    void main() 
    {
       gl_Position = vec4(pos, 1);
       v_TexCoord=texCoord;
    } 

    #shader fragment

    #version 130

    in vec2 v_TexCoord;

    uniform vec4 u_Color;
    uniform sampler2D u_Texture;

    void main() 
    {
    vec4 texColor = texture(u_Texture,v_TexCoord) ;
    gl_FragColor = texColor;
    } 

and for D--------------------

    #shader vertex

    #version 130
    in vec3 pos;
    in vec3 col;
    in vec2 texCoord;

    out vec3 v_Col;
    out vec2 v_TexCoord;

    void main() 
    {
       gl_Position = vec4(pos, 1);
       v_Col=col;
       v_TexCoord=texCoord;
    } 

    #shader fragment

    #version 130


    in vec3 v_Col;
    in vec2 v_TexCoord;

    uniform sampler2D u_Texture;

    void main() 
    {
        vec4 texColor = texture(u_Texture,v_TexCoord) * vec4(v_Col,1.0);
        gl_FragColor = texColor;
       
    } 

//-------
Can i make a single shader and use them for A,B,C,D ??

Yes. Just use the D shader. If you don’t want a colour or gradient, set all vertex colours to white (1,1,1). If you don’t want a texture, use a 1x1 texture containing a single white pixel.

ok…do i need to set them as uniforms in shader or in vertex data??
and after this can i use the vertex data like this…???

 float vertices_A[]={     0.8f,0.8f,0.0f,
	                  -0.8f,0.8f,0.0f,
	                  -0.8f,-0.8f,0.0f,
	                   0.8f,-0.8f,0.0f  };

float vertices_B[]={       0.8f,0.8f,0.0f,  1.0f,0.0f,0.0f,   
	                  -0.8f,0.8f,0.0f,  0.0f,1.0f,0.0f,   
	                  -0.8f,-0.8f,0.0f, 0.0f,0.0f,1.0f,  
	                   0.8f,-0.8f,0.0f, 1.0f,1.0f,0.0f   };

float vertices_C[]={       0.8f,0.8f,0.0f,  1.0f,1.0f,
	                  -0.8f,0.8f,0.0f,  0.0f,1.0f,
	                  -0.8f,-0.8f,0.0f, 0.0f,0.0f,
	                   0.8f,-0.8f,0.0f, 1.0f,0.0f  };
	                

float vertices_D[]={       0.8f,0.8f,0.0f,  1.0f,0.0f,0.0f,   1.0f,1.0f,
	                  -0.8f,0.8f,0.0f,  0.0f,1.0f,0.0f,   0.0f,1.0f,
	                  -0.8f,-0.8f,0.0f, 0.0f,0.0f,1.0f,   0.0f,0.0f,
	                   0.8f,-0.8f,0.0f, 1.0f,1.0f,0.0f,   1.0f,0.0f  };

I dont want to store unnecessary data…
can i use the Shader D with these data…
and i am varying the vertexbuffer layout accordingly

Or…
Do the D Shader expects me send data like…x,y,z, r,g,b, s,t ??
after writing this…

in vec3 pos;
in vec3 col;
in vec2 texCoord;

in D shader

If you’re talking about the vertex colors and texture coordinates, you can provide them in vertex attributes. But provide them as constant vertex attribute values rather than as vertex arrays. That way, you can use exactly the same shader for all cases but you don’t need to waste the vertex attribute array space specifying redundant values for the color and/or texcoord values.

In the case that you don’t really need a vertex color so you want to provide a constant “white” vertex color as input, just set a constant vertex attribute value with that white color (see glVertexAttrib*()). To instruct OpenGL to pull from this constant attribute value that you’ve set instead of trying to pull it in via a vertex array, call glDisableVertexAttribArray() on that attribute.

Same thing for the texture coordinate. In the case that you don’t need a texture so you just bind a white texture, you can just provide a constant vertex attribute for the texture coordinate which has some random texcoord value in it (e.g. (0.5, 0.5)).

NOTE: Here I’m assuming that you’re using a vertex array to provide the vertex position attribute (glVertexAttribPointer()).

Or you can just use the same texture coordinates as for any other quad. If the texture is a solid colour, the texture coordinates aren’t going to matter. Alternatively, you can use any texture which contains at least one white pixel, and use constant texture coordinates set to the centre of that pixel.