ncca-ngl 0.3.5__py3-none-any.whl → 0.5.0__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.
Files changed (56) hide show
  1. ncca/ngl/PrimData/pack_arrays.py +2 -3
  2. ncca/ngl/__init__.py +3 -4
  3. ncca/ngl/base_mesh.py +28 -20
  4. ncca/ngl/image.py +1 -3
  5. ncca/ngl/mat2.py +79 -53
  6. ncca/ngl/mat3.py +104 -185
  7. ncca/ngl/mat4.py +144 -309
  8. ncca/ngl/prim_data.py +42 -36
  9. ncca/ngl/primitives.py +2 -2
  10. ncca/ngl/pyside_event_handling_mixin.py +0 -108
  11. ncca/ngl/quaternion.py +69 -36
  12. ncca/ngl/shader.py +0 -116
  13. ncca/ngl/shader_program.py +94 -117
  14. ncca/ngl/texture.py +5 -2
  15. ncca/ngl/util.py +0 -2
  16. ncca/ngl/vec2.py +59 -302
  17. ncca/ngl/vec2_array.py +79 -28
  18. ncca/ngl/vec3.py +60 -350
  19. ncca/ngl/vec3_array.py +76 -23
  20. ncca/ngl/vec4.py +90 -200
  21. ncca/ngl/vec4_array.py +78 -27
  22. ncca/ngl/vector_base.py +542 -0
  23. ncca/ngl/webgpu/__init__.py +20 -0
  24. ncca/ngl/webgpu/__main__.py +640 -0
  25. ncca/ngl/webgpu/__main__.py.backup +640 -0
  26. ncca/ngl/webgpu/base_webgpu_pipeline.py +354 -0
  27. ncca/ngl/webgpu/custom_shader_pipeline.py +288 -0
  28. ncca/ngl/webgpu/instanced_geometry_pipeline.py +594 -0
  29. ncca/ngl/webgpu/line_pipeline.py +405 -0
  30. ncca/ngl/webgpu/pipeline_factory.py +190 -0
  31. ncca/ngl/webgpu/pipeline_shaders.py +497 -0
  32. ncca/ngl/webgpu/point_list_pipeline.py +349 -0
  33. ncca/ngl/webgpu/point_pipeline.py +336 -0
  34. ncca/ngl/webgpu/triangle_pipeline.py +419 -0
  35. ncca/ngl/webgpu/webgpu_constants.py +31 -0
  36. ncca/ngl/webgpu/webgpu_widget.py +322 -0
  37. ncca/ngl/webgpu/wip/REFACTORING_SUMMARY.md +82 -0
  38. ncca/ngl/webgpu/wip/UNIFIED_SYSTEM.md +314 -0
  39. ncca/ngl/webgpu/wip/buffer_manager.py +396 -0
  40. ncca/ngl/webgpu/wip/pipeline_config.py +463 -0
  41. ncca/ngl/webgpu/wip/shader_constants.py +328 -0
  42. ncca/ngl/webgpu/wip/shader_templates.py +563 -0
  43. ncca/ngl/webgpu/wip/unified_examples.py +390 -0
  44. ncca/ngl/webgpu/wip/unified_factory.py +449 -0
  45. ncca/ngl/webgpu/wip/unified_pipeline.py +469 -0
  46. ncca/ngl/widgets/__init__.py +18 -2
  47. ncca/ngl/widgets/__main__.py +2 -1
  48. ncca/ngl/widgets/lookatwidget.py +2 -1
  49. ncca/ngl/widgets/mat4widget.py +2 -2
  50. ncca/ngl/widgets/vec2widget.py +1 -1
  51. ncca/ngl/widgets/vec3widget.py +1 -0
  52. {ncca_ngl-0.3.5.dist-info → ncca_ngl-0.5.0.dist-info}/METADATA +3 -2
  53. ncca_ngl-0.5.0.dist-info/RECORD +105 -0
  54. ncca/ngl/widgets/transformation_widget.py +0 -299
  55. ncca_ngl-0.3.5.dist-info/RECORD +0 -82
  56. {ncca_ngl-0.3.5.dist-info → ncca_ngl-0.5.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,463 @@
1
+ """
2
+ Configuration objects for WebGPU pipeline definitions.
3
+ Provides dataclasses and builders for flexible pipeline configuration.
4
+ """
5
+
6
+ from dataclasses import dataclass, field
7
+ from enum import Enum
8
+ from typing import Any, Dict, List, Optional, Tuple, Union
9
+
10
+ import numpy as np
11
+ import wgpu
12
+
13
+ from .shader_templates import (
14
+ ColorMode,
15
+ PrimitiveType,
16
+ RenderMode,
17
+ ShaderConfig,
18
+ UniformField,
19
+ VertexAttribute,
20
+ create_shader_config,
21
+ )
22
+
23
+
24
+ class TopologyType(Enum):
25
+ """WebGPU primitive topology types."""
26
+
27
+ POINT_LIST = "point_list"
28
+ LINE_LIST = "line_list"
29
+ LINE_STRIP = "line_strip"
30
+ TRIANGLE_LIST = "triangle_list"
31
+ TRIANGLE_STRIP = "triangle_strip"
32
+
33
+
34
+ @dataclass
35
+ class BufferLayout:
36
+ """Configuration for a vertex buffer layout."""
37
+
38
+ stride: int
39
+ step_mode: str = "vertex"
40
+ attributes: List[Dict[str, Any]] = field(default_factory=list)
41
+
42
+
43
+ @dataclass
44
+ class PipelineConfig:
45
+ """Complete configuration for a WebGPU pipeline."""
46
+
47
+ # Core configuration
48
+ primitive_type: PrimitiveType
49
+ color_mode: ColorMode
50
+ topology: wgpu.PrimitiveTopology
51
+
52
+ # Rendering options
53
+ render_mode: RenderMode = RenderMode.STANDARD
54
+ texture_format: wgpu.TextureFormat = wgpu.TextureFormat.rgba8unorm
55
+ depth_format: wgpu.TextureFormat = wgpu.TextureFormat.depth24plus
56
+ msaa_sample_count: int = 4
57
+
58
+ # Vertex data configuration
59
+ data_type: str = "Vec3"
60
+ stride: int = 0
61
+
62
+ # Custom shader support
63
+ custom_vertex_shader: Optional[str] = None
64
+ custom_fragment_shader: Optional[str] = None
65
+
66
+ # Extended configuration
67
+ custom_uniforms: Optional[List[UniformField]] = None
68
+ custom_attributes: Optional[List[VertexAttribute]] = None
69
+ buffer_layouts: Optional[List[BufferLayout]] = None
70
+
71
+ # Pipeline options
72
+ cull_mode: wgpu.CullMode = wgpu.CullMode.none
73
+ front_face: wgpu.FrontFace = wgpu.FrontFace.ccw
74
+
75
+ def to_shader_config(self) -> ShaderConfig:
76
+ """Convert to shader configuration."""
77
+ return create_shader_config(
78
+ primitive_type=self.primitive_type,
79
+ color_mode=self.color_mode,
80
+ render_mode=self.render_mode,
81
+ custom_vertex_shader=self.custom_vertex_shader,
82
+ custom_fragment_shader=self.custom_fragment_shader,
83
+ custom_uniforms=self.custom_uniforms,
84
+ custom_attributes=self.custom_attributes,
85
+ )
86
+
87
+
88
+ @dataclass
89
+ class BufferConfig:
90
+ """Configuration for buffer management."""
91
+
92
+ name: str
93
+ data: Optional[Union[np.ndarray, wgpu.GPUBuffer]] = None
94
+ usage: Optional[wgpu.BufferUsage] = None
95
+ buffer_label: Optional[str] = None
96
+ default_value: Optional[np.ndarray] = None
97
+ padding_size: Optional[int] = None
98
+
99
+
100
+ @dataclass
101
+ class UniformConfig:
102
+ """Configuration for uniform buffer management."""
103
+
104
+ name: str
105
+ data_type: str
106
+ value: Optional[Union[float, np.ndarray]] = None
107
+ array_size: Optional[int] = None
108
+
109
+
110
+ class PipelineConfigBuilder:
111
+ """Builder for creating pipeline configurations."""
112
+
113
+ def __init__(self):
114
+ """Initialize builder with default values."""
115
+ self._config = PipelineConfig(
116
+ primitive_type=PrimitiveType.TRIANGLE,
117
+ color_mode=ColorMode.MULTI,
118
+ topology=wgpu.PrimitiveTopology.triangle_list,
119
+ )
120
+ self._buffer_layouts: List[BufferLayout] = []
121
+ self._uniforms: List[UniformConfig] = []
122
+
123
+ def primitive(self, primitive_type: PrimitiveType) -> "PipelineConfigBuilder":
124
+ """Set primitive type."""
125
+ self._config.primitive_type = primitive_type
126
+ return self
127
+
128
+ def color_mode(self, color_mode: ColorMode) -> "PipelineConfigBuilder":
129
+ """Set color mode."""
130
+ self._config.color_mode = color_mode
131
+ return self
132
+
133
+ def topology(self, topology: wgpu.PrimitiveTopology) -> "PipelineConfigBuilder":
134
+ """Set primitive topology."""
135
+ self._config.topology = topology
136
+ return self
137
+
138
+ def render_mode(self, render_mode: RenderMode) -> "PipelineConfigBuilder":
139
+ """Set render mode."""
140
+ self._config.render_mode = render_mode
141
+ return self
142
+
143
+ def texture_format(self, format: wgpu.TextureFormat) -> "PipelineConfigBuilder":
144
+ """Set texture format."""
145
+ self._config.texture_format = format
146
+ return self
147
+
148
+ def depth_format(self, format: wgpu.TextureFormat) -> "PipelineConfigBuilder":
149
+ """Set depth format."""
150
+ self._config.depth_format = format
151
+ return self
152
+
153
+ def msaa(self, samples: int) -> "PipelineConfigBuilder":
154
+ """Set MSAA sample count."""
155
+ self._config.msaa_sample_count = samples
156
+ return self
157
+
158
+ def data_type(self, data_type: str) -> "PipelineConfigBuilder":
159
+ """Set vertex data type."""
160
+ self._config.data_type = data_type
161
+ return self
162
+
163
+ def stride(self, stride: int) -> "PipelineConfigBuilder":
164
+ """Set vertex buffer stride."""
165
+ self._config.stride = stride
166
+ return self
167
+
168
+ def custom_shaders(
169
+ self,
170
+ vertex_shader: Optional[str] = None,
171
+ fragment_shader: Optional[str] = None,
172
+ ) -> "PipelineConfigBuilder":
173
+ """Set custom shaders."""
174
+ self._config.custom_vertex_shader = vertex_shader
175
+ self._config.custom_fragment_shader = fragment_shader
176
+ return self
177
+
178
+ def custom_uniforms(self, uniforms: List[UniformField]) -> "PipelineConfigBuilder":
179
+ """Set custom uniforms."""
180
+ self._config.custom_uniforms = uniforms
181
+ return self
182
+
183
+ def custom_attributes(
184
+ self, attributes: List[VertexAttribute]
185
+ ) -> "PipelineConfigBuilder":
186
+ """Set custom vertex attributes."""
187
+ self._config.custom_attributes = attributes
188
+ return self
189
+
190
+ def buffer_layout(self, layout: BufferLayout) -> "PipelineConfigBuilder":
191
+ """Add a buffer layout."""
192
+ self._buffer_layouts.append(layout)
193
+ return self
194
+
195
+ def cull_mode(self, mode: wgpu.CullMode) -> "PipelineConfigBuilder":
196
+ """Set cull mode."""
197
+ self._config.cull_mode = mode
198
+ return self
199
+
200
+ def front_face(self, face: wgpu.FrontFace) -> "PipelineConfigBuilder":
201
+ """Set front face winding."""
202
+ self._config.front_face = face
203
+ return self
204
+
205
+ def build(self) -> PipelineConfig:
206
+ """Build the pipeline configuration."""
207
+ if self._buffer_layouts:
208
+ self._config.buffer_layouts = self._buffer_layouts
209
+ return self._config
210
+
211
+
212
+ class VertexLayoutBuilder:
213
+ """Builder for creating vertex buffer layouts."""
214
+
215
+ def __init__(self, stride: int = 0, step_mode: str = "vertex"):
216
+ """Initialize layout builder."""
217
+ self.stride = stride
218
+ self.step_mode = step_mode
219
+ self.attributes: List[Dict[str, Any]] = []
220
+
221
+ def with_stride(self, stride: int) -> "VertexLayoutBuilder":
222
+ """Set stride for the layout."""
223
+ self.stride = stride
224
+ return self
225
+
226
+ def with_step_mode(self, step_mode: str) -> "VertexLayoutBuilder":
227
+ """Set step mode for the layout."""
228
+ self.step_mode = step_mode
229
+ return self
230
+
231
+ def add_attribute(
232
+ self,
233
+ format: str,
234
+ offset: int,
235
+ shader_location: int,
236
+ ) -> "VertexLayoutBuilder":
237
+ """Add an attribute to the layout."""
238
+ self.attributes.append(
239
+ {
240
+ "format": format,
241
+ "offset": offset,
242
+ "shader_location": shader_location,
243
+ }
244
+ )
245
+ return self
246
+
247
+ def with_position(
248
+ self,
249
+ data_type: str = "Vec3",
250
+ offset: int = 0,
251
+ location: int = 0,
252
+ ) -> "VertexLayoutBuilder":
253
+ """Add position attribute."""
254
+ from .webgpu_constants import NGLToWebGPU
255
+
256
+ self.attributes.append(
257
+ {
258
+ "format": NGLToWebGPU.vertex_format(data_type),
259
+ "offset": offset,
260
+ "shader_location": location,
261
+ }
262
+ )
263
+ return self
264
+
265
+ def with_color(
266
+ self,
267
+ data_type: str = "Vec3",
268
+ offset: int = 0,
269
+ location: int = 1,
270
+ ) -> "VertexLayoutBuilder":
271
+ """Add color attribute."""
272
+ from .webgpu_constants import NGLToWebGPU
273
+
274
+ self.attributes.append(
275
+ {
276
+ "format": NGLToWebGPU.vertex_format(data_type),
277
+ "offset": offset,
278
+ "shader_location": location,
279
+ }
280
+ )
281
+ return self
282
+
283
+ def with_normal(
284
+ self,
285
+ data_type: str = "Vec3",
286
+ offset: int = 0,
287
+ location: int = 2,
288
+ ) -> "VertexLayoutBuilder":
289
+ """Add normal attribute."""
290
+ from .webgpu_constants import NGLToWebGPU
291
+
292
+ self.attributes.append(
293
+ {
294
+ "format": NGLToWebGPU.vertex_format(data_type),
295
+ "offset": offset,
296
+ "shader_location": location,
297
+ }
298
+ )
299
+ return self
300
+
301
+ def with_texcoord(
302
+ self,
303
+ data_type: str = "Vec2",
304
+ offset: int = 0,
305
+ location: int = 3,
306
+ ) -> "VertexLayoutBuilder":
307
+ """Add texture coordinate attribute."""
308
+ from .webgpu_constants import NGLToWebGPU
309
+
310
+ self.attributes.append(
311
+ {
312
+ "format": NGLToWebGPU.vertex_format(data_type),
313
+ "offset": offset,
314
+ "shader_location": location,
315
+ }
316
+ )
317
+ return self
318
+
319
+ def with_custom_attribute(
320
+ self,
321
+ data_type: str,
322
+ offset: int,
323
+ location: int,
324
+ ) -> "VertexLayoutBuilder":
325
+ """Add custom attribute."""
326
+ from .webgpu_constants import NGLToWebGPU
327
+
328
+ self.attributes.append(
329
+ {
330
+ "format": NGLToWebGPU.vertex_format(data_type),
331
+ "offset": offset,
332
+ "shader_location": location,
333
+ }
334
+ )
335
+ return self
336
+
337
+ def build(self) -> BufferLayout:
338
+ """Build the buffer layout."""
339
+ return BufferLayout(
340
+ stride=self.stride,
341
+ step_mode=self.step_mode,
342
+ attributes=self.attributes.copy(),
343
+ )
344
+
345
+
346
+ # Predefined configurations for common use cases
347
+ class PredefinedConfigs:
348
+ """Predefined pipeline configurations."""
349
+
350
+ @staticmethod
351
+ def point_single_colour() -> PipelineConfig:
352
+ """Single color point pipeline configuration."""
353
+ return (
354
+ PipelineConfigBuilder()
355
+ .primitive(PrimitiveType.POINT)
356
+ .color_mode(ColorMode.SINGLE)
357
+ .render_mode(RenderMode.BILLBOARDED)
358
+ .topology(wgpu.PrimitiveTopology.triangle_strip)
359
+ .build()
360
+ )
361
+
362
+ @staticmethod
363
+ def point_multi_colour() -> PipelineConfig:
364
+ """Multi-color point pipeline configuration."""
365
+ return (
366
+ PipelineConfigBuilder()
367
+ .primitive(PrimitiveType.POINT)
368
+ .color_mode(ColorMode.MULTI)
369
+ .render_mode(RenderMode.BILLBOARDED)
370
+ .topology(wgpu.PrimitiveTopology.triangle_strip)
371
+ .build()
372
+ )
373
+
374
+ @staticmethod
375
+ def line_single_colour() -> PipelineConfig:
376
+ """Single color line pipeline configuration."""
377
+ return (
378
+ PipelineConfigBuilder()
379
+ .primitive(PrimitiveType.LINE)
380
+ .color_mode(ColorMode.SINGLE)
381
+ .topology(wgpu.PrimitiveTopology.line_list)
382
+ .build()
383
+ )
384
+
385
+ @staticmethod
386
+ def line_multi_colour() -> PipelineConfig:
387
+ """Multi-color line pipeline configuration."""
388
+ return (
389
+ PipelineConfigBuilder()
390
+ .primitive(PrimitiveType.LINE)
391
+ .color_mode(ColorMode.MULTI)
392
+ .topology(wgpu.PrimitiveTopology.line_list)
393
+ .build()
394
+ )
395
+
396
+ @staticmethod
397
+ def triangle_single_colour() -> PipelineConfig:
398
+ """Single color triangle pipeline configuration."""
399
+ return (
400
+ PipelineConfigBuilder()
401
+ .primitive(PrimitiveType.TRIANGLE)
402
+ .color_mode(ColorMode.SINGLE)
403
+ .topology(wgpu.PrimitiveTopology.triangle_list)
404
+ .build()
405
+ )
406
+
407
+ @staticmethod
408
+ def triangle_multi_colour() -> PipelineConfig:
409
+ """Multi-color triangle pipeline configuration."""
410
+ return (
411
+ PipelineConfigBuilder()
412
+ .primitive(PrimitiveType.TRIANGLE)
413
+ .color_mode(ColorMode.MULTI)
414
+ .topology(wgpu.PrimitiveTopology.triangle_list)
415
+ .build()
416
+ )
417
+
418
+ @staticmethod
419
+ def triangle_strip_single_colour() -> PipelineConfig:
420
+ """Single color triangle strip pipeline configuration."""
421
+ return (
422
+ PipelineConfigBuilder()
423
+ .primitive(PrimitiveType.TRIANGLE)
424
+ .color_mode(ColorMode.SINGLE)
425
+ .topology(wgpu.PrimitiveTopology.triangle_strip)
426
+ .build()
427
+ )
428
+
429
+ @staticmethod
430
+ def triangle_strip_multi_colour() -> PipelineConfig:
431
+ """Multi-color triangle strip pipeline configuration."""
432
+ return (
433
+ PipelineConfigBuilder()
434
+ .primitive(PrimitiveType.TRIANGLE)
435
+ .color_mode(ColorMode.MULTI)
436
+ .topology(wgpu.PrimitiveTopology.triangle_strip)
437
+ .build()
438
+ )
439
+
440
+
441
+ def create_pipeline_config(
442
+ primitive_type: PrimitiveType,
443
+ color_mode: ColorMode,
444
+ topology: Optional[wgpu.PrimitiveTopology] = None,
445
+ **kwargs,
446
+ ) -> PipelineConfig:
447
+ """Create a pipeline configuration with sensible defaults."""
448
+ if topology is None:
449
+ # Set default topology based on primitive type
450
+ if primitive_type == PrimitiveType.POINT:
451
+ topology = wgpu.PrimitiveTopology.triangle_strip # For billboarding
452
+ elif primitive_type == PrimitiveType.LINE:
453
+ topology = wgpu.PrimitiveTopology.line_list
454
+ else: # TRIANGLE
455
+ topology = wgpu.PrimitiveTopology.triangle_list
456
+
457
+ return (
458
+ PipelineConfigBuilder()
459
+ .primitive(primitive_type)
460
+ .color_mode(color_mode)
461
+ .topology(topology)
462
+ .build()
463
+ )