basilisk-engine 0.1.30__py3-none-any.whl → 0.1.31__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of basilisk-engine might be problematic. Click here for more details.

Files changed (93) hide show
  1. basilisk/__init__.py +15 -15
  2. basilisk/audio/sound.py +27 -27
  3. basilisk/bsk_assets/cube.obj +48 -48
  4. basilisk/collisions/broad/broad_aabb.py +102 -102
  5. basilisk/collisions/broad/broad_bvh.py +137 -137
  6. basilisk/collisions/collider.py +95 -95
  7. basilisk/collisions/collider_handler.py +224 -224
  8. basilisk/collisions/narrow/contact_manifold.py +95 -95
  9. basilisk/collisions/narrow/dataclasses.py +34 -34
  10. basilisk/collisions/narrow/deprecated.py +46 -46
  11. basilisk/collisions/narrow/epa.py +91 -91
  12. basilisk/collisions/narrow/gjk.py +66 -66
  13. basilisk/collisions/narrow/graham_scan.py +24 -24
  14. basilisk/collisions/narrow/helper.py +29 -29
  15. basilisk/collisions/narrow/line_intersections.py +106 -106
  16. basilisk/collisions/narrow/sutherland_hodgman.py +75 -75
  17. basilisk/config.py +3 -3
  18. basilisk/draw/draw.py +100 -100
  19. basilisk/draw/draw_handler.py +175 -175
  20. basilisk/draw/font_renderer.py +28 -28
  21. basilisk/engine.py +165 -165
  22. basilisk/generic/abstract_bvh.py +15 -15
  23. basilisk/generic/abstract_custom.py +133 -133
  24. basilisk/generic/collisions.py +70 -70
  25. basilisk/generic/input_validation.py +74 -74
  26. basilisk/generic/math.py +6 -6
  27. basilisk/generic/matrices.py +35 -35
  28. basilisk/generic/meshes.py +72 -72
  29. basilisk/generic/quat.py +142 -142
  30. basilisk/generic/quat_methods.py +7 -7
  31. basilisk/generic/raycast_result.py +26 -26
  32. basilisk/generic/vec3.py +143 -143
  33. basilisk/input/__init__.py +0 -0
  34. basilisk/input/mouse.py +62 -0
  35. basilisk/input/path.py +14 -0
  36. basilisk/input_output/IO_handler.py +91 -91
  37. basilisk/input_output/clock.py +49 -49
  38. basilisk/input_output/keys.py +43 -43
  39. basilisk/input_output/mouse.py +89 -89
  40. basilisk/input_output/path.py +14 -14
  41. basilisk/mesh/cube.py +33 -33
  42. basilisk/mesh/mesh.py +233 -233
  43. basilisk/mesh/mesh_from_data.py +150 -150
  44. basilisk/mesh/model.py +271 -271
  45. basilisk/mesh/narrow_aabb.py +89 -89
  46. basilisk/mesh/narrow_bvh.py +91 -91
  47. basilisk/mesh/narrow_primative.py +23 -23
  48. basilisk/nodes/helper.py +28 -28
  49. basilisk/nodes/node.py +699 -689
  50. basilisk/nodes/node_handler.py +97 -97
  51. basilisk/particles/particle_handler.py +64 -64
  52. basilisk/particles/particle_renderer.py +92 -92
  53. basilisk/physics/impulse.py +112 -112
  54. basilisk/physics/physics_body.py +43 -43
  55. basilisk/physics/physics_engine.py +35 -35
  56. basilisk/render/batch.py +103 -103
  57. basilisk/render/camera.py +260 -260
  58. basilisk/render/chunk.py +106 -106
  59. basilisk/render/chunk_handler.py +165 -165
  60. basilisk/render/frame.py +95 -95
  61. basilisk/render/framebuffer.py +191 -191
  62. basilisk/render/image.py +120 -120
  63. basilisk/render/image_handler.py +120 -120
  64. basilisk/render/light.py +96 -96
  65. basilisk/render/light_handler.py +58 -58
  66. basilisk/render/material.py +221 -221
  67. basilisk/render/material_handler.py +133 -133
  68. basilisk/render/post_process.py +139 -139
  69. basilisk/render/shader.py +134 -134
  70. basilisk/render/shader_handler.py +83 -83
  71. basilisk/render/sky.py +120 -120
  72. basilisk/scene.py +289 -289
  73. basilisk/shaders/batch.frag +276 -276
  74. basilisk/shaders/batch.vert +115 -115
  75. basilisk/shaders/crt.frag +31 -31
  76. basilisk/shaders/draw.frag +22 -22
  77. basilisk/shaders/draw.vert +25 -25
  78. basilisk/shaders/filter.frag +22 -22
  79. basilisk/shaders/frame.frag +12 -12
  80. basilisk/shaders/frame.vert +13 -13
  81. basilisk/shaders/geometry.frag +8 -8
  82. basilisk/shaders/geometry.vert +41 -41
  83. basilisk/shaders/normal.frag +59 -59
  84. basilisk/shaders/normal.vert +96 -96
  85. basilisk/shaders/particle.frag +71 -71
  86. basilisk/shaders/particle.vert +84 -84
  87. basilisk/shaders/sky.frag +9 -9
  88. basilisk/shaders/sky.vert +13 -13
  89. {basilisk_engine-0.1.30.dist-info → basilisk_engine-0.1.31.dist-info}/METADATA +45 -38
  90. basilisk_engine-0.1.31.dist-info/RECORD +109 -0
  91. {basilisk_engine-0.1.30.dist-info → basilisk_engine-0.1.31.dist-info}/WHEEL +1 -1
  92. basilisk_engine-0.1.30.dist-info/RECORD +0 -106
  93. {basilisk_engine-0.1.30.dist-info → basilisk_engine-0.1.31.dist-info}/top_level.txt +0 -0
