Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for draw list user callbacks in ImGui integration #84

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 28 additions & 17 deletions src/Magnum/ImGuiIntegration/Context.cpp
Expand Up @@ -318,23 +318,34 @@ void Context::drawFrame() {

for(std::int_fast32_t c = 0; c < cmdList->CmdBuffer.Size; ++c) {
const ImDrawCmd* pcmd = &cmdList->CmdBuffer[c];

GL::Renderer::setScissor(Range2Di{Range2D{
{pcmd->ClipRect.x, fbSize.y() - pcmd->ClipRect.w},
{pcmd->ClipRect.z, fbSize.y() - pcmd->ClipRect.y}}
.scaled(_supersamplingRatio)});

_mesh.setCount(pcmd->ElemCount);
_mesh.setIndexBuffer(_indexBuffer, indexBufferOffset*sizeof(ImDrawIdx),
sizeof(ImDrawIdx) == 2
? GL::MeshIndexType::UnsignedShort
: GL::MeshIndexType::UnsignedInt);

indexBufferOffset += pcmd->ElemCount;

_shader
.bindTexture(*static_cast<GL::Texture2D*>(pcmd->TextureId))
.draw(_mesh);
if (pcmd->UserCallback)
{
// 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. We do not have anything to do here though...
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
;
else
pcmd->UserCallback(cmdList, pcmd);
} else {
GL::Renderer::setScissor(Range2Di{Range2D{
{pcmd->ClipRect.x, fbSize.y() - pcmd->ClipRect.w},
{pcmd->ClipRect.z, fbSize.y() - pcmd->ClipRect.y}}
.scaled(_supersamplingRatio)});

_mesh.setCount(pcmd->ElemCount);
_mesh.setIndexBuffer(_indexBuffer, indexBufferOffset*sizeof(ImDrawIdx),
sizeof(ImDrawIdx) == 2
? GL::MeshIndexType::UnsignedShort
: GL::MeshIndexType::UnsignedInt);

indexBufferOffset += pcmd->ElemCount;

_shader
.bindTexture(*static_cast<GL::Texture2D*>(pcmd->TextureId))
.draw(_mesh);
}
}
}

Expand Down