def shader_string(body, glsl_version='450 core'):
"""
Call this method from a function that defines a literal shader string as the "body" argument.
Dresses up a shader string in three ways:
1) Insert #version at the top
2) Insert #line number declaration
3) un-indents
The line number information can help debug glsl compile errors.
The version string needs to be the very first characters in the shader,
which can be distracting, requiring backslashes or other tricks.
The unindenting allows you to type the shader code at a pleasing indent level
in your python method, while still creating an unindented GLSL string at the end.
"""
line_count = len(body.split('\n'))
line_number = inspect.currentframe().f_back.f_lineno + 1 - line_count
return """\
#version %s
%s
""" % (glsl_version, shader_substring(body, stack_frame=2))
评论列表
文章目录