question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UserCallback bindings

See original GitHub issue

How are you handling situations when the render state changes, in vulkan they are using a callback function. Is it possible for you to quickly add this binding to your native library?

`    // Render command lists
    // (Because we merged all buffers into a single one, we maintain our own offset into them)
    int global_vtx_offset = 0;
    int global_idx_offset = 0;
    for (int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList* cmd_list = draw_data->CmdLists[n];
        for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
        {
            const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
            if (pcmd->UserCallback != NULL)
            {
                // User callback, registered via ImDrawList::AddCallback()
                // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
                if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
                    ImGui_ImplVulkan_SetupRenderState(draw_data, command_buffer, rb, fb_width, fb_height);
                else
                    pcmd->UserCallback(cmd_list, pcmd);
            }
            else
            {
                // Project scissor/clipping rectangles into framebuffer space
                ImVec4 clip_rect;
                clip_rect.x = (pcmd->ClipRect.x - clip_off.x) * clip_scale.x;
                clip_rect.y = (pcmd->ClipRect.y - clip_off.y) * clip_scale.y;
                clip_rect.z = (pcmd->ClipRect.z - clip_off.x) * clip_scale.x;
                clip_rect.w = (pcmd->ClipRect.w - clip_off.y) * clip_scale.y;

                if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
                {
                    // Negative offsets are illegal for vkCmdSetScissor
                    if (clip_rect.x < 0.0f)
                        clip_rect.x = 0.0f;
                    if (clip_rect.y < 0.0f)
                        clip_rect.y = 0.0f;

                    // Apply scissor/clipping rectangle
                    VkRect2D scissor;
                    scissor.offset.x = (int32_t)(clip_rect.x);
                    scissor.offset.y = (int32_t)(clip_rect.y);
                    scissor.extent.width = (uint32_t)(clip_rect.z - clip_rect.x);
                    scissor.extent.height = (uint32_t)(clip_rect.w - clip_rect.y);
                    vkCmdSetScissor(command_buffer, 0, 1, &scissor);

                    // Draw
                    vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
                }
            }
        }
        global_idx_offset += cmd_list->IdxBuffer.Size;
        global_vtx_offset += cmd_list->VtxBuffer.Size;
    }`

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
calvertdwcommented, Feb 12, 2021

I got rendering to the ImGui window working via a framebuffer texture.

0reactions
gviznyukcommented, Feb 12, 2021

Awesome, thanks! Greetings,

Thanks, Georgii

On Thu, Feb 11, 2021 at 8:13 PM Duncan Calvert notifications@github.com wrote:

I got rendering to the ImGui window working via a framebuffer texture.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/SpaiR/imgui-java/issues/11#issuecomment-777901916, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI7CU3U7ZUVIHOUKQEZZMATS6R6CDANCNFSM4OFWWATA .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Your Guide to React.useCallback() - Dmitri Pavlutin
A functional component wrapped inside React.memo() accepts a function object prop; When the function object is a dependency to other hooks, e.g. ...
Read more >
Examples: Metal: Restore state after UserCallback by bear24rw ...
In Metal there doesn't seem to be a way for a UserCallback to save the existing state before changing it so we should...
Read more >
User Callback - Libwebsockets
The protocol callback is the primary way lws interacts with user code. For one of a list of a few dozen reasons the...
Read more >
C++ Binding Issues - MPI Forum
User callback functions that return integer error codes should not throw exceptions; ... The C++ bindings presented in Annex MPI-1 C++ Language Binding...
Read more >
C Bindings: Callbacks - Crystal - W3cubDocs
Callbacks. You can use function types in C declarations: lib X # In C: # # void callback(int (*f)(int)); fun callback(f : Int32...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found