basilisk/render/frame.py CHANGED
@@ -1,96 +1,96 @@
1
- import numpy as np
2
- import moderngl as mgl
3
- from .shader import Shader
4
- from .framebuffer import Framebuffer
5
-
6
- from .post_process import PostProcess
7
-
8
- class Frame:
9
- shader: Shader=None
10
- vbo: mgl.Buffer=None
11
- vao: mgl.VertexArray=None
12
- framebuffer: mgl.Framebuffer=None
13
-
14
- def __init__(self, engine, scale: float=1.0, linear_filter: bool=False) -> None:
15
- """
16
- Basilisk render destination.
17
- Can be used to render to the screen or for headless rendering
18
- """
19
-
20
- self.engine = engine
21
- self.ctx = engine.ctx
22
-
23
- # Load framebuffer
24
- self.framebuffer = Framebuffer(self.engine, scale=scale, linear_filter=linear_filter)
25
- self.ping_pong_buffer = Framebuffer(self.engine, scale=scale, linear_filter=linear_filter)
26
-
27
- # Load Shaders
28
- self.shader = Shader(self.engine, self.engine.root + '/shaders/frame.vert', self.engine.root + '/shaders/frame.frag')
29
- self.engine.shader_handler.add(self.shader)
30
-
31
- # Load VAO
32
- self.vbo = self.ctx.buffer(np.array([[-1, -1, 0, 0, 0], [1, -1, 0, 1, 0], [1, 1, 0, 1, 1], [-1, 1, 0, 0, 1], [-1, -1, 0, 0, 0], [1, 1, 0, 1, 1]], dtype='f4'))
33
- self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '3f 2f', 'in_position', 'in_uv')], skip_errors=True)
34
-
35
- # TEMP TESTING
36
- self.post_processes = []
37
-
38
-
39
- def render(self) -> None:
40
- """
41
- Renders the current frame to the screen
42
- """
43
-
44
- for process in self.post_processes:
45
- self.ping_pong_buffer = process.apply(self.framebuffer, self.ping_pong_buffer)
46
-
47
- temp = self.framebuffer
48
- self.framebuffer = self.ping_pong_buffer
49
- self.ping_pong_buffer = temp
50
-
51
- self.ctx.screen.use()
52
- self.shader.program['screenTexture'] = 0
53
- self.framebuffer.texture.use(location=0)
54
- self.vao.render()
55
-
56
-
57
- def use(self) -> None:
58
- """
59
- Uses the frame as a render target
60
- """
61
-
62
- self.framebuffer.use()
63
-
64
- def add_post_process(self, post_process: PostProcess) -> PostProcess:
65
- """
66
- Add a post process to the frames post process stack
67
- """
68
-
69
- self.post_processes.append(post_process)
70
- return post_process
71
-
72
- def save(self, destination: str=None) -> None:
73
- """
74
- Saves the frame as an image to the given file destination
75
- """
76
-
77
- self.framebuffer.save(destination)
78
-
79
- def clear(self):
80
- self.framebuffer.clear()
81
-
82
- def resize(self, size: tuple[int]=None) -> None:
83
- """
84
- Resize the frame to the given size. None for window size
85
- """
86
-
87
- self.framebuffer.resize()
88
- self.ping_pong_buffer.resize()
89
-
90
- def __del__(self) -> None:
91
- """
92
- Releases memory used by the frame
93
- """
94
-
95
- if self.vbo: self.vbo.release()
1
+ import numpy as np
2
+ import moderngl as mgl
3
+ from .shader import Shader
4
+ from .framebuffer import Framebuffer
5
+
6
+ from .post_process import PostProcess
7
+
8
+ class Frame:
9
+ shader: Shader=None
10
+ vbo: mgl.Buffer=None
11
+ vao: mgl.VertexArray=None
12
+ framebuffer: mgl.Framebuffer=None
13
+
14
+ def __init__(self, engine, scale: float=1.0, linear_filter: bool=False) -> None:
15
+ """
16
+ Basilisk render destination.
17
+ Can be used to render to the screen or for headless rendering
18
+ """
19
+
20
+ self.engine = engine
21
+ self.ctx = engine.ctx
22
+
23
+ # Load framebuffer
24
+ self.framebuffer = Framebuffer(self.engine, scale=scale, linear_filter=linear_filter)
25
+ self.ping_pong_buffer = Framebuffer(self.engine, scale=scale, linear_filter=linear_filter)
26
+
27
+ # Load Shaders
28
+ self.shader = Shader(self.engine, self.engine.root + '/shaders/frame.vert', self.engine.root + '/shaders/frame.frag')
29
+ self.engine.shader_handler.add(self.shader)
30
+
31
+ # Load VAO
32
+ self.vbo = self.ctx.buffer(np.array([[-1, -1, 0, 0, 0], [1, -1, 0, 1, 0], [1, 1, 0, 1, 1], [-1, 1, 0, 0, 1], [-1, -1, 0, 0, 0], [1, 1, 0, 1, 1]], dtype='f4'))
33
+ self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '3f 2f', 'in_position', 'in_uv')], skip_errors=True)
34
+
35
+ # TEMP TESTING
36
+ self.post_processes = []
37
+
38
+
39
+ def render(self) -> None:
40
+ """
41
+ Renders the current frame to the screen
42
+ """
43
+
44
+ for process in self.post_processes:
45
+ self.ping_pong_buffer = process.apply(self.framebuffer, self.ping_pong_buffer)
46
+
47
+ temp = self.framebuffer
48
+ self.framebuffer = self.ping_pong_buffer
49
+ self.ping_pong_buffer = temp
50
+
51
+ self.ctx.screen.use()
52
+ self.shader.program['screenTexture'] = 0
53
+ self.framebuffer.texture.use(location=0)
54
+ self.vao.render()
55
+
56
+
57
+ def use(self) -> None:
58
+ """
59
+ Uses the frame as a render target
60
+ """
61
+
62
+ self.framebuffer.use()
63
+
64
+ def add_post_process(self, post_process: PostProcess) -> PostProcess:
65
+ """
66
+ Add a post process to the frames post process stack
67
+ """
68
+
69
+ self.post_processes.append(post_process)
70
+ return post_process
71
+
72
+ def save(self, destination: str=None) -> None:
73
+ """
74
+ Saves the frame as an image to the given file destination
75
+ """
76
+
77
+ self.framebuffer.save(destination)
78
+
79
+ def clear(self):
80
+ self.framebuffer.clear()
81
+
82
+ def resize(self, size: tuple[int]=None) -> None:
83
+ """
84
+ Resize the frame to the given size. None for window size
85
+ """
86
+
87
+ self.framebuffer.resize()
88
+ self.ping_pong_buffer.resize()
89
+
90
+ def __del__(self) -> None:
91
+ """
92
+ Releases memory used by the frame
93
+ """
94
+
95
+ if self.vbo: self.vbo.release()
96
96
  if self.vao: self.vao.release()
