MCPcopy Create free account
hub / github.com/vispy/vispy / _parse_variables_from_code

Method _parse_variables_from_code

vispy/gloo/program.py:244–279  ·  view source on GitHub ↗

Parse uniforms, attributes and varyings from the source code.

(self, update_variables=True)

Source from the content-addressed store, hash-verified

242 return [x[:3] for x in self._code_variables.values()]
243
244 def _parse_variables_from_code(self, update_variables=True):
245 """Parse uniforms, attributes and varyings from the source code."""
246 # Get one string of code with comments removed
247 code = '\n\n'.join([sh.code for sh in self._shaders])
248 code = re.sub(r'(.*)(//.*)', r'\1', code, flags=re.M)
249
250 # Parse uniforms, attributes and varyings
251 self._code_variables = {}
252 for kind in ('uniform', 'attribute', 'varying', 'const', 'in', 'out'):
253
254 # pick regex for the correct kind of var
255 reg = REGEX_VAR[kind]
256
257 # treat *in* like attribute, *out* like varying
258 if kind == 'in':
259 kind = 'attribute'
260 elif kind == 'out':
261 kind = 'varying'
262
263 for m in re.finditer(reg, code):
264 gtype = m.group('type')
265 size = int(m.group('size')) if m.group('size') else -1
266 this_kind = kind
267 if size >= 1:
268 # uniform arrays get added both as individuals and full
269 for i in range(size):
270 name = '%s[%d]' % (m.group('name'), i)
271 self._code_variables[name] = kind, gtype, name, -1
272 this_kind = 'uniform_array'
273 name = m.group('name')
274 self._code_variables[name] = this_kind, gtype, name, size
275
276 # Now that our code variables are up-to date, we can process
277 # the variables that were set but yet unknown.
278 if update_variables:
279 self._process_pending_variables()
280
281 def bind(self, data):
282 """Bind a VertexBuffer that has structured data

Callers 1

set_shadersMethod · 0.95

Calls 1

Tested by

no test coverage detected