title: OpenGL ES 2.0 Multiple Programs or Multiple Shaders or what? How does it work?
body: <h2>The Problem (TL;DR)</h2>
  
  <p>My problem, fundamentally, is that I do not know how OpenGL ES 2.0 expects me to write and use multiple shaders; or if it is even advisable/expected that a person will do so.</p>
  
  <p>The fundamental question here is: if I have an apple, a glowing rock and a fuzzy mesh, all in the same 3D world, all best drawn with different shader programs but using the same mvpMatrix then how would I go about using all of them in the same OpenGL render such that they all use their most appropriate shaders that I have written?</p>
  
  <h2>What Have I done</h2>
  
  <p>So I have written a basic OpenGL ES 2.0 program for my Android Game that works perfectly in that it can draw the outline of the objects to the screen. But it does nothing else; pretty much because the shaders look like this:</p>
  
  <h3>Vertex Shader</h3>
  
  <pre><code>uniform mat4 uMVPMatrix;
  attribute vec4 aPosition;
  
  void main() {
      gl_Position = uMVPMatrix * aPosition;
  }
  </code></pre>
  
  <h3>Fragment Shader</h3>
  
  <pre><code>void main() {
      gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
  }
  </code></pre>
  
  <p>Now they are pretty basic. The reason that I have not gone further is because I cannot figure out if I am supposed to write one shader to apply to all of my different objects or if I am supposed to use multiple shaders. And if I am supposed to use multiple shaders to draw multiple different objects then how do I go about doing that in an efficient way?</p>
  
  <p>I get the feeling that this must be basic knowledge to anybody that does OpenGL ES 2.0 day in and day out so I am hoping that somebody can answer my question or point me in the right direction.</p>
  
  <p>I have:</p>
  
  <ul>
  <li>Looked at multiple tutorials; none of which use anything but the most basic shaders.</li>
  <li>Read the entire OpenGL ES 2.0 GLSL Spec (none of which mentioned how it was intended to be used; it was just about what everything did rather than how it fits together).</li>
  <li>Tried to modify my shaders a bit.</li>
  </ul>
  
  <p>So I'm hoping that I am close to understanding the OpenGL workflow but I don't seem to be there yet. </p>
  
  <p>Edit: I found this well afterwards:</p>
  
  <blockquote>
    <p>If your application is written for OpenGL ES 2.0, do not create a single shader with lots of switches and conditionals that performs every task your application needs to render the scene. Instead, compile multiple shader programs that each perform a specific, focused task.</p>
  </blockquote>
  
  <p>That is from the <a href="http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/Performance/Performance.html#//apple_ref/doc/uid/TP40008793-CH105-SW11" rel="noreferrer">iOS OpenGL ES 2.0 guidelines.</a></p>