@@ -1,192 +1,192 @@
1
- import numpy as np
2
- import moderngl as mgl
3
- from PIL import Image
4
- from ..render.shader import Shader
5
- from ..generic.input_validation import validate_int
6
-
7
-
8
- class Framebuffer:
9
- engine: ...
10
- """Reference to the parent engine"""
11
- size: tuple[int] | None=None
12
- """The dimensions of the framebuffer (x, y). Defaults to window size if None"""
13
- scale: float=1.0
14
- """Scaling factor applied to the size. Best for use with default size"""
15
- texture_filter: tuple[int]=(mgl.NEAREST, mgl.NEAREST)
16
- """The filter applied to the texture when rendering"""
17
- fbo: mgl.Framebuffer=None
18
- """The core framebuffer the object provides abstraction for."""
19
- texture: mgl.Texture=None
20
- """The color texture of the framebuffer"""
21
- depth: mgl.Texture=None
22
- """The depth texture of the framebuffer"""
23
- _color_attachments = None
24
- """"""
25
- _depth_attachment = None
26
- """"""
27
-
28
- def __init__(self, engine: ..., size: tuple[int]=None, n_color_attachments: int=1, scale: float=1.0, linear_filter: bool=True) -> None:
29
- """
30
- Abstraction of the MGL framebuffer.
31
- Has the given number of color attachements (4-component) and 1 depth attachment.
32
- All textures are of uniform size.
33
- """
34
-
35
- self.engine = engine
36
- self.ctx = engine.ctx
37
- self._size = size
38
- self.scale = scale
39
- self.texture_filter = (mgl.LINEAR, mgl.LINEAR) if linear_filter else (mgl.NEAREST, mgl.NEAREST)
40
- self.n_attachments = n_color_attachments
41
-
42
- self.load_pipeline()
43
- self.generate_fbo()
44
-
45
- self.engine.fbos.append(self)
46
-
47
- def generate_fbo(self):
48
- """
49
- Generates fresh depth texture and color textures and creates an FBO
50
- """
51
-
52
- # Release existing memory
53
- self.__del__()
54
-
55
- # Create textures
56
- self._color_attachments = [self.ctx.texture(self.size, components=4) for i in range(self.n_attachments)]
57
- for tex in self._color_attachments: tex.filter = self.texture_filter
58
- self._depth_attachment = self.ctx.depth_texture(self.size)
59
-
60
- # Create the internal fbo
61
- self.fbo = self.ctx.framebuffer(self._color_attachments, self._depth_attachment)
62
-
63
- # Set the show attachment to default
64
- self._show = -1
65
- self.show = 0
66
-
67
- def resize(self, new_size: tuple[int]=None) -> None:
68
- """
69
- Update set size framebuffers with the given size.
70
- """
71
-
72
- # Check that we are not updating the size to the existing size and
73
- if self._size and self._size == new_size: return
74
-
75
- # If we have a set size, update with the given size
76
- if self._size and new_size: self._size = new_size
77
-
78
- # Update the textures and fbo
79
- self.generate_fbo()
80
-
81
- def load_pipeline(self) -> None:
82
- """
83
- Loads the shader, vbo, and vao used to display the fbo
84
- """
85
-
86
- # Load Shaders
87
- self.shader = Shader(self.engine, self.engine.root + '/shaders/frame.vert', self.engine.root + '/shaders/frame.frag')
88
- self.engine.shader_handler.add(self.shader)
89
-
90
- # Load VAO
91
- self.vbo = self.ctx.buffer(np.array([[-1, -1, 0, 0, 0], [1, -1, 0, 1, 0], [1, 1, 0, 1, 1], [-1, 1, 0, 0, 1], [-1, -1, 0, 0, 0], [1, 1, 0, 1, 1]], dtype='f4'))
92
- self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '3f 2f', 'in_position', 'in_uv')], skip_errors=True)
93
-
94
- def render(self, render_target=None, show: int=None) -> None:
95
- """
96
- Render the fbo to the screen
97
- If the fbo has multiple attachments, show will specifiy which is shown
98
- Depth is considered the last show element
99
- """
100
-
101
- if not isinstance(show, type(None)): self.show = show
102
-
103
- target = render_target if render_target else self.engine.frame
104
- target.use()
105
-
106
- self.vao.render()
107
-
108
- def use(self) -> None:
109
- """
110
- Select this framebuffer for use
111
- """
112
-
113
- self.fbo.use()
114
-
115
- def clear(self) -> None:
116
- """
117
- Clear all data currently in the textures (set to black)
118
- """
119
-
120
- self.fbo.clear()
121
-
122
- def save(self, destination: str=None) -> None:
123
- """
124
- Saves the frame as an image to the given file destination
125
- """
126
-
127
- path = destination if destination else 'screenshot'
128
-
129
- data = self.fbo.read(components=3, alignment=1)
130
- img = Image.frombytes('RGB', self.size, data).transpose(Image.FLIP_TOP_BOTTOM)
131
- img.save(f'{path}.png')
132
-
133
-
134
- @property
135
- def size(self) -> tuple[int]:
136
- """Size of the textures in the fbo in pixels (x: int, y: int)"""
137
- size = self._size if self._size else self.engine.win_size
138
- size = tuple(map((lambda x: int(x * self.scale)), size))
139
- return size
140
- @property
141
- def texture(self) -> mgl.Texture:
142
- """First color attachment in the fbo"""
143
- return self._color_attachments[0]
144
- @property
145
- def color_attachments(self) -> list[mgl.Texture]:
146
- """List of all color attachments in the fbo"""
147
- return self._color_attachments
148
- @property
149
- def depth(self) -> mgl.Texture:
150
- """Depth attachment of the fbo"""
151
- return self._depth_attachment
152
- @property
153
- def data(self) -> bytes:
154
- """Reads the data from the fbo"""
155
- return self.fbo.read()
156
- @property
157
- def show(self) -> int:
158
- return self._show
159
-
160
- @size.setter
161
- def size(self, value: tuple[int]=None) -> tuple[int]:
162
- self.resize(value)
163
- return self.size
164
-
165
- @show.setter
166
- def show(self, value: int) -> None:
167
- value = validate_int("Framebuffer", "show", value)
168
- if value == self._show: return
169
-
170
- # Verify the range
171
- if value < 0 or value > len(self.color_attachments): raise ValueError(f'Framebuffer.show: invalid color attachement to show, {value} is out of range')
172
- elif value == len(self.color_attachments): src = self.depth
173
- else: src = self.color_attachments[value]
174
-
175
- # Update value
176
- self._show = value
177
-
178
- # Bind the correct texture
179
- self.shader.program['screenTexture'] = value+1
180
- src.use(location=value+1)
181
-
182
- def __repr__(self) -> str:
183
- return f'<bsk.Framebuffer | size: {self.size}>'
184
-
185
- def __del__(self) -> None:
186
- """
187
- Releases all memory used by the fbo
188
- """
189
-
190
- if self._color_attachments: [tex.release() for tex in self._color_attachments]
191
- if self._depth_attachment: self._depth_attachment.release()
1
+ import numpy as np
2
+ import moderngl as mgl
3
+ from PIL import Image
4
+ from ..render.shader import Shader
5
+ from ..generic.input_validation import validate_int
6
+
7
+
8
+ class Framebuffer:
9
+ engine: ...
10
+ """Reference to the parent engine"""
11
+ size: tuple[int] | None=None
12
+ """The dimensions of the framebuffer (x, y). Defaults to window size if None"""
13
+ scale: float=1.0
14
+ """Scaling factor applied to the size. Best for use with default size"""
15
+ texture_filter: tuple[int]=(mgl.NEAREST, mgl.NEAREST)
16
+ """The filter applied to the texture when rendering"""
17
+ fbo: mgl.Framebuffer=None
18
+ """The core framebuffer the object provides abstraction for."""
19
+ texture: mgl.Texture=None
20
+ """The color texture of the framebuffer"""
21
+ depth: mgl.Texture=None
22
+ """The depth texture of the framebuffer"""
23
+ _color_attachments = None
24
+ """"""
25
+ _depth_attachment = None
26
+ """"""
27
+
28
+ def __init__(self, engine: ..., size: tuple[int]=None, n_color_attachments: int=1, scale: float=1.0, linear_filter: bool=True) -> None:
29
+ """
30
+ Abstraction of the MGL framebuffer.
31
+ Has the given number of color attachements (4-component) and 1 depth attachment.
32
+ All textures are of uniform size.
33
+ """
34
+
35
+ self.engine = engine
36
+ self.ctx = engine.ctx
37
+ self._size = size
38
+ self.scale = scale
39
+ self.texture_filter = (mgl.LINEAR, mgl.LINEAR) if linear_filter else (mgl.NEAREST, mgl.NEAREST)
40
+ self.n_attachments = n_color_attachments
41
+
42
+ self.load_pipeline()
43
+ self.generate_fbo()
44
+
45
+ self.engine.fbos.append(self)
46
+
47
+ def generate_fbo(self):
48
+ """
49
+ Generates fresh depth texture and color textures and creates an FBO
50
+ """
51
+
52
+ # Release existing memory
53
+ self.__del__()
54
+
55
+ # Create textures
56
+ self._color_attachments = [self.ctx.texture(self.size, components=4) for i in range(self.n_attachments)]
57
+ for tex in self._color_attachments: tex.filter = self.texture_filter
58
+ self._depth_attachment = self.ctx.depth_texture(self.size)
59
+
60
+ # Create the internal fbo
61
+ self.fbo = self.ctx.framebuffer(self._color_attachments, self._depth_attachment)
62
+
63
+ # Set the show attachment to default
64
+ self._show = -1
65
+ self.show = 0
66
+
67
+ def resize(self, new_size: tuple[int]=None) -> None:
68
+ """
69
+ Update set size framebuffers with the given size.
70
+ """
71
+
72
+ # Check that we are not updating the size to the existing size and
73
+ if self._size and self._size == new_size: return
74
+
75
+ # If we have a set size, update with the given size
76
+ if self._size and new_size: self._size = new_size
77
+
78
+ # Update the textures and fbo
79
+ self.generate_fbo()
80
+
81
+ def load_pipeline(self) -> None:
82
+ """
83
+ Loads the shader, vbo, and vao used to display the fbo
84
+ """
85
+
86
+ # Load Shaders
87
+ self.shader = Shader(self.engine, self.engine.root + '/shaders/frame.vert', self.engine.root + '/shaders/frame.frag')
88
+ self.engine.shader_handler.add(self.shader)
89
+
90
+ # Load VAO
91
+ self.vbo = self.ctx.buffer(np.array([[-1, -1, 0, 0, 0], [1, -1, 0, 1, 0], [1, 1, 0, 1, 1], [-1, 1, 0, 0, 1], [-1, -1, 0, 0, 0], [1, 1, 0, 1, 1]], dtype='f4'))
92
+ self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '3f 2f', 'in_position', 'in_uv')], skip_errors=True)
93
+
94
+ def render(self, render_target=None, show: int=None) -> None:
95
+ """
96
+ Render the fbo to the screen
97
+ If the fbo has multiple attachments, show will specifiy which is shown
98
+ Depth is considered the last show element
99
+ """
100
+
101
+ if not isinstance(show, type(None)): self.show = show
102
+
103
+ target = render_target if render_target else self.engine.frame
104
+ target.use()
105
+
106
+ self.vao.render()
107
+
108
+ def use(self) -> None:
109
+ """
110
+ Select this framebuffer for use
111
+ """
112
+
113
+ self.fbo.use()
114
+
115
+ def clear(self) -> None:
116
+ """
117
+ Clear all data currently in the textures (set to black)
118
+ """
119
+
120
+ self.fbo.clear()
121
+
122
+ def save(self, destination: str=None) -> None:
123
+ """
124
+ Saves the frame as an image to the given file destination
125
+ """
126
+
127
+ path = destination if destination else 'screenshot'
128
+
129
+ data = self.fbo.read(components=3, alignment=1)
130
+ img = Image.frombytes('RGB', self.size, data).transpose(Image.FLIP_TOP_BOTTOM)
131
+ img.save(f'{path}.png')
132
+
133
+
134
+ @property
135
+ def size(self) -> tuple[int]:
136
+ """Size of the textures in the fbo in pixels (x: int, y: int)"""
137
+ size = self._size if self._size else self.engine.win_size
138
+ size = tuple(map((lambda x: int(x * self.scale)), size))
139
+ return size
140
+ @property
141
+ def texture(self) -> mgl.Texture:
142
+ """First color attachment in the fbo"""
143
+ return self._color_attachments[0]
144
+ @property
145
+ def color_attachments(self) -> list[mgl.Texture]:
146
+ """List of all color attachments in the fbo"""
147
+ return self._color_attachments
148
+ @property
149
+ def depth(self) -> mgl.Texture:
150
+ """Depth attachment of the fbo"""
151
+ return self._depth_attachment
152
+ @property
153
+ def data(self) -> bytes:
154
+ """Reads the data from the fbo"""
155
+ return self.fbo.read()
156
+ @property
157
+ def show(self) -> int:
158
+ return self._show
159
+
160
+ @size.setter
161
+ def size(self, value: tuple[int]=None) -> tuple[int]:
162
+ self.resize(value)
163
+ return self.size
164
+
165
+ @show.setter
166
+ def show(self, value: int) -> None:
167
+ value = validate_int("Framebuffer", "show", value)
168
+ if value == self._show: return
169
+
170
+ # Verify the range
171
+ if value < 0 or value > len(self.color_attachments): raise ValueError(f'Framebuffer.show: invalid color attachement to show, {value} is out of range')
172
+ elif value == len(self.color_attachments): src = self.depth
173
+ else: src = self.color_attachments[value]
174
+
175
+ # Update value
176
+ self._show = value
177
+
178
+ # Bind the correct texture
179
+ self.shader.program['screenTexture'] = value+1
180
+ src.use(location=value+1)
181
+
182
+ def __repr__(self) -> str:
183
+ return f'<bsk.Framebuffer | size: {self.size}>'
184
+
185
+ def __del__(self) -> None:
186
+ """
187
+ Releases all memory used by the fbo
188
+ """
189
+
190
+ if self._color_attachments: [tex.release() for tex in self._color_attachments]
191
+ if self._depth_attachment: self._depth_attachment.release()
192
192
  if self.fbo: self.fbo.release()