/usr/share/pyshared/glitch/shader.py is in python-glitch 0.6-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | "Shader support."
from __future__ import with_statement
import OpenGL.GL as gl
import OpenGL.GL.shaders as shaders
import glitch
from glitch.multicontext import MultiContext
class Shader(glitch.Node, MultiContext):
"An OpenGL vertex and fragment shader."
_context_key = 'shader'
vertex = """
varying vec4 vertex_color;
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vertex_color = gl_Color;
}
"""
fragment = """
varying vec4 vertex_color;
void main() {
gl_FragColor = vertex_color;
}
"""
def __init__(self, vertex=None, fragment=None, **kw):
if vertex:
self.vertex = vertex
if fragment:
self.fragment = fragment
glitch.Node.__init__(self, **kw)
MultiContext.__init__(self)
def compile(self, ctx):
"Compile this shader."
try:
return shaders.compileProgram(
shaders.compileShader(self.vertex, gl.GL_VERTEX_SHADER),
shaders.compileShader(self.fragment, gl.GL_FRAGMENT_SHADER))
except RuntimeError, e:
print e
return None
def set_uniforms(self, ctx, shader):
"Set any uniform variables the shader uses."
def _context_create(self, ctx):
return self.compile(ctx)
def _context_update(self, ctx, _old_shader):
return self.compile(ctx)
def render(self, ctx):
shader = self.context_get(ctx)
if shader is not None:
with shader:
self.set_uniforms(ctx, shader)
glitch.Node.render(self, ctx)
|