|
9 | 9 |
|
10 | 10 |
|
11 | 11 | class BaseProject:
|
12 |
| - """The Project""" |
13 |
| - effect_packages = [] |
14 |
| - resources = [] |
15 |
| - override_resources = {} |
| 12 | + """ |
| 13 | + The base project class we extend when creating a project configuration |
| 14 | +
|
| 15 | + The minimal implementation:: |
| 16 | +
|
| 17 | + from demosys.project.base import BaseProject |
| 18 | + from demosys.resources.meta import ProgramDescription, TextureDescription |
| 19 | +
|
| 20 | + class Project(BaseProject): |
| 21 | + # The effect packages to import using full python path |
| 22 | + effect_packages = [ |
| 23 | + 'myproject.efect_package1', |
| 24 | + 'myproject.efect_package2', |
| 25 | + 'myproject.efect_package2', |
| 26 | + ] |
| 27 | + # Resource description for global project resources (not loaded by effect packages) |
| 28 | + resources = [ |
| 29 | + ProgramDescription(label='cube_textured', path="cube_textured.glsl'), |
| 30 | + TextureDescription(label='wood', path="wood.png', mipmap=True), |
| 31 | + ] |
| 32 | +
|
| 33 | + def create_resources(self): |
| 34 | + # Override the method adding additional resources |
| 35 | +
|
| 36 | + # Create some shared fbo |
| 37 | + size = (256, 256) |
| 38 | + self.shared_framebuffer = self.ctx.framebuffer( |
| 39 | + color_attachments=self.ctx.texture(size, 4), |
| 40 | + depth_attachement=self.ctx.depth_texture(size) |
| 41 | + ) |
| 42 | +
|
| 43 | + return self.resources |
| 44 | +
|
| 45 | + def create_effect_instances(self): |
| 46 | + # Create and register instances of an effect class we loaded from the effect packages |
| 47 | + self.create_effect('cube1', 'CubeEffect') |
| 48 | +
|
| 49 | + # Using full path to class |
| 50 | + self.create_effect('cube2', 'myproject.efect_package1.CubeEffect') |
| 51 | +
|
| 52 | + # Passing variables to initializer |
| 53 | + self.create_effect('cube3', 'CubeEffect', texture=self.get_texture('wood')) |
| 54 | +
|
| 55 | + # Assign resources manually |
| 56 | + cube = self.create_effect('cube1', 'CubeEffect') |
| 57 | + cube.program = self.get_program('cube_textured') |
| 58 | + cube.texture = self.get_texture('wood') |
| 59 | + cube.fbo = self.shared_framebuffer |
| 60 | + |
| 61 | + These effects instances can then be obtained by the configured timeline class deciding |
| 62 | + when they should be rendered. |
| 63 | + """ |
| 64 | + effect_packages = [] #: The effect packages to load |
| 65 | + resources = [] #: Global project resource descriptions |
16 | 66 |
|
17 | 67 | def __init__(self):
|
18 | 68 | self._effects = {}
|
|
0 commit comments