[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7F9ZMY216N33QZPBM5WC8T3":3,"skill-same:01M7F9ZMY216N33QZPBM5WC8T3":62},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":28,"commitSha":29,"skillDirectory":30,"forksCount":13,"repositoryHtmlUrl":31,"repositoryHomepageUrl":6,"ownerHtmlUrl":32,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":33,"install":34,"resources":47},"01M7F9ZMY216N33QZPBM5WC8T3","blender-core-gpu",null,"Use when drawing custom overlays, viewport visualizations, or offscreen renders in Blender Python. Prevents the critical mistake of using the deprecated bgl module (removed in Blender 5.0) instead of the gpu module. Covers gpu.shader, gpu.batch, gpu.state, SpaceView3D draw handlers, built-in shaders, and BGL-to-gpu migration. Keywords: gpu module, bgl, draw handler, viewport overlay, offscreen rendering, SpaceView3D, shader, UNIFORM_COLOR, Blender Python drawing, draw on viewport, custom overlay, draw lines in 3D view.","lagzgabrielmuller-dot\u002Fkit-ingenieria-3d","lagzgabrielmuller-dot","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F333339260?v=4","01M7F985KYC0XB2XZ97B5YWH4C","01M7F985MHK8N2NVE4VAR5WBWS",0,"MIT","https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fblender-bim-sverchok\u002Fskills\u002Fblender\u002Fcore\u002Fblender-core-gpu\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: blender-core-gpu\ndescription: >\n  Use when drawing custom overlays, viewport visualizations, or offscreen renders in\n  Blender Python. Prevents the critical mistake of using the deprecated bgl module\n  (removed in Blender 5.0) instead of the gpu module. Covers gpu.shader, gpu.batch,\n  gpu.state, SpaceView3D draw handlers, built-in shaders, and BGL-to-gpu migration.\n  Keywords: gpu module, bgl, draw handler, viewport overlay, offscreen rendering, SpaceView3D, shader, UNIFORM_COLOR, Blender Python drawing, draw on viewport, custom overlay, draw lines in 3D view.\nlicense: MIT\ncompatibility: \"Designed for Claude Code. Requires Blender 3.x\u002F4.x\u002F5.x with Python.\"\nmetadata:\n  author: OpenAEC-Foundation\n  version: \"1.0\"\n---\n\n# blender-core-gpu\n\n## Quick Reference\n\n### Critical Warnings\n\n**NEVER** use the `bgl` module — it is deprecated since Blender 3.5 and **completely removed in Blender 5.0**. ALL drawing code MUST use the `gpu` module.\n\n**NEVER** use shader name `3D_UNIFORM_COLOR` or `3D_FLAT_COLOR` in Blender 4.0+ — the `3D_` prefix was removed. Use `UNIFORM_COLOR`, `POLYLINE_UNIFORM_COLOR`, etc.\n\n**NEVER** forget to restore `gpu.state` to defaults at the end of draw callbacks — failing to restore state corrupts rendering for ALL subsequent draw handlers and Blender's own UI.\n\n**NEVER** create `gpu.types.GPUOffScreen` outside a valid OpenGL\u002FGPU context — offscreen buffers require a graphics context (viewport draw callback or `bpy.types.SpaceView3D`).\n\n**NEVER** call `gpu.shader.from_builtin()` or create batches from a background thread — ALL GPU operations MUST execute on the main thread.\n\n**ALWAYS** remove draw handlers in addon `unregister()` — leaked handlers cause crashes or persistent ghost overlays.\n\n**ALWAYS** set `viewportSize` and `lineWidth` uniforms when using `POLYLINE_*` shaders — these are REQUIRED uniforms (Blender 4.0+).\n\n**ALWAYS** call `offscreen.free()` when done with offscreen buffers to prevent GPU memory leaks.\n\n### Module Overview\n\n| Module | Purpose |\n|--------|---------|\n| `gpu` | Core GPU module — shader creation, state management |\n| `gpu.shader` | Shader compilation, built-in shader access |\n| `gpu.types` | GPU types: `GPUShader`, `GPUBatch`, `GPUOffScreen`, `GPUTexture` |\n| `gpu.state` | OpenGL-like state: blend, depth, line width, viewport |\n| `gpu.texture` | Texture creation from images |\n| `gpu.matrix` | Model-view-projection matrix stack |\n| `gpu.select` | GPU-based selection utilities |\n| `gpu.platform` | GPU backend info (vendor, renderer, version) |\n| `gpu_extras.batch` | `batch_for_shader()` helper |\n| `gpu_extras.presets` | `draw_circle_2d()`, `draw_texture_2d()` |\n\n### Built-in Shaders (Blender 4.0+)\n\n| Shader Name | Geometry | Use Case |\n|-------------|----------|----------|\n| `'UNIFORM_COLOR'` | Triangles, points | Flat colored filled geometry |\n| `'POLYLINE_UNIFORM_COLOR'` | Lines | Lines with configurable width |\n| `'FLAT_COLOR'` | Triangles | Per-vertex colored (flat shaded) |\n| `'POLYLINE_FLAT_COLOR'` | Lines | Per-vertex colored lines |\n| `'SMOOTH_COLOR'` | Triangles | Per-vertex colored (smooth shaded) |\n| `'POLYLINE_SMOOTH_COLOR'` | Lines | Smooth per-vertex colored lines |\n| `'IMAGE'` | Triangles | Textured quads\u002Fgeometry |\n| `'IMAGE_COLOR'` | Triangles | Textured with color tint |\n\n#### Shader Name Version Map\n\n| Blender 3.x Name | Blender 4.0+ Name |\n|-------------------|-------------------|\n| `'3D_UNIFORM_COLOR'` | `'UNIFORM_COLOR'` |\n| `'3D_FLAT_COLOR'` | `'FLAT_COLOR'` |\n| `'3D_SMOOTH_COLOR'` | `'SMOOTH_COLOR'` |\n| `'3D_IMAGE'` | `'IMAGE'` |\n| `'2D_UNIFORM_COLOR'` | `'UNIFORM_COLOR'` |\n| `'2D_FLAT_COLOR'` | `'FLAT_COLOR'` |\n| `'2D_SMOOTH_COLOR'` | `'SMOOTH_COLOR'` |\n| `'2D_IMAGE'` | `'IMAGE'` |\n\nIn Blender 4.0+, the `2D_`\u002F`3D_` distinction is removed. A single `'UNIFORM_COLOR'` works in both 2D and 3D contexts.\n\n---\n\n## Essential Patterns\n\n### Pattern 1: Basic Line Drawing with POLYLINE Shader\n\n```python\n# Blender 4.0+\u002F5.x: Draw colored lines in 3D viewport\nimport bpy\nimport gpu\nfrom gpu_extras.batch import batch_for_shader\n\ndef draw_lines():\n    coords = [(0, 0, 0), (5, 0, 0), (5, 5, 0), (0, 5, 0), (0, 0, 0)]\n    shader = gpu.shader.from_builtin('POLYLINE_UNIFORM_COLOR')\n    batch = batch_for_shader(shader, 'LINE_STRIP', {\"pos\": coords})\n\n    gpu.state.blend_set('ALPHA')\n    gpu.state.line_width_set(2.0)\n\n    shader.bind()\n    region = bpy.context.region\n    shader.uniform_float(\"viewportSize\", (region.width, region.height))\n    shader.uniform_float(\"lineWidth\", 2.0)\n    shader.uniform_float(\"color\", (1.0, 0.0, 0.0, 0.8))\n    batch.draw(shader)\n\n    # ALWAYS restore state\n    gpu.state.blend_set('NONE')\n    gpu.state.line_width_set(1.0)\n\n_handle = bpy.types.SpaceView3D.draw_handler_add(draw_lines, (), 'WINDOW', 'POST_VIEW')\n# Remove: bpy.types.SpaceView3D.draw_handler_remove(_handle, 'WINDOW')\n```\n\n### Pattern 2: Filled Triangles with UNIFORM_COLOR\n\n```python\n# Blender 4.0+\u002F5.x: Draw a filled quad (two triangles)\nimport gpu\nfrom gpu_extras.batch import batch_for_shader\n\ndef draw_filled():\n    verts = [(0, 0, 0), (5, 0, 0), (5, 5, 0), (0, 5, 0)]\n    indices = ((0, 1, 2), (2, 3, 0))\n    shader = gpu.shader.from_builtin('UNIFORM_COLOR')\n    batch = batch_for_shader(shader, 'TRIS', {\"pos\": verts}, indices=indices)\n\n    gpu.state.blend_set('ALPHA')\n    shader.bind()\n    shader.uniform_float(\"color\", (0.0, 0.5, 1.0, 0.3))\n    batch.draw(shader)\n    gpu.state.blend_set('NONE')\n```\n\n### Pattern 3: Draw Handler Registration\u002FRemoval\n\n```python\n# Blender 3.x\u002F4.x\u002F5.x: Proper handler lifecycle in an addon\nimport bpy\n\n_draw_handle = None\n\ndef register():\n    global _draw_handle\n    _draw_handle = bpy.types.SpaceView3D.draw_handler_add(\n        draw_callback, (), 'WINDOW', 'POST_VIEW'\n    )\n\ndef unregister():\n    global _draw_handle\n    if _draw_handle is not None:\n        bpy.types.SpaceView3D.draw_handler_remove(_draw_handle, 'WINDOW')\n        _draw_handle = None\n```\n\n#### Draw Handler Layer Options\n\n| Layer | When | Coordinate Space |\n|-------|------|------------------|\n| `'PRE_VIEW'` | Before 3D scene | 3D world space |\n| `'POST_VIEW'` | After 3D scene, before gizmos | 3D world space |\n| `'POST_PIXEL'` | After everything, on top | 2D pixel space |\n\n### Pattern 4: Version-Compatible Shader Selection\n\n```python\n# Blender 3.x\u002F4.x\u002F5.x: Version-safe shader selection\nimport bpy\nimport gpu\n\ndef get_line_shader():\n    if bpy.app.version >= (4, 0, 0):\n        return gpu.shader.from_builtin('POLYLINE_UNIFORM_COLOR')\n    else:\n        return gpu.shader.from_builtin('3D_UNIFORM_COLOR')\n\ndef get_flat_shader():\n    if bpy.app.version >= (4, 0, 0):\n        return gpu.shader.from_builtin('UNIFORM_COLOR')\n    else:\n        return gpu.shader.from_builtin('3D_UNIFORM_COLOR')\n```\n\n### Pattern 5: Offscreen Rendering\n\n```python\n# Blender 4.x\u002F5.x: Render to offscreen buffer\nimport gpu\n\noffscreen = gpu.types.GPUOffScreen(512, 512)\nwith offscreen.bind():\n    fb = gpu.state.active_framebuffer_get()\n    fb.clear(color=(0.0, 0.0, 0.0, 0.0))\n    # Draw operations here (shaders, batches)\n\ntexture = offscreen.texture_color  # GPUTexture\noffscreen.free()  # ALWAYS free when done\n```\n\n### Pattern 6: GPU State Management\n\n```python\n# Blender 3.5+\u002F4.x\u002F5.x: Full state management pattern\nimport gpu\n\ndef draw_with_state():\n    # Save implicit state by setting explicitly\n    gpu.state.blend_set('ALPHA')\n    gpu.state.depth_test_set('LESS_EQUAL')\n    gpu.state.depth_mask_set(True)\n    gpu.state.line_width_set(2.0)\n    gpu.state.point_size_set(5.0)\n    gpu.state.face_culling_set('BACK')\n\n    # ... draw calls ...\n\n    # ALWAYS restore defaults\n    gpu.state.blend_set('NONE')\n    gpu.state.depth_test_set('NONE')\n    gpu.state.depth_mask_set(False)\n    gpu.state.line_width_set(1.0)\n    gpu.state.point_size_set(1.0)\n    gpu.state.face_culling_set('NONE')\n```\n\n---\n\n## Common Operations\n\n### Drawing 2D Overlays (POST_PIXEL)\n\n```python\n# Blender 4.0+\u002F5.x: 2D HUD overlay in pixel coordinates\nimport bpy\nimport gpu\nfrom gpu_extras.batch import batch_for_shader\n\ndef draw_2d_overlay():\n    verts = [(10, 10), (200, 10), (200, 50), (10, 50)]\n    indices = ((0, 1, 2), (2, 3, 0))\n    shader = gpu.shader.from_builtin('UNIFORM_COLOR')\n    batch = batch_for_shader(shader, 'TRIS', {\"pos\": verts}, indices=indices)\n\n    gpu.state.blend_set('ALPHA')\n    shader.bind()\n    shader.uniform_float(\"color\", (0.0, 0.0, 0.0, 0.5))\n    batch.draw(shader)\n    gpu.state.blend_set('NONE')\n\n# POST_PIXEL = 2D pixel space overlay\n_handle = bpy.types.SpaceView3D.draw_handler_add(\n    draw_2d_overlay, (), 'WINDOW', 'POST_PIXEL'\n)\n```\n\n### Drawing Textured Quads\n\n```python\n# Blender 4.0+\u002F5.x: Draw image texture in viewport\nimport gpu\nfrom gpu_extras.batch import batch_for_shader\n\ndef draw_image(texture):\n    shader = gpu.shader.from_builtin('IMAGE')\n    batch = batch_for_shader(\n        shader, 'TRI_FAN',\n        {\n            \"pos\": ((0, 0), (200, 0), (200, 200), (0, 200)),\n            \"texCoord\": ((0, 0), (1, 0), (1, 1), (0, 1)),\n        },\n    )\n    shader.bind()\n    shader.uniform_sampler(\"image\", texture)\n    batch.draw(shader)\n```\n\n### Per-Vertex Colored Geometry\n\n```python\n# Blender 4.0+\u002F5.x: Smooth colored triangle\nimport gpu\nfrom gpu_extras.batch import batch_for_shader\n\nshader = gpu.shader.from_builtin('SMOOTH_COLOR')\nbatch = batch_for_shader(shader, 'TRIS', {\n    \"pos\": [(0, 0, 0), (5, 0, 0), (2.5, 5, 0)],\n    \"color\": [(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)],\n})\nshader.bind()\nbatch.draw(shader)\n```\n\n### Loading Image as GPU Texture\n\n```python\n# Blender 4.0+\u002F5.x: Load image to GPU texture (replaces bgl texture binding)\nimport bpy\nimport gpu\n\nimage = bpy.data.images.load(\"\u002Fpath\u002Fto\u002Fimage.png\")\ntexture = gpu.texture.from_image(image)\n# Use texture with IMAGE shader via shader.uniform_sampler(\"image\", texture)\n```\n\n---\n\n## BGL-to-gpu Migration Checklist\n\nWhen migrating code from `bgl` to `gpu`:\n\n1. **Remove** ALL `import bgl` statements\n2. **Replace** `bgl.glEnable(bgl.GL_BLEND)` → `gpu.state.blend_set('ALPHA')`\n3. **Replace** `bgl.glDisable(bgl.GL_BLEND)` → `gpu.state.blend_set('NONE')`\n4. **Replace** `bgl.glLineWidth(w)` → `gpu.state.line_width_set(w)`\n5. **Replace** `bgl.glEnable(bgl.GL_DEPTH_TEST)` → `gpu.state.depth_test_set('LESS_EQUAL')`\n6. **Replace** `bgl.glDisable(bgl.GL_DEPTH_TEST)` → `gpu.state.depth_test_set('NONE')`\n7. **Replace** `bgl.glDepthMask(GL_TRUE)` → `gpu.state.depth_mask_set(True)`\n8. **Replace** `bgl.glPointSize(s)` → `gpu.state.point_size_set(s)`\n9. **Replace** `bgl.glEnable(bgl.GL_LINE_SMOOTH)` → use `POLYLINE_*` shaders (no direct replacement)\n10. **Replace** `image.gl_load()` \u002F `bgl.glBindTexture()` → `gpu.texture.from_image(image)`\n11. **Replace** `3D_UNIFORM_COLOR` → `POLYLINE_UNIFORM_COLOR` (for lines) or `UNIFORM_COLOR` (for triangles)\n12. **Replace** `3D_FLAT_COLOR` → `POLYLINE_FLAT_COLOR` (for lines) or `FLAT_COLOR` (for triangles)\n13. **Add** `viewportSize` and `lineWidth` uniforms for ALL `POLYLINE_*` shaders\n14. **Add** state restoration at end of every draw callback\n15. **Test** on Apple Silicon (Metal backend) — bgl was already non-functional there\n\n### BGL-to-gpu API Mapping\n\n| bgl (REMOVED in 5.0) | gpu replacement (3.5+) | Notes |\n|---|---|---|\n| `bgl.glEnable(bgl.GL_BLEND)` | `gpu.state.blend_set('ALPHA')` | Options: `'ALPHA'`, `'ADDITIVE'`, `'ADDITIVE_PREMUL'`, `'MULTIPLY'` |\n| `bgl.glDisable(bgl.GL_BLEND)` | `gpu.state.blend_set('NONE')` | |\n| `bgl.glLineWidth(w)` | `gpu.state.line_width_set(w)` | Also set `lineWidth` uniform for POLYLINE shaders |\n| `bgl.glEnable(bgl.GL_DEPTH_TEST)` | `gpu.state.depth_test_set('LESS_EQUAL')` | Options: `'NONE'`, `'LESS'`, `'LESS_EQUAL'`, `'EQUAL'`, `'GREATER'` |\n| `bgl.glDisable(bgl.GL_DEPTH_TEST)` | `gpu.state.depth_test_set('NONE')` | |\n| `bgl.glDepthMask(GL_TRUE)` | `gpu.state.depth_mask_set(True)` | |\n| `bgl.glPointSize(s)` | `gpu.state.point_size_set(s)` | |\n| `bgl.glEnable(bgl.GL_LINE_SMOOTH)` | *(no direct replacement)* | Use `POLYLINE_*` shaders for antialiased lines |\n| `image.gl_load()` \u002F `bgl.glBindTexture()` | `gpu.texture.from_image(image)` | Completely different API |\n\n---\n\n## Version Timeline\n\n| Version | Change |\n|---------|--------|\n| Blender 3.0 | `gpu` module stable, `gpu_extras.batch` available |\n| Blender 3.5 | `bgl` module officially deprecated |\n| Blender 4.0 | `3D_`\u002F`2D_` shader name prefixes removed; `POLYLINE_*` shaders added |\n| Blender 5.0 | `bgl` module completely removed; `gpu` is the ONLY drawing API |\n\n---\n\n## Reference Links\n\n- [references\u002Fmethods.md](references\u002Fmethods.md) — Complete API signatures for gpu, gpu.shader, gpu.state, gpu.types, gpu_extras\n- [references\u002Fexamples.md](references\u002Fexamples.md) — Working code examples for all drawing scenarios\n- [references\u002Fanti-patterns.md](references\u002Fanti-patterns.md) — What NOT to do with GPU drawing\n\n### Cross-References\n\n- [blender-core-api](..\u002Fblender-core-api\u002FSKILL.md) — bpy.context, draw handler registration, restricted contexts\n\n### Official Sources\n\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu.html\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu.shader.html\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu.types.html\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu.state.html\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu_extras.batch.html\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu_extras.presets.html\n","# blender-core-gpu\n\n## Quick Reference\n\n### Critical Warnings\n\n**NEVER** use the `bgl` module — it is deprecated since Blender 3.5 and **completely removed in Blender 5.0**. ALL drawing code MUST use the `gpu` module.\n\n**NEVER** use shader name `3D_UNIFORM_COLOR` or `3D_FLAT_COLOR` in Blender 4.0+ — the `3D_` prefix was removed. Use `UNIFORM_COLOR`, `POLYLINE_UNIFORM_COLOR`, etc.\n\n**NEVER** forget to restore `gpu.state` to defaults at the end of draw callbacks — failing to restore state corrupts rendering for ALL subsequent draw handlers and Blender's own UI.\n\n**NEVER** create `gpu.types.GPUOffScreen` outside a valid OpenGL\u002FGPU context — offscreen buffers require a graphics context (viewport draw callback or `bpy.types.SpaceView3D`).\n\n**NEVER** call `gpu.shader.from_builtin()` or create batches from a background thread — ALL GPU operations MUST execute on the main thread.\n\n**ALWAYS** remove draw handlers in addon `unregister()` — leaked handlers cause crashes or persistent ghost overlays.\n\n**ALWAYS** set `viewportSize` and `lineWidth` uniforms when using `POLYLINE_*` shaders — these are REQUIRED uniforms (Blender 4.0+).\n\n**ALWAYS** call `offscreen.free()` when done with offscreen buffers to prevent GPU memory leaks.\n\n### Module Overview\n\n| Module | Purpose |\n|--------|---------|\n| `gpu` | Core GPU module — shader creation, state management |\n| `gpu.shader` | Shader compilation, built-in shader access |\n| `gpu.types` | GPU types: `GPUShader`, `GPUBatch`, `GPUOffScreen`, `GPUTexture` |\n| `gpu.state` | OpenGL-like state: blend, depth, line width, viewport |\n| `gpu.texture` | Texture creation from images |\n| `gpu.matrix` | Model-view-projection matrix stack |\n| `gpu.select` | GPU-based selection utilities |\n| `gpu.platform` | GPU backend info (vendor, renderer, version) |\n| `gpu_extras.batch` | `batch_for_shader()` helper |\n| `gpu_extras.presets` | `draw_circle_2d()`, `draw_texture_2d()` |\n\n### Built-in Shaders (Blender 4.0+)\n\n| Shader Name | Geometry | Use Case |\n|-------------|----------|----------|\n| `'UNIFORM_COLOR'` | Triangles, points | Flat colored filled geometry |\n| `'POLYLINE_UNIFORM_COLOR'` | Lines | Lines with configurable width |\n| `'FLAT_COLOR'` | Triangles | Per-vertex colored (flat shaded) |\n| `'POLYLINE_FLAT_COLOR'` | Lines | Per-vertex colored lines |\n| `'SMOOTH_COLOR'` | Triangles | Per-vertex colored (smooth shaded) |\n| `'POLYLINE_SMOOTH_COLOR'` | Lines | Smooth per-vertex colored lines |\n| `'IMAGE'` | Triangles | Textured quads\u002Fgeometry |\n| `'IMAGE_COLOR'` | Triangles | Textured with color tint |\n\n#### Shader Name Version Map\n\n| Blender 3.x Name | Blender 4.0+ Name |\n|-------------------|-------------------|\n| `'3D_UNIFORM_COLOR'` | `'UNIFORM_COLOR'` |\n| `'3D_FLAT_COLOR'` | `'FLAT_COLOR'` |\n| `'3D_SMOOTH_COLOR'` | `'SMOOTH_COLOR'` |\n| `'3D_IMAGE'` | `'IMAGE'` |\n| `'2D_UNIFORM_COLOR'` | `'UNIFORM_COLOR'` |\n| `'2D_FLAT_COLOR'` | `'FLAT_COLOR'` |\n| `'2D_SMOOTH_COLOR'` | `'SMOOTH_COLOR'` |\n| `'2D_IMAGE'` | `'IMAGE'` |\n\nIn Blender 4.0+, the `2D_`\u002F`3D_` distinction is removed. A single `'UNIFORM_COLOR'` works in both 2D and 3D contexts.\n\n---\n\n## Essential Patterns\n\n### Pattern 1: Basic Line Drawing with POLYLINE Shader\n\n```python\n# Blender 4.0+\u002F5.x: Draw colored lines in 3D viewport\nimport bpy\nimport gpu\nfrom gpu_extras.batch import batch_for_shader\n\ndef draw_lines():\n    coords = [(0, 0, 0), (5, 0, 0), (5, 5, 0), (0, 5, 0), (0, 0, 0)]\n    shader = gpu.shader.from_builtin('POLYLINE_UNIFORM_COLOR')\n    batch = batch_for_shader(shader, 'LINE_STRIP', {\"pos\": coords})\n\n    gpu.state.blend_set('ALPHA')\n    gpu.state.line_width_set(2.0)\n\n    shader.bind()\n    region = bpy.context.region\n    shader.uniform_float(\"viewportSize\", (region.width, region.height))\n    shader.uniform_float(\"lineWidth\", 2.0)\n    shader.uniform_float(\"color\", (1.0, 0.0, 0.0, 0.8))\n    batch.draw(shader)\n\n    # ALWAYS restore state\n    gpu.state.blend_set('NONE')\n    gpu.state.line_width_set(1.0)\n\n_handle = bpy.types.SpaceView3D.draw_handler_add(draw_lines, (), 'WINDOW', 'POST_VIEW')\n# Remove: bpy.types.SpaceView3D.draw_handler_remove(_handle, 'WINDOW')\n```\n\n### Pattern 2: Filled Triangles with UNIFORM_COLOR\n\n```python\n# Blender 4.0+\u002F5.x: Draw a filled quad (two triangles)\nimport gpu\nfrom gpu_extras.batch import batch_for_shader\n\ndef draw_filled():\n    verts = [(0, 0, 0), (5, 0, 0), (5, 5, 0), (0, 5, 0)]\n    indices = ((0, 1, 2), (2, 3, 0))\n    shader = gpu.shader.from_builtin('UNIFORM_COLOR')\n    batch = batch_for_shader(shader, 'TRIS', {\"pos\": verts}, indices=indices)\n\n    gpu.state.blend_set('ALPHA')\n    shader.bind()\n    shader.uniform_float(\"color\", (0.0, 0.5, 1.0, 0.3))\n    batch.draw(shader)\n    gpu.state.blend_set('NONE')\n```\n\n### Pattern 3: Draw Handler Registration\u002FRemoval\n\n```python\n# Blender 3.x\u002F4.x\u002F5.x: Proper handler lifecycle in an addon\nimport bpy\n\n_draw_handle = None\n\ndef register():\n    global _draw_handle\n    _draw_handle = bpy.types.SpaceView3D.draw_handler_add(\n        draw_callback, (), 'WINDOW', 'POST_VIEW'\n    )\n\ndef unregister():\n    global _draw_handle\n    if _draw_handle is not None:\n        bpy.types.SpaceView3D.draw_handler_remove(_draw_handle, 'WINDOW')\n        _draw_handle = None\n```\n\n#### Draw Handler Layer Options\n\n| Layer | When | Coordinate Space |\n|-------|------|------------------|\n| `'PRE_VIEW'` | Before 3D scene | 3D world space |\n| `'POST_VIEW'` | After 3D scene, before gizmos | 3D world space |\n| `'POST_PIXEL'` | After everything, on top | 2D pixel space |\n\n### Pattern 4: Version-Compatible Shader Selection\n\n```python\n# Blender 3.x\u002F4.x\u002F5.x: Version-safe shader selection\nimport bpy\nimport gpu\n\ndef get_line_shader():\n    if bpy.app.version >= (4, 0, 0):\n        return gpu.shader.from_builtin('POLYLINE_UNIFORM_COLOR')\n    else:\n        return gpu.shader.from_builtin('3D_UNIFORM_COLOR')\n\ndef get_flat_shader():\n    if bpy.app.version >= (4, 0, 0):\n        return gpu.shader.from_builtin('UNIFORM_COLOR')\n    else:\n        return gpu.shader.from_builtin('3D_UNIFORM_COLOR')\n```\n\n### Pattern 5: Offscreen Rendering\n\n```python\n# Blender 4.x\u002F5.x: Render to offscreen buffer\nimport gpu\n\noffscreen = gpu.types.GPUOffScreen(512, 512)\nwith offscreen.bind():\n    fb = gpu.state.active_framebuffer_get()\n    fb.clear(color=(0.0, 0.0, 0.0, 0.0))\n    # Draw operations here (shaders, batches)\n\ntexture = offscreen.texture_color  # GPUTexture\noffscreen.free()  # ALWAYS free when done\n```\n\n### Pattern 6: GPU State Management\n\n```python\n# Blender 3.5+\u002F4.x\u002F5.x: Full state management pattern\nimport gpu\n\ndef draw_with_state():\n    # Save implicit state by setting explicitly\n    gpu.state.blend_set('ALPHA')\n    gpu.state.depth_test_set('LESS_EQUAL')\n    gpu.state.depth_mask_set(True)\n    gpu.state.line_width_set(2.0)\n    gpu.state.point_size_set(5.0)\n    gpu.state.face_culling_set('BACK')\n\n    # ... draw calls ...\n\n    # ALWAYS restore defaults\n    gpu.state.blend_set('NONE')\n    gpu.state.depth_test_set('NONE')\n    gpu.state.depth_mask_set(False)\n    gpu.state.line_width_set(1.0)\n    gpu.state.point_size_set(1.0)\n    gpu.state.face_culling_set('NONE')\n```\n\n---\n\n## Common Operations\n\n### Drawing 2D Overlays (POST_PIXEL)\n\n```python\n# Blender 4.0+\u002F5.x: 2D HUD overlay in pixel coordinates\nimport bpy\nimport gpu\nfrom gpu_extras.batch import batch_for_shader\n\ndef draw_2d_overlay():\n    verts = [(10, 10), (200, 10), (200, 50), (10, 50)]\n    indices = ((0, 1, 2), (2, 3, 0))\n    shader = gpu.shader.from_builtin('UNIFORM_COLOR')\n    batch = batch_for_shader(shader, 'TRIS', {\"pos\": verts}, indices=indices)\n\n    gpu.state.blend_set('ALPHA')\n    shader.bind()\n    shader.uniform_float(\"color\", (0.0, 0.0, 0.0, 0.5))\n    batch.draw(shader)\n    gpu.state.blend_set('NONE')\n\n# POST_PIXEL = 2D pixel space overlay\n_handle = bpy.types.SpaceView3D.draw_handler_add(\n    draw_2d_overlay, (), 'WINDOW', 'POST_PIXEL'\n)\n```\n\n### Drawing Textured Quads\n\n```python\n# Blender 4.0+\u002F5.x: Draw image texture in viewport\nimport gpu\nfrom gpu_extras.batch import batch_for_shader\n\ndef draw_image(texture):\n    shader = gpu.shader.from_builtin('IMAGE')\n    batch = batch_for_shader(\n        shader, 'TRI_FAN',\n        {\n            \"pos\": ((0, 0), (200, 0), (200, 200), (0, 200)),\n            \"texCoord\": ((0, 0), (1, 0), (1, 1), (0, 1)),\n        },\n    )\n    shader.bind()\n    shader.uniform_sampler(\"image\", texture)\n    batch.draw(shader)\n```\n\n### Per-Vertex Colored Geometry\n\n```python\n# Blender 4.0+\u002F5.x: Smooth colored triangle\nimport gpu\nfrom gpu_extras.batch import batch_for_shader\n\nshader = gpu.shader.from_builtin('SMOOTH_COLOR')\nbatch = batch_for_shader(shader, 'TRIS', {\n    \"pos\": [(0, 0, 0), (5, 0, 0), (2.5, 5, 0)],\n    \"color\": [(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)],\n})\nshader.bind()\nbatch.draw(shader)\n```\n\n### Loading Image as GPU Texture\n\n```python\n# Blender 4.0+\u002F5.x: Load image to GPU texture (replaces bgl texture binding)\nimport bpy\nimport gpu\n\nimage = bpy.data.images.load(\"\u002Fpath\u002Fto\u002Fimage.png\")\ntexture = gpu.texture.from_image(image)\n# Use texture with IMAGE shader via shader.uniform_sampler(\"image\", texture)\n```\n\n---\n\n## BGL-to-gpu Migration Checklist\n\nWhen migrating code from `bgl` to `gpu`:\n\n1. **Remove** ALL `import bgl` statements\n2. **Replace** `bgl.glEnable(bgl.GL_BLEND)` → `gpu.state.blend_set('ALPHA')`\n3. **Replace** `bgl.glDisable(bgl.GL_BLEND)` → `gpu.state.blend_set('NONE')`\n4. **Replace** `bgl.glLineWidth(w)` → `gpu.state.line_width_set(w)`\n5. **Replace** `bgl.glEnable(bgl.GL_DEPTH_TEST)` → `gpu.state.depth_test_set('LESS_EQUAL')`\n6. **Replace** `bgl.glDisable(bgl.GL_DEPTH_TEST)` → `gpu.state.depth_test_set('NONE')`\n7. **Replace** `bgl.glDepthMask(GL_TRUE)` → `gpu.state.depth_mask_set(True)`\n8. **Replace** `bgl.glPointSize(s)` → `gpu.state.point_size_set(s)`\n9. **Replace** `bgl.glEnable(bgl.GL_LINE_SMOOTH)` → use `POLYLINE_*` shaders (no direct replacement)\n10. **Replace** `image.gl_load()` \u002F `bgl.glBindTexture()` → `gpu.texture.from_image(image)`\n11. **Replace** `3D_UNIFORM_COLOR` → `POLYLINE_UNIFORM_COLOR` (for lines) or `UNIFORM_COLOR` (for triangles)\n12. **Replace** `3D_FLAT_COLOR` → `POLYLINE_FLAT_COLOR` (for lines) or `FLAT_COLOR` (for triangles)\n13. **Add** `viewportSize` and `lineWidth` uniforms for ALL `POLYLINE_*` shaders\n14. **Add** state restoration at end of every draw callback\n15. **Test** on Apple Silicon (Metal backend) — bgl was already non-functional there\n\n### BGL-to-gpu API Mapping\n\n| bgl (REMOVED in 5.0) | gpu replacement (3.5+) | Notes |\n|---|---|---|\n| `bgl.glEnable(bgl.GL_BLEND)` | `gpu.state.blend_set('ALPHA')` | Options: `'ALPHA'`, `'ADDITIVE'`, `'ADDITIVE_PREMUL'`, `'MULTIPLY'` |\n| `bgl.glDisable(bgl.GL_BLEND)` | `gpu.state.blend_set('NONE')` | |\n| `bgl.glLineWidth(w)` | `gpu.state.line_width_set(w)` | Also set `lineWidth` uniform for POLYLINE shaders |\n| `bgl.glEnable(bgl.GL_DEPTH_TEST)` | `gpu.state.depth_test_set('LESS_EQUAL')` | Options: `'NONE'`, `'LESS'`, `'LESS_EQUAL'`, `'EQUAL'`, `'GREATER'` |\n| `bgl.glDisable(bgl.GL_DEPTH_TEST)` | `gpu.state.depth_test_set('NONE')` | |\n| `bgl.glDepthMask(GL_TRUE)` | `gpu.state.depth_mask_set(True)` | |\n| `bgl.glPointSize(s)` | `gpu.state.point_size_set(s)` | |\n| `bgl.glEnable(bgl.GL_LINE_SMOOTH)` | *(no direct replacement)* | Use `POLYLINE_*` shaders for antialiased lines |\n| `image.gl_load()` \u002F `bgl.glBindTexture()` | `gpu.texture.from_image(image)` | Completely different API |\n\n---\n\n## Version Timeline\n\n| Version | Change |\n|---------|--------|\n| Blender 3.0 | `gpu` module stable, `gpu_extras.batch` available |\n| Blender 3.5 | `bgl` module officially deprecated |\n| Blender 4.0 | `3D_`\u002F`2D_` shader name prefixes removed; `POLYLINE_*` shaders added |\n| Blender 5.0 | `bgl` module completely removed; `gpu` is the ONLY drawing API |\n\n---\n\n## Reference Links\n\n- [references\u002Fmethods.md](references\u002Fmethods.md) — Complete API signatures for gpu, gpu.shader, gpu.state, gpu.types, gpu_extras\n- [references\u002Fexamples.md](references\u002Fexamples.md) — Working code examples for all drawing scenarios\n- [references\u002Fanti-patterns.md](references\u002Fanti-patterns.md) — What NOT to do with GPU drawing\n\n### Cross-References\n\n- [blender-core-api](..\u002Fblender-core-api\u002FSKILL.md) — bpy.context, draw handler registration, restricted contexts\n\n### Official Sources\n\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu.html\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu.shader.html\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu.types.html\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu.state.html\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu_extras.batch.html\n- https:\u002F\u002Fdocs.blender.org\u002Fapi\u002Fcurrent\u002Fgpu_extras.presets.html\n",{"name":5,"license":14,"metadata":23,"description":26,"compatibility":27},{"author":24,"version":25},"OpenAEC-Foundation","1.0","Use when drawing custom overlays, viewport visualizations, or offscreen renders in Blender Python. Prevents the critical mistake of using the deprecated bgl module (removed in Blender 5.0) instead of the gpu module. Covers gpu.shader, gpu.batch, gpu.state, SpaceView3D draw handlers, built-in shaders, and BGL-to-gpu migration. Keywords: gpu module, bgl, draw handler, viewport overlay, offscreen rendering, SpaceView3D, shader, UNIFORM_COLOR, Blender Python drawing, draw on viewport, custom overlay, draw lines in 3D view.\n","Designed for Claude Code. Requires Blender 3.x\u002F4.x\u002F5.x with Python.","main","9bb7acf0c2ec4f44373969cb14e55af3c9a8385f","plugins\u002Fblender-bim-sverchok\u002Fskills\u002Fblender\u002Fcore\u002Fblender-core-gpu","https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d","https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot","2026-11-09 13:26:47",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add lagzgabrielmuller-dot\u002Fkit-ingenieria-3d --skill blender-core-gpu",{"tool":40,"command":41},"bunx","bunx skills add lagzgabrielmuller-dot\u002Fkit-ingenieria-3d --skill blender-core-gpu",{"tool":43,"command":44},"pnpm","pnpm dlx skills add lagzgabrielmuller-dot\u002Fkit-ingenieria-3d --skill blender-core-gpu","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fblender-bim-sverchok\u002Fskills\u002Fblender\u002Fcore\u002Fblender-core-gpu\u002FSKILL.md",true,[48,54,58],{"path":49,"resourceType":50,"resourceTypeDesc":51,"sizeBytes":52,"sourceHtmlUrl":53},"references\u002Fanti-patterns.md","REFERENCE","参考文档",11834,"https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fblender-bim-sverchok\u002Fskills\u002Fblender\u002Fcore\u002Fblender-core-gpu\u002Freferences\u002Fanti-patterns.md",{"path":55,"resourceType":50,"resourceTypeDesc":51,"sizeBytes":56,"sourceHtmlUrl":57},"references\u002Fexamples.md",15843,"https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fblender-bim-sverchok\u002Fskills\u002Fblender\u002Fcore\u002Fblender-core-gpu\u002Freferences\u002Fexamples.md",{"path":59,"resourceType":50,"resourceTypeDesc":51,"sizeBytes":60,"sourceHtmlUrl":61},"references\u002Fmethods.md",12679,"https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fblender-bim-sverchok\u002Fskills\u002Fblender\u002Fcore\u002Fblender-core-gpu\u002Freferences\u002Fmethods.md",[63,71,78,85,92,99],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":67,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":18},"01M7FBFSZ93YM463CGS91D0TZG","manimce-best-practices","Trigger when: (1) User mentions \"manim\" or \"Manim Community\" or \"ManimCE\", (2) Code contains `from manim import *`, (3) User runs `manim` CLI commands, (4) Working with Scene, MathTex, Create(), or ManimCE-specific classes.\n\nBest practices for Manim Community Edition - the community-maintained Python animation engine. Covers Scene structure, animations, LaTeX\u002FMathTex, 3D with ThreeDScene, camera control, styling, and CLI usage.\n\nNOT for ManimGL\u002F3b1b version (which uses `manimlib` imports and `manimgl` CLI).","https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fmanim-animaciones\u002Fskills\u002Fmanimce-best-practices\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fmanim-animaciones\u002Fskills\u002Fmanimce-best-practices\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":18},"01M7FB2K59HNNXS9WKHAMWHC3C","drawio","Create, edit, replicate, import, and export draw.io diagrams with an offline YAML-first workflow: architecture, network topologies, flowcharts, UML\u002FER, org charts, Mermaid\u002FCSV conversion, existing .drawio bundles, style presets, themes, and non-publication formula diagrams. For publication figures (paper, thesis, IEEE, camera-ready) use drawio-academic-skills instead.","https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fdiagramas-y-documentos\u002Fskills\u002Fdrawio\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":18},"01M7FB2BWX7GWK9H2X8BGCYDDD","drawio-academic-skills","Publication-figure overlay for draw.io. Use instead of drawio whenever the diagram is for a paper, thesis, dissertation, journal, conference, IEEE\u002FACM submission, manuscript, camera-ready, Word\u002FLaTeX figure, or other publication. Applies venue, figure-type, color, caption\u002Flegend, formula, and paper-readability gates for architecture, workflow, roadmap, network-topology, and replicated paper figures.","https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fdiagramas-y-documentos\u002Fskills\u002Fdrawio-academic-skills\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":18},"01M7FB22JESEAV8T15DJT3D444","uncertainty-and-units","Tracks physical units and propagates measurement uncertainty in scientific calculations using pint and uncertainties. Use for unit conversion and dimensional checking, GUM uncertainty budgets, Type A and Type B evaluation, coverage factors and expanded uncertainty, Monte Carlo propagation, significant-figure and plus-minus reporting, error propagation through curve fits, CODATA constants, auditing Python code for stripped units or broken uncertainty propagation, and order-of-magnitude plausibility checks using dimensionless groups (Reynolds, Peclet, Damkohler, Knudsen, Biot, Womersley), characteristic scales such as diffusion time or Debye length, and observed magnitude ranges. Trigger on \"is this number physically reasonable\", \"sanity check these units\", \"what regime is this flow in\", or a result that looks off by orders of magnitude.","https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fciencia-y-calculo\u002Fskills\u002Funcertainty-and-units\u002FSKILL.md",[],[],{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":18},"01M7FB1ANRSG28R335FDY9SA3R","statistical-analysis","Guided statistical analysis for research data - test selection, assumption checking, effect sizes, power analysis, Bayesian alternatives, and APA-formatted reporting. Use whenever a user wants to compare groups, test a hypothesis, analyze experimental or survey data, check statistical assumptions, compute required sample sizes, or write up results - even if they never name a specific test. Covers t-tests, ANOVA, chi-square, correlation, regression, non-parametric and Bayesian methods. For low-level model APIs, see the statsmodels and pymc skills.","https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fciencia-y-calculo\u002Fskills\u002Fstatistical-analysis\u002FSKILL.md",[],[],{"skillNo":100,"name":101,"nameZh":6,"description":102,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":18},"01M7FB15KRA9D7JCPH4P9T6XJY","simpy","Builds, inspects, tests, and analyzes bounded process-based discrete-event simulations with SimPy. Use for event scheduling, resource queues, interrupts, monitoring, independent replications, warm-up, and reproducible output analysis.","https:\u002F\u002Fgithub.com\u002Flagzgabrielmuller-dot\u002Fkit-ingenieria-3d\u002Fblob\u002Fmain\u002Fplugins\u002Fciencia-y-calculo\u002Fskills\u002Fsimpy\u002FSKILL.md",[],[]]