diff options
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/CODING_STYLE.md | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/doc/CODING_STYLE.md b/doc/CODING_STYLE.md index 5c86409..254a1c3 100644 --- a/doc/CODING_STYLE.md +++ b/doc/CODING_STYLE.md @@ -52,6 +52,41 @@ Always use `defined()` and closing comment. --- +## Platform-Specific Code + +**Rule:** Platform-specific compilation (`#ifdef DEMO_CROSS_COMPILE_WIN32`, etc.) must be confined to `src/gpu/gpu.{h,cc}` and `src/platform/platform.{h,cc}`. + +### Correct +```cpp +// In gpu.h - abstract platform differences +#if defined(DEMO_CROSS_COMPILE_WIN32) +using GpuTextureCopyInfo = WGPUImageCopyTexture; +#else +using GpuTextureCopyInfo = WGPUTexelCopyTextureInfo; +#endif + +// In effect.cc - use abstraction +GpuTextureCopyInfo src_copy = { + .texture = src, .mipLevel = 0, .origin = {0, 0, 0}}; +``` + +### Wrong +```cpp +// In effect.cc - direct platform check (FORBIDDEN) +#if defined(DEMO_CROSS_COMPILE_WIN32) + WGPUImageCopyTexture src_copy = {...}; +#else + WGPUTexelCopyTextureInfo src_copy = {...}; +#endif +``` + +**Rationale:** +- Centralizes platform handling in gpu/platform layers +- Prevents #ifdef proliferation across codebase +- Makes cross-platform testing easier + +--- + ## Struct Initialization ### Good |
