comparison pytouhou/ui/opengl/shader.pyx @ 606:3c2f96f1d715

Fix compilation under Cython 0.22, by making the pyx and the pxd declarations’ except clause similar.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 26 Nov 2014 13:36:38 +0100
parents aca9551ee8b4
children a6af3ff86612
comparison
equal deleted inserted replaced
605:d6ead6f0ba80 606:3c2f96f1d715
56 self.link() 56 self.link()
57 57
58 if use_debug_group: 58 if use_debug_group:
59 glPopDebugGroup() 59 glPopDebugGroup()
60 60
61 cdef void create_shader(self, const GLchar *string, GLenum_shader shader_type): 61 cdef void create_shader(self, const GLchar *string, GLenum_shader shader_type) except *:
62 cdef GLint temp 62 cdef GLint temp
63 cdef const GLchar *strings[2] 63 cdef const GLchar *strings[2]
64 strings[:] = [shader_header, string] 64 strings[:] = [shader_header, string]
65 65
66 # create the shader handle 66 # create the shader handle
89 raise GLSLException(buf) 89 raise GLSLException(buf)
90 else: 90 else:
91 # all is well, so attach the shader to the program 91 # all is well, so attach the shader to the program
92 glAttachShader(self.handle, shader) 92 glAttachShader(self.handle, shader)
93 93
94 cdef void link(self): 94 cdef void link(self) except *:
95 cdef GLint temp 95 cdef GLint temp
96 96
97 # link the program 97 # link the program
98 glLinkProgram(self.handle) 98 glLinkProgram(self.handle)
99 99
114 raise GLSLException(buf) 114 raise GLSLException(buf)
115 else: 115 else:
116 # all is well, so we are linked 116 # all is well, so we are linked
117 self.linked = True 117 self.linked = True
118 118
119 cdef GLint get_uniform_location(self, name): 119 cdef GLint get_uniform_location(self, name) except -1:
120 if isinstance(name, str): 120 if isinstance(name, str):
121 name = name.encode() 121 name = name.encode()
122 if name not in self.location_cache: 122 if name not in self.location_cache:
123 loc = glGetUniformLocation(self.handle, name) 123 loc = glGetUniformLocation(self.handle, name)
124 if loc == -1: 124 if loc == -1:
130 # bind the program 130 # bind the program
131 glUseProgram(self.handle) 131 glUseProgram(self.handle)
132 132
133 # upload a floating point uniform 133 # upload a floating point uniform
134 # this program must be currently bound 134 # this program must be currently bound
135 cdef void uniform_1(self, name, GLfloat val): 135 cdef void uniform_1(self, name, GLfloat val) except *:
136 glUniform1fv(self.get_uniform_location(name), 1, &val) 136 glUniform1fv(self.get_uniform_location(name), 1, &val)
137 137
138 # upload a vec4 uniform 138 # upload a vec4 uniform
139 cdef void uniform_4(self, name, GLfloat a, GLfloat b, GLfloat c, GLfloat d): 139 cdef void uniform_4(self, name, GLfloat a, GLfloat b, GLfloat c, GLfloat d) except *:
140 cdef GLfloat vals[4] 140 cdef GLfloat vals[4]
141 vals[0] = a 141 vals[0] = a
142 vals[1] = b 142 vals[1] = b
143 vals[2] = c 143 vals[2] = c
144 vals[3] = d 144 vals[3] = d
145 glUniform4fv(self.get_uniform_location(name), 1, vals) 145 glUniform4fv(self.get_uniform_location(name), 1, vals)
146 146
147 # upload a uniform matrix 147 # upload a uniform matrix
148 # works with matrices stored as lists, 148 # works with matrices stored as lists,
149 # as well as euclid matrices 149 # as well as euclid matrices
150 cdef void uniform_matrix(self, name, Matrix *mat): 150 cdef void uniform_matrix(self, name, Matrix *mat) except *:
151 # obtain the uniform location 151 # obtain the uniform location
152 loc = self.get_uniform_location(name) 152 loc = self.get_uniform_location(name)
153 # uplaod the 4x4 floating point matrix 153 # uplaod the 4x4 floating point matrix
154 glUniformMatrix4fv(loc, 1, False, <GLfloat*>mat) 154 glUniformMatrix4fv(loc, 1, False, <GLfloat*>mat)