Package glitter :: Package convenience :: Module defaultpipeline
[hide private]
[frames] | no frames]

Source Code for Module glitter.convenience.defaultpipeline

 1  """Shader program emulating the traditional OpenGL default pipeline. 
 2   
 3  @author: Stephan Wenger 
 4  @date: 2012-03-06 
 5  """ 
 6   
 7  from glitter.shaders import ShaderProgram 
 8   
 9  vertex_code = """ 
10  #version 400 core 
11   
12  #define MODELVIEW 1 
13  #define COLOR 1 
14   
15  layout(location=0) in vec4 in_position; 
16  #if COLOR 
17  layout(location=1) in vec4 in_color; 
18  #endif 
19  #if MODELVIEW 
20  uniform mat4 modelview_matrix; 
21  #endif 
22  out vec4 ex_color; 
23   
24  void main() { 
25      #if MODELVIEW 
26      gl_Position = modelview_matrix * in_position; 
27      #else 
28      gl_Position = in_position; 
29      #endif 
30      #if COLOR 
31      ex_color = in_color; 
32      #else 
33      ex_color = vec4(1.0); 
34      #endif 
35  } 
36  """ 
37  """Default vertex shader.""" 
38   
39  fragment_code = """ 
40  #version 400 core 
41   
42  in vec4 ex_color; 
43  layout(location=0) out vec4 out_color; 
44   
45  void main() { 
46      out_color = ex_color; 
47  } 
48  """ 
49  """Default fragment shader.""" 
50   
51 -def get_default_program(modelview=True, color=True, context=None):
52 """Get a shader program emulating the default pipeline. 53 54 The program has two inputs, C{in_position} and (optionally) C{in_color}; 55 one output, C{out_color}; and (optionally) one uniform variable, 56 C{modelview_matrix}. 57 58 @param modelview: Whether to use the modelview matrix. 59 @type modelview: C{bool} 60 @param color: Whether to use colors. 61 @type color: C{bool} 62 @param context: The context to create the program in, or C{None} for the current context. 63 @type context: L{Context} 64 @rtype: L{ShaderProgram} 65 """ 66 67 vertex = vertex_code 68 if not modelview: 69 vertex = vertex.replace("#define MODELVIEW 1", "#define MODELVIEW 0") 70 if not color: 71 vertex = vertex.replace("#define COLOR 1", "#define COLOR 0") 72 return ShaderProgram(vertex=vertex, fragment=fragment_code, context=context)
73 74 __all__ = ["vertex_code", "fragment_code", "get_default_program"] 75