33
44
55def bind_target (func ):
6- """Decorator auto binding and releasing the incoming FBO"""
6+ """
7+ Decorator auto binding and releasing the incoming FBO in ``draw()``.
8+
9+ literal blocks::
10+
11+ @bind_target
12+ def draw(...):
13+ # draw stuff
14+ """
715 def func_wrapper (* args , ** kwargs ):
816 args [3 ].bind ()
917 func (* args , ** kwargs )
@@ -12,6 +20,15 @@ def func_wrapper(*args, **kwargs):
1220
1321
1422class Effect :
23+ """Effect base class.
24+
25+ The following attributes are injected by demosys before initialization:
26+
27+ * window_width (int): Window width in pixels
28+ * window_height (int): Window height in pixels
29+ * window_aspect (float): Aspect ratio of the resolution
30+ * sys_camera (demosys.scene.camera.Camera): The system camera responding to inputs
31+ """
1532 # Window properties set by controller on initialization
1633 name = ""
1734 window_width = 0
@@ -21,22 +38,61 @@ class Effect:
2138
2239 # Methods to override
2340 def draw (self , time , frametime , target ):
41+ """Draw function called by the system every frame.
42+
43+ :param time: The current time in seconds (float)
44+ :param frametime: The number of milliseconds the frame is expected to take
45+ :param target: The target FBO for the effect
46+ """
2447 raise NotImplemented
2548
2649 # Methods for getting resources
2750
2851 def get_shader (self , path ):
52+ """
53+ Get a shader or schedule the shader for loading.
54+ If the resource is not loaded yet, an empty shader object
55+ is returned that will be populated later.
56+
57+ :param path: Path to the shader in the virtual shader directory
58+ :return: Shader object
59+ """
2960 return resources .shaders .get (path , create = True )
3061
3162 def get_texture (self , path ):
63+ """
64+ Get a shader or schedule the texture for loading.
65+ If the resource is not loaded yet, an empty texture object
66+ is returned that will be populated later.
67+
68+ :param path: Path to the texture in the virtual texture directory
69+ :return: Texture object
70+ """
3271 return resources .textures .get (path , create = True )
3372
3473 def get_track (self , name ):
74+ """
75+ Get or create a rocket track. This only makes sense when using rocket timers.
76+ If the resource is not loaded yet, an empty track object
77+ is returned that will be populated later.
78+
79+ :param name: The rocket track name
80+ :return: Track object
81+ """
3582 return resources .tracks .get (name )
3683
3784 # Utility methods for matrices
3885
3986 def create_projection (self , fov = 75.0 , near = 1.0 , far = 100.0 , ratio = None ):
87+ """
88+ Create a projection matrix with the following parameters.
89+
90+ :param fov: Field of view (float)
91+ :param near: Camera near value
92+ :param far: Camrea far value
93+ :param ratio: Aspect ratio of the window
94+ :return: The projection matrix
95+ """
4096 return matrix44 .create_perspective_projection_matrix (
4197 fov ,
4298 ratio or self .window_aspect ,
@@ -64,7 +120,13 @@ def create_transformation(self, rotation=None, translation=None):
64120 return mat
65121
66122 def create_normal_matrix (self , modelview ):
67- """Convert to mat3 and return inverse transpose"""
123+ """
124+ Convert to mat3 and return inverse transpose.
125+ These are normally needed when dealing with normals in shaders.
126+
127+ :param modelview: The modelview matrix
128+ :return: Normal matrix
129+ """
68130 normal_m = Matrix33 .from_matrix44 (modelview )
69131 normal_m = normal_m .inverse
70132 normal_m = normal_m .transpose ()
0 commit comments