-
-
Notifications
You must be signed in to change notification settings - Fork 12k
Vulkan: Viewport and Scissor offset #9327
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
Changes from 4 commits
1364672
f910a45
d5d44d4
3788371
a5ff838
9c74896
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -495,28 +495,28 @@ static void ImGui_ImplVulkan_SetupRenderState(ImDrawData* draw_data, VkPipeline | |
| } | ||
|
|
||
| // Setup viewport: | ||
| { | ||
| VkViewport viewport; | ||
| viewport.x = 0; | ||
| viewport.y = 0; | ||
| viewport.width = (float)fb_width; | ||
| viewport.height = (float)fb_height; | ||
| viewport.minDepth = 0.0f; | ||
| viewport.maxDepth = 1.0f; | ||
| vkCmdSetViewport(command_buffer, 0, 1, &viewport); | ||
| } | ||
|
|
||
| VkViewport viewport; | ||
| viewport.x = draw_data->OwnerViewport->Pos.x; | ||
| viewport.y = draw_data->OwnerViewport->Pos.y; | ||
| viewport.width = (float)fb_width; | ||
| viewport.height = (float)fb_height; | ||
| viewport.minDepth = 0.0f; | ||
| viewport.maxDepth = 1.0f; | ||
| vkCmdSetViewport(command_buffer, 0, 1, &viewport); | ||
|
|
||
|
|
||
| // Setup scale and translation: | ||
| // Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps. | ||
| { | ||
| float scale[2]; | ||
| scale[0] = 2.0f / draw_data->DisplaySize.x; | ||
| scale[1] = 2.0f / draw_data->DisplaySize.y; | ||
| float translate[2]; | ||
| translate[0] = -1.0f - draw_data->DisplayPos.x * scale[0]; | ||
| translate[1] = -1.0f - draw_data->DisplayPos.y * scale[1]; | ||
| vkCmdPushConstants(command_buffer, bd->PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 0, sizeof(float) * 2, scale); | ||
| vkCmdPushConstants(command_buffer, bd->PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 2, sizeof(float) * 2, translate); | ||
| float scale_translate[4]; | ||
| //first two are scale | ||
| scale_translate[0] = 2.0f / draw_data->DisplaySize.x; | ||
| scale_translate[1] = 2.0f / draw_data->DisplaySize.y; | ||
| //second two are translate | ||
| scale_translate[2] = -1.0f - draw_data->DisplayPos.x * scale_translate[0]; | ||
| scale_translate[3] = -1.0f - draw_data->DisplayPos.y * scale_translate[1]; | ||
| vkCmdPushConstants(command_buffer, bd->PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float) * 4, scale_translate); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -629,23 +629,21 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm | |
| else | ||
| { | ||
| // Project scissor/clipping rectangles into framebuffer space | ||
| ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y); | ||
| ImVec2 clip_min(pcmd->ClipRect.x * clip_scale.x, pcmd->ClipRect.y * clip_scale.y); | ||
| ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); | ||
|
|
||
| // Clamp to viewport as vkCmdSetScissor() won't accept values that are off bounds | ||
| if (clip_min.x < 0.0f) { clip_min.x = 0.0f; } | ||
| if (clip_min.y < 0.0f) { clip_min.y = 0.0f; } | ||
| if (clip_max.x > fb_width) { clip_max.x = (float)fb_width; } | ||
| if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; } | ||
| if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are acceptable values, as seen immediately below at line 645, scissor is a position and size, as opposed to a min and max. |
||
| continue; | ||
|
|
||
| // Apply scissor/clipping rectangle | ||
| VkRect2D scissor; | ||
| scissor.offset.x = (int32_t)(clip_min.x); | ||
| scissor.offset.y = (int32_t)(clip_min.y); | ||
| scissor.extent.width = (uint32_t)(clip_max.x - clip_min.x); | ||
| scissor.extent.height = (uint32_t)(clip_max.y - clip_min.y); | ||
| scissor.extent.width = uint32_t(clip_max.x); | ||
| scissor.extent.height = uint32_t(clip_max.y); | ||
| vkCmdSetScissor(command_buffer, 0, 1, &scissor); | ||
|
|
||
| // Bind DescriptorSet with font or user texture | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15816,7 +15816,6 @@ static void ImGui::UpdateViewportsNewFrame() | |
| // FIXME-VIEWPORT: Size is driven by backend/user code for backward-compatibility but we should aim to make this more consistent. | ||
| ImGuiViewportP* main_viewport = g.Viewports[0]; | ||
| main_viewport->Flags = ImGuiViewportFlags_IsPlatformWindow | ImGuiViewportFlags_OwnedByApp; | ||
| main_viewport->Pos = ImVec2(0.0f, 0.0f); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously, this was a wasted instruction as |
||
| main_viewport->Size = g.IO.DisplaySize; | ||
| main_viewport->FramebufferScale = g.IO.DisplayFramebufferScale; | ||
| IM_ASSERT(main_viewport->FramebufferScale.x > 0.0f && main_viewport->FramebufferScale.y > 0.0f); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this double applied the offset, and cut pixels (fragments?) from the right when they were supposed to be removed from the left.