Optimized UI overlay strategy
This commit is contained in:
parent
73dbdfcbda
commit
e9c4cd4a0b
3 changed files with 33 additions and 12 deletions
|
|
@ -35,7 +35,15 @@ namespace vks
|
||||||
style.Colors[ImGuiCol_Header] = ImVec4(0.8f, 0.0f, 0.0f, 0.4f);
|
style.Colors[ImGuiCol_Header] = ImVec4(0.8f, 0.0f, 0.0f, 0.4f);
|
||||||
style.Colors[ImGuiCol_HeaderActive] = ImVec4(1.0f, 0.0f, 0.0f, 0.4f);
|
style.Colors[ImGuiCol_HeaderActive] = ImVec4(1.0f, 0.0f, 0.0f, 0.4f);
|
||||||
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(1.0f, 0.0f, 0.0f, 0.4f);
|
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(1.0f, 0.0f, 0.0f, 0.4f);
|
||||||
|
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.8f);
|
||||||
style.Colors[ImGuiCol_CheckMark] = ImVec4(1.0f, 0.0f, 0.0f, 0.8f);
|
style.Colors[ImGuiCol_CheckMark] = ImVec4(1.0f, 0.0f, 0.0f, 0.8f);
|
||||||
|
style.Colors[ImGuiCol_SliderGrab] = ImVec4(1.0f, 0.0f, 0.0f, 0.4f);
|
||||||
|
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(1.0f, 0.0f, 0.0f, 0.8f);
|
||||||
|
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.1f);
|
||||||
|
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.2f);
|
||||||
|
style.Colors[ImGuiCol_Button] = ImVec4(1.0f, 0.0f, 0.0f, 0.4f);
|
||||||
|
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(1.0f, 0.0f, 0.0f, 0.6f);
|
||||||
|
style.Colors[ImGuiCol_ButtonActive] = ImVec4(1.0f, 0.0f, 0.0f, 0.8f);
|
||||||
// Dimensions
|
// Dimensions
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.FontGlobalScale = scale;
|
io.FontGlobalScale = scale;
|
||||||
|
|
@ -334,13 +342,13 @@ namespace vks
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||||
|
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, NULL);
|
||||||
|
|
||||||
pushConstBlock.scale = glm::vec2(2.0f / io.DisplaySize.x, 2.0f / io.DisplaySize.y);
|
pushConstBlock.scale = glm::vec2(2.0f / io.DisplaySize.x, 2.0f / io.DisplaySize.y);
|
||||||
pushConstBlock.translate = glm::vec2(-1.0f);
|
pushConstBlock.translate = glm::vec2(-1.0f);
|
||||||
vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(PushConstBlock), &pushConstBlock);
|
vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(PushConstBlock), &pushConstBlock);
|
||||||
|
|
||||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
|
||||||
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, NULL);
|
|
||||||
|
|
||||||
VkDeviceSize offsets[1] = { 0 };
|
VkDeviceSize offsets[1] = { 0 };
|
||||||
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &vertexBuffer.buffer, offsets);
|
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &vertexBuffer.buffer, offsets);
|
||||||
vkCmdBindIndexBuffer(commandBuffer, indexBuffer.buffer, 0, VK_INDEX_TYPE_UINT16);
|
vkCmdBindIndexBuffer(commandBuffer, indexBuffer.buffer, 0, VK_INDEX_TYPE_UINT16);
|
||||||
|
|
@ -392,7 +400,9 @@ namespace vks
|
||||||
|
|
||||||
bool UIOverlay::checkBox(const char *caption, bool *value)
|
bool UIOverlay::checkBox(const char *caption, bool *value)
|
||||||
{
|
{
|
||||||
return ImGui::Checkbox(caption, value);
|
bool res = ImGui::Checkbox(caption, value);
|
||||||
|
if (res) { updated = true; };
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UIOverlay::checkBox(const char *caption, int32_t *value)
|
bool UIOverlay::checkBox(const char *caption, int32_t *value)
|
||||||
|
|
@ -400,22 +410,29 @@ namespace vks
|
||||||
bool val = (*value == 1);
|
bool val = (*value == 1);
|
||||||
bool res = ImGui::Checkbox(caption, &val);
|
bool res = ImGui::Checkbox(caption, &val);
|
||||||
*value = val;
|
*value = val;
|
||||||
|
if (res) { updated = true; };
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UIOverlay::inputFloat(const char *caption, float *value, float step, uint32_t precision)
|
bool UIOverlay::inputFloat(const char *caption, float *value, float step, uint32_t precision)
|
||||||
{
|
{
|
||||||
return ImGui::InputFloat(caption, value, step, step * 10.0f, precision);
|
bool res = ImGui::InputFloat(caption, value, step, step * 10.0f, precision);
|
||||||
|
if (res) { updated = true; };
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UIOverlay::sliderFloat(const char* caption, float* value, float min, float max)
|
bool UIOverlay::sliderFloat(const char* caption, float* value, float min, float max)
|
||||||
{
|
{
|
||||||
return ImGui::SliderFloat(caption, value, min, max);
|
bool res = ImGui::SliderFloat(caption, value, min, max);
|
||||||
|
if (res) { updated = true; };
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UIOverlay::sliderInt(const char* caption, int32_t* value, int32_t min, int32_t max)
|
bool UIOverlay::sliderInt(const char* caption, int32_t* value, int32_t min, int32_t max)
|
||||||
{
|
{
|
||||||
return ImGui::SliderInt(caption, value, min, max);
|
bool res = ImGui::SliderInt(caption, value, min, max);
|
||||||
|
if (res) { updated = true; };
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UIOverlay::comboBox(const char *caption, int32_t *itemindex, std::vector<std::string> items)
|
bool UIOverlay::comboBox(const char *caption, int32_t *itemindex, std::vector<std::string> items)
|
||||||
|
|
@ -429,12 +446,16 @@ namespace vks
|
||||||
charitems.push_back(items[i].c_str());
|
charitems.push_back(items[i].c_str());
|
||||||
}
|
}
|
||||||
uint32_t itemCount = static_cast<uint32_t>(charitems.size());
|
uint32_t itemCount = static_cast<uint32_t>(charitems.size());
|
||||||
return ImGui::Combo(caption, itemindex, &charitems[0], itemCount, itemCount);
|
bool res = ImGui::Combo(caption, itemindex, &charitems[0], itemCount, itemCount);
|
||||||
|
if (res) { updated = true; };
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UIOverlay::button(const char *caption)
|
bool UIOverlay::button(const char *caption)
|
||||||
{
|
{
|
||||||
return ImGui::Button(caption);
|
bool res = ImGui::Button(caption);
|
||||||
|
if (res) { updated = true; };
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIOverlay::text(const char *formatstr, ...)
|
void UIOverlay::text(const char *formatstr, ...)
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ namespace vks
|
||||||
} pushConstBlock;
|
} pushConstBlock;
|
||||||
|
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
|
bool updated = false;
|
||||||
float scale = 1.0f;
|
float scale = 1.0f;
|
||||||
|
|
||||||
UIOverlay();
|
UIOverlay();
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,6 @@ void VulkanExampleBase::prepare()
|
||||||
};
|
};
|
||||||
UIOverlay.prepareResources();
|
UIOverlay.prepareResources();
|
||||||
UIOverlay.preparePipeline(pipelineCache, renderPass);
|
UIOverlay.preparePipeline(pipelineCache, renderPass);
|
||||||
updateOverlay();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -592,8 +591,9 @@ void VulkanExampleBase::updateOverlay()
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
||||||
if (UIOverlay.update()) {
|
if (UIOverlay.update() || UIOverlay.updated) {
|
||||||
buildCommandBuffers();
|
buildCommandBuffers();
|
||||||
|
UIOverlay.updated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||||
|
|
@ -606,7 +606,6 @@ void VulkanExampleBase::updateOverlay()
|
||||||
void VulkanExampleBase::drawUI(const VkCommandBuffer commandBuffer)
|
void VulkanExampleBase::drawUI(const VkCommandBuffer commandBuffer)
|
||||||
{
|
{
|
||||||
if (settings.overlay) {
|
if (settings.overlay) {
|
||||||
|
|
||||||
const VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f);
|
const VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f);
|
||||||
const VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0);
|
const VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0);
|
||||||
vkCmdSetViewport(commandBuffer, 0, 1, &viewport);
|
vkCmdSetViewport(commandBuffer, 0, 1, &viewport);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue