3.3 KiB
3.3 KiB
Custom Shaders and Window Frame Architecture
1. Shader Injection Strategy
Evaluation
- Dear PyGui (Legacy): Does not natively support raw GLSL/HLSL shader injection into the UI layer. It relies heavily on fixed-function vertex/fragment shaders compiled into the C++ core. Faux-shaders via DrawList are the only viable path without modifying the DPG source.
- imgui-bundle (Current):
imgui-bundleutilizeshello_imguias its application runner, which provides robust lifecycle callbacks (e.g.,callbacks.custom_background,callbacks.post_init). Becausehello_imguiexposes the underlying OpenGL context, we can usePyOpenGLalongside it to execute raw GLSL shaders.
Chosen Approach: Hybrid Faux-Shader & PyOpenGL FBO
Given the Python environment, we will adopt a hybrid approach:
- Faux-Shaders (ImDrawList Batching): Continue using
imgui.ImDrawListprimitives for simple effects like soft shadows, glows, and basic gradients (as seen insrc/shaders.py). This is highly performant for UI elements and requires no external dependencies. - True GPU Shaders (PyOpenGL + FBO): For complex post-processing (CRT curvature, bloom, dynamic noise backgrounds), we will integrate
PyOpenGL.- We will compile GLSL shaders during
post_init. - We will render the effect into a Framebuffer Object (FBO).
- We will display the resulting texture ID using
imgui.image()or inject it into thecustom_backgroundcallback.
- We will compile GLSL shaders during
Note: This approach introduces PyOpenGL as a dependency, which is standard for advanced Python graphics.
2. Custom Window Frame Strategy
Evaluation
- Native DWM Overloading (PyWin32): It is possible to use
pywin32to subclass the application window, interceptWM_NCHITTEST, and returnHTCAPTIONfor a custom ImGui-drawn title bar region. This preserves Windows snap layouts and native drop shadows. However, it is strictly Windows-only and can conflict with GLFW/SDL2 event loops used byhello_imgui. - Borderless Window Mode (ImGui/GLFW):
hello_imguiallows configuring the main window as borderless/undecorated (runner_params.app_window_params.borderless = True). We must then manually draw the title bar, minimize/maximize/close buttons, and handle window dragging by updating the OS window position based on ImGui mouse drag deltas.
Chosen Approach: Pure ImGui Borderless Implementation
To ensure cross-platform compatibility and avoid brittle Win32 hook collisions with hello_imgui, we will use the Borderless Window Mode approach.
- Initialization: Configure
hello_imgui.RunnerParamsto disable OS window decorations. - Title Bar Rendering: Dedicate the top ~30 pixels of the ImGui workspace to a custom title bar that matches the current theme (e.g., NERV or standard).
- Window Controls: Implement custom ImGui buttons for
_,[], andX, which will call native window management functions exposed byhello_imguiorglfw. - Drag Handling: Detect
imgui.is_mouse_dragging()on the title bar region and dynamically adjust the application window position.
3. Integration with Event Metrics
Both the shader uniforms (time, resolution) and window control events will be hooked into the existing dag_engine and events systems to ensure minimal performance overhead and centralized configuration via config.toml.