Can i use just those two shaders when they are rendered?
Say the position is defined as in vec3 in_vertex;
The normals are defined as in vec3 in_normal;
uniform mat4 matproj;
uniform mat4 matview;
in vec3 in_vertex; // these in statements is what makes this a unique shader that works for a specific mesh format
in vec3 in_normal; // what this means is that the mesh format provides (x, y, z) (nx, ny, nz) and (r, g, b, a)
in vec4 in_color;
out vec4 out_color;
gl_Position = matproj * matview * vec4(in_vertex, 1.0); // a valid vertex shader MUST set gl_Position (that's the only requirement)
out_color = in_color;
A basic shader which transforms a vertex, and passes a color attribute to the fragment shader. Notice how we don't use in_normal, yet I still defined it.
You can make a copy of this shader, and as long as the attributes (in's) are the same, and the shader is valid, you can use it for ANY mesh that has this structure defined.
If the model also provided uvs, then I could not use them, simply because I didn't define them in the shader. It doesn't matter if the model provides 30 attributes, what matters is which of them I use in the shader, and which attributes have been enabled before rendering.
I imagine the answer to your question is yes. Their formats should be similar. What those formats look like is defined by your attrib statements when forming the VAO. The shader doesn't care if the model uses SHORT or FLOAT for (x, y, z) as long as the bindings are correct, and the number of elements are the same.
The binding is towards the string "in_vertex" and the number of elements is 3 as in "vec3" --> in vec3 in_vertex;
Whether or not the model stores (x, y, z) as float or short is not important, because you define that with attrib array pointer, which is tied to an index value.
To a shader these statements are the same:
glVertexAttribPointer(0, 3, GL_SHORT, GL_FALSE, sizeof(vertex_t), (void*) offsetof(vertex_t, x )); // vertex
Is the same as:
glVertexAttribPointer(0, 3, GL_FLOAT GL_FALSE, sizeof(vertex_t), (void*) offsetof(vertex_t, x )); // vertex
The difference is how the data is treated, but you just defined that. You are making a promise to OpenGL that the data you provided are of a specific type, and should be treated so and so. The shader must know there is an index 0, and that index is typically the position of the vertex (x,y,z) which in my example above would be "in_vertex."
Other than that, you just provide what indexes you want. Enabling and disabling them.
Edited by Kaptein, 19 January 2014 - 02:50 PM.