شعار Gpu Drawing And Overlays

Gpu Drawing And Overlays

المجتمع
TMHSDigital
gpu-drawing-and-overlays

Draw viewport overlays and offscreen images with the gpu module instead of the removed bgl: SpaceView3D.draw_handler_add/remove symmetry, gpu.shader.from_builtin names, gpu_extras.batch.batch_for_shader, gpu.state for blending, depth and line width (POLYLINE shaders), blf text, tag_redraw, and GPUOffScreen with gpu.init() for --background on 5.2. Use when the user wants a viewport overlay, measurement readout, guide lines, debug visualization or an offscreen render from Python, or hits ModuleNotFoundError: No module named 'bgl' or 'GPU functions for drawing are not available in background mode'. Targets 5.2 LTS with 4.5 LTS fallback.

نظرة عامة

الناشرTMHSDigital
المستودعBlender-Developer-Tools
اسم المهارةgpu-drawing-and-overlays
النجوم
20
التفريعات
5
الملفات المرفقة
تعليمات فقط
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • مكتفية بذاتها

    كل ما يحتاجه النموذج موجود في التعليمات — لا ملفات إضافية لمزامنتها.

  • مفتوحة المصدر

    نشرها TMHSDigital على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Gpu Drawing And Overlays في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/TMHSDigital/Blender-Developer-Tools/tree/main/skills/gpu-drawing-and-overlays
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/TMHSDigital/Blender-Developer-Tools.git /tmp/Blender-Developer-Tools
mkdir -p .claude/skills
cp -r /tmp/Blender-Developer-Tools/skills/gpu-drawing-and-overlays .claude/skills/gpu-drawing-and-overlays
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Gpu Drawing And Overlays في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج مهارة Gpu Drawing And Overlays تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Gpu Drawing And Overlays بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

GPU Drawing and Overlays

Trigger

Use this skill when the user:

  • Wants to draw lines, points, shapes or text over the 3D viewport or an image editor from an add-on
  • Has add-on code with import bgl, bgl.glEnable, bgl.glLineWidth, or gets ModuleNotFoundError: No module named 'bgl' on 5.x
  • Wants to render something with the GPU into an image from a script, including headless
  • Sees SystemError: GPU functions for drawing are not available in background mode

bgl is gone

bgl wrapped raw OpenGL calls, which Blender's Metal and Vulkan backends cannot honour. It is deprecated on 4.5 LTS and removed in 5.x. Measured: importlib.util.find_spec('bgl') is None on 5.0.1, 5.1.2 and 5.2.1, and still present on 4.5.14. Code that imports it does not register on 5.x at all. Everything below uses gpu, gpu_extras and blf, which work on both 4.5 and 5.x, so no version branch is needed for drawing itself. The no-bgl rule flags leftovers.

The overlay pattern: register, draw, unregister

python
import bpy
import gpu
from gpu_extras.batch import batch_for_shader

_handle = None


def draw_guides():
    obj = bpy.context.active_object
    if obj is None:
        return
    shader = gpu.shader.from_builtin("POLYLINE_UNIFORM_COLOR")
    origin = obj.matrix_world.translation
    tip = origin + obj.matrix_world.to_3x3().col[2].normalized()
    batch = batch_for_shader(shader, "LINES", {"pos": [origin, tip]})
    region = bpy.context.region
    shader.uniform_float("viewportSize", (region.width, region.height))
    shader.uniform_float("lineWidth", 3.0)
    shader.uniform_float("color", (1.0, 0.6, 0.1, 0.9))
    gpu.state.blend_set("ALPHA")
    gpu.state.depth_test_set("LESS_EQUAL")
    batch.draw(shader)
    gpu.state.depth_test_set("NONE")
    gpu.state.blend_set("NONE")


def register():
    global _handle
    _handle = bpy.types.SpaceView3D.draw_handler_add(draw_guides, (), "WINDOW", "POST_VIEW")


def unregister():
    global _handle
    if _handle is not None:
        bpy.types.SpaceView3D.draw_handler_remove(_handle, "WINDOW")
        _handle = None
  • Keep the handle. draw_handler_add returns it; draw_handler_remove(handle, region_type) needs it. A handler added without storing the handle cannot be removed, and it keeps drawing after the add-on is disabled. On re-enable you get two.
  • Remove in unregister(), symmetric with register() (see addon-scaffolding).
  • args is a tuple passed to the callback: (self, context) from a modal operator, () for a module-level function.
  • Draw types. POST_VIEW draws in 3D world space under the view matrices (positions are world coordinates). POST_PIXEL draws in region pixels with an orthographic matrix (positions are (x, y) in pixels, origin bottom-left), which is where text and HUD panels go. PRE_VIEW draws under the scene.
  • The callback runs on every redraw of every 3D viewport. Keep it cheap: build batches from cached data, not by walking bpy.data. Guard context.active_object against None (see type-annotate-props-and-defend-context).
  • Nothing redraws by itself. After your data changes, call area.tag_redraw() for the areas that show it, for example from a timer or a depsgraph handler (see drivers-and-app-handlers, timers-modal-and-threading).
  • Copy-paste version: snippets/gpu-draw-handler.py is this pattern reduced to one fixed line.

Builtin shaders

gpu.shader.from_builtin(name) takes one of these names on both 4.5 LTS and 5.2:

NameAttributesUniforms
UNIFORM_COLORposcolor
FLAT_COLOR, SMOOTH_COLORpos, color—
IMAGEpos, texCoordimage
IMAGE_COLORpos, texCoordimage, color
POLYLINE_UNIFORM_COLORposviewportSize, lineWidth, color
POLYLINE_FLAT_COLOR, POLYLINE_SMOOTH_COLORpos, colorviewportSize, lineWidth
POINT_UNIFORM_COLORposcolor, size
POINT_FLAT_COLORpos, colorsize

5.2 adds IMAGE_SCENE_LINEAR_TO_REC709_SRGB and IMAGE_COLOR_SCENE_LINEAR_TO_REC709_SRGB for scene-linear images. The 2D_ / 3D_ prefixed names from 2.8–3.x (2D_UNIFORM_COLOR, 3D_SMOOTH_COLOR) are rejected on 5.2: ValueError: expected a string in ('FLAT_COLOR', 'IMAGE', ...). One shader handles 2D and 3D: pass 2-component or 3-component pos.

gpu.state replaces the bgl state calls

bglgpu
glEnable(GL_BLEND) / glDisable(GL_BLEND)gpu.state.blend_set('ALPHA') / blend_set('NONE')
glLineWidth(w)a POLYLINE_* shader's lineWidth and viewportSize uniforms
glPointSize(s)POINT_* shader size uniform, or gpu.state.point_size_set(s)
glEnable(GL_DEPTH_TEST), glDepthFuncgpu.state.depth_test_set('LESS_EQUAL'); 'NONE' to disable
glDepthMaskgpu.state.depth_mask_set(True)
glReadPixelsgpu.state.active_framebuffer_get().read_color(x, y, w, h, 4, 0, 'FLOAT')
bgl.Buffergpu.types.Buffer

Two traps:

  • Blending is off by default. Measured in examples/gpu-offscreen-draw: red at alpha 0.5 over opaque blue gives the mix (0.498, 0, 0.502) with blend_set('ALPHA'), and overwrites the target with (1, 0, 0, 0.498) without it. An overlay that "ignores alpha" is missing this call.
  • Wide lines need a POLYLINE_* shader. lineWidth 6 drew a 7 px line (one antialiased edge pixel); lineWidth 1 drew 2 px. gpu.state.line_width_set with a non-polyline shader depends on the backend, because core OpenGL, Metal and Vulkan do not guarantee wide-line rasterization. POLYLINE_* builds the width in geometry, so it looks the same everywhere. It needs viewportSize in pixels: (region.width, region.height) in a draw callback, or the offscreen size.

Restore every state you set before returning. Draw callbacks share GPU state with the rest of the editor, so a leftover blend_set('ALPHA') or depth test changes how the next overlay draws.

Text with blf

python
import blf

def draw_label():          # register with draw type "POST_PIXEL"
    font_id = 0            # the default UI font
    blf.size(font_id, 16)  # 4.0+: (fontid, size); the dpi argument is gone
    blf.color(font_id, 1.0, 1.0, 1.0, 1.0)
    blf.position(font_id, 20, 30, 0)   # region pixels, origin bottom-left
    blf.draw(font_id, "Edges: 128")

blf.size(font_id, size, dpi) from 3.x raises a TypeError on 4.0 and later. Measure text with blf.dimensions(font_id, text) before laying it out.

Offscreen: drawing into an image, also headless

python
import gpu
from gpu_extras.batch import batch_for_shader

if bpy.app.version >= (5, 2, 0):
    gpu.init()          # 5.2+: makes drawing available under --background

off = gpu.types.GPUOffScreen(256, 256)
try:
    with off.bind():
        fb = gpu.state.active_framebuffer_get()
        fb.clear(color=(0.0, 0.0, 0.0, 0.0))
        gpu.matrix.load_identity()          # NDC: -1..1 covers the image
        shader = gpu.shader.from_builtin("UNIFORM_COLOR")
        batch = batch_for_shader(shader, "TRI_FAN",
                                 {"pos": [(-0.5, -0.5), (0.5, -0.5), (0.5, 0.5), (-0.5, 0.5)]})
        shader.uniform_float("color", (1.0, 0.0, 0.0, 1.0))
        batch.draw(shader)
        buf = fb.read_color(0, 0, 256, 256, 4, 0, "FLOAT")
finally:
    off.free()
  • Headless drawing is new in 5.2. gpu.init() "initializes the GPU module for background use". On 5.1, 5.0 and 4.5 LTS there is no gpu.init, and any draw under --background raises SystemError: GPU functions for drawing are not available in background mode. On those versions, offscreen drawing works only in a session with a window.
  • Let go of GPU objects before exit. A 5.2.1 probe that called sys.exit at module level while its batch, shader and framebuffer were still referenced crashed Blender on shutdown (EXCEPTION_ACCESS_VIOLATION, exit 5). The same drawing done inside a function, so those references were gone on return, exited 0. Free the offscreen in a finally, and keep the GPU objects local.
  • To save the result as an image, copy buf into an Image's pixels with foreach_set (see use-foreach-set-for-bulk-data).
  • To draw the scene itself into an offscreen in a UI session, use off.draw_view3d(scene, view_layer, view3d, region, view_matrix, projection_matrix).

Common AI mistakes

MistakeConsequenceDo instead
import bglImport fails on 5.x; the add-on never registersgpu.state, POLYLINE_* shaders
from_builtin('3D_UNIFORM_COLOR')ValueError on 5.2UNIFORM_COLOR
Not storing the draw_handler_add handleOverlay keeps drawing after disable; doubles on re-enableStore it, remove it in unregister()
Expecting alpha without blend_setTransparent colours draw opaque-overgpu.state.blend_set('ALPHA'), then 'NONE'
line_width_set for thick linesThin lines on core-profile backendsPOLYLINE_* with lineWidth
blf.size(id, size, 72)TypeError on 4.0+blf.size(id, size)
Drawing under --background on 4.5 / 5.1SystemErrorRun with a window, or require 5.2 and call gpu.init()

Runnable examples

Each example runs headless, asserts the contract, and exits non-zero when it breaks. Run one with blender --background --python <script> --; pass a falsifier flag to watch the check fail.

  • gpu-offscreen-draw: Check-only witness for drawing with the gpu module, the replacement for the bgl module that 5.x removed. Blender 5.2+. Falsify: --skip-blend (exit 5).

Snippets

Short standalone patterns to copy. Each one runs in CI on 5.2 and 4.5 with a check and a falsifier.

References

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Gpu Drawing And Overlays؟

Draw viewport overlays and offscreen images with the gpu module instead of the removed bgl: SpaceView3D.draw_handler_add/remove symmetry, gpu.shader.from_builtin names, gpu_extras.batch.batch_for_shader, gpu.state for blending, depth and line width (POLYLINE shaders), blf text, tag_redraw, and GPUOffScreen with gpu.init() for --background on 5.2. Use when the user wants a viewport overlay, measurement readout, guide lines, debug visualization or an offscreen render from Python, or hits ModuleNotFoundError: No module named 'bgl' or 'GPU functions for drawing are not available in background m...

لماذا تستخدم Gpu Drawing And Overlays على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Gpu Drawing And Overlays عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Gpu Drawing And Overlays في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/TMHSDigital/Blender-Developer-Tools/tree/main/skills/gpu-drawing-and-overlays. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Gpu Drawing And Overlays؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Gpu Drawing And Overlays؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Gpu Drawing And Overlays معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Gpu Drawing And Overlays مجانية؟

نشرها TMHSDigital على GitHub. راجع المستودع للاطلاع على شروط الترخيص. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