ImGui example now shows Vulkan API and driver info, ImGui+TextOverlay+ConditionalRender+gltfSceneRendering examples now support macOS retina displays
This commit is contained in:
parent
bb4281ac24
commit
d9d3e8c1fb
5 changed files with 52 additions and 19 deletions
|
|
@ -79,12 +79,14 @@ namespace vks
|
|||
#else
|
||||
const std::string filename = getAssetPath() + "Roboto-Medium.ttf";
|
||||
io.Fonts->AddFontFromFileTTF(filename.c_str(), 16.0f * scale);
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
style.ScaleAllSizes(scale);
|
||||
#endif
|
||||
io.Fonts->GetTexDataAsRGBA32(&fontData, &texWidth, &texHeight);
|
||||
VkDeviceSize uploadSize = texWidth*texHeight * 4 * sizeof(char);
|
||||
|
||||
//SRS - Set ImGui style scale factor to handle retina and other HiDPI displays (same as font scaling above)
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
style.ScaleAllSizes(scale);
|
||||
|
||||
// Create target image for copy
|
||||
VkImageCreateInfo imageInfo = vks::initializers::imageCreateInfo();
|
||||
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||
|
|
@ -324,7 +326,6 @@ namespace vks
|
|||
}
|
||||
|
||||
// Index buffer
|
||||
VkDeviceSize indexSize = imDrawData->TotalIdxCount * sizeof(ImDrawIdx);
|
||||
if ((indexBuffer.buffer == VK_NULL_HANDLE) || (indexCount < imDrawData->TotalIdxCount)) {
|
||||
indexBuffer.unmap();
|
||||
indexBuffer.destroy();
|
||||
|
|
|
|||
|
|
@ -354,7 +354,7 @@ public:
|
|||
}
|
||||
ImGui::NewLine();
|
||||
|
||||
ImGui::BeginChild("InnerRegion", ImVec2(200.0f, 400.0f), false);
|
||||
ImGui::BeginChild("InnerRegion", ImVec2(200.0f * overlay->scale, 400.0f * overlay->scale), false);
|
||||
for (auto node : scene.linearNodes) {
|
||||
// Add visibility toggle checkboxes for all model nodes with a mesh
|
||||
if (node->mesh) {
|
||||
|
|
@ -370,4 +370,4 @@ public:
|
|||
|
||||
};
|
||||
|
||||
VULKAN_EXAMPLE_MAIN()
|
||||
VULKAN_EXAMPLE_MAIN()
|
||||
|
|
|
|||
|
|
@ -652,7 +652,7 @@ void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay)
|
|||
ImGui::NewLine();
|
||||
|
||||
// POI: Create a list of glTF nodes for visibility toggle
|
||||
ImGui::BeginChild("#nodelist", ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() * (glTFScene.nodes.size() + 4)), false);
|
||||
ImGui::BeginChild("#nodelist", ImVec2(200.0f * overlay->scale, 340.0f * overlay->scale), false);
|
||||
for (auto &node : glTFScene.nodes)
|
||||
{
|
||||
if (overlay->checkBox(node.name.c_str(), &node.visible))
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ private:
|
|||
VkDescriptorSetLayout descriptorSetLayout;
|
||||
VkDescriptorSet descriptorSet;
|
||||
vks::VulkanDevice *device;
|
||||
VkPhysicalDeviceDriverProperties driverProperties = {};
|
||||
VulkanExampleBase *example;
|
||||
public:
|
||||
// UI params are set via push constants
|
||||
|
|
@ -57,6 +58,12 @@ public:
|
|||
{
|
||||
device = example->vulkanDevice;
|
||||
ImGui::CreateContext();
|
||||
|
||||
//SRS - Set ImGui font and style scale factors to handle retina and other HiDPI displays
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.FontGlobalScale = example->UIOverlay.scale;
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
style.ScaleAllSizes(example->UIOverlay.scale);
|
||||
};
|
||||
|
||||
~ImGUI()
|
||||
|
|
@ -103,6 +110,16 @@ public:
|
|||
io.Fonts->GetTexDataAsRGBA32(&fontData, &texWidth, &texHeight);
|
||||
VkDeviceSize uploadSize = texWidth*texHeight * 4 * sizeof(char);
|
||||
|
||||
//SRS - Get Vulkan device driver information if available, use later for display
|
||||
if (device->extensionSupported(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME))
|
||||
{
|
||||
VkPhysicalDeviceProperties2 deviceProperties2 = {};
|
||||
deviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
|
||||
deviceProperties2.pNext = &driverProperties;
|
||||
driverProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
|
||||
vkGetPhysicalDeviceProperties2(device->physicalDevice, &deviceProperties2);
|
||||
}
|
||||
|
||||
// Create target image for copy
|
||||
VkImageCreateInfo imageInfo = vks::initializers::imageCreateInfo();
|
||||
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||
|
|
@ -325,10 +342,15 @@ public:
|
|||
|
||||
// Init imGui windows and elements
|
||||
|
||||
ImVec4 clear_color = ImColor(114, 144, 154);
|
||||
static float f = 0.0f;
|
||||
// SRS - Set initial position of default Debug window (note: Debug window sets its own initial size, use ImGuiSetCond_Always to override)
|
||||
ImGui::SetWindowPos(ImVec2(20 * example->UIOverlay.scale, 20 * example->UIOverlay.scale), ImGuiSetCond_FirstUseEver);
|
||||
ImGui::SetWindowSize(ImVec2(300 * example->UIOverlay.scale, 300 * example->UIOverlay.scale), ImGuiSetCond_Always);
|
||||
ImGui::TextUnformatted(example->title.c_str());
|
||||
ImGui::TextUnformatted(device->properties.deviceName);
|
||||
|
||||
//SRS - Display Vulkan API version and device driver information if available (otherwise blank)
|
||||
ImGui::Text("Vulkan API %i.%i.%i", VK_API_VERSION_MAJOR(device->properties.apiVersion), VK_API_VERSION_MINOR(device->properties.apiVersion), VK_API_VERSION_PATCH(device->properties.apiVersion));
|
||||
ImGui::Text("%s %s", driverProperties.driverName, driverProperties.driverInfo);
|
||||
|
||||
// Update frame time display
|
||||
if (updateFrameGraph) {
|
||||
|
|
@ -349,7 +371,9 @@ public:
|
|||
ImGui::InputFloat3("position", &example->camera.position.x, 2);
|
||||
ImGui::InputFloat3("rotation", &example->camera.rotation.x, 2);
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(200, 200), ImGuiSetCond_FirstUseEver);
|
||||
// SRS - Set initial position and size of Example settings window
|
||||
ImGui::SetNextWindowPos(ImVec2(20 * example->UIOverlay.scale, 360 * example->UIOverlay.scale), ImGuiSetCond_FirstUseEver);
|
||||
ImGui::SetNextWindowSize(ImVec2(300 * example->UIOverlay.scale, 200 * example->UIOverlay.scale), ImGuiSetCond_FirstUseEver);
|
||||
ImGui::Begin("Example settings");
|
||||
ImGui::Checkbox("Render models", &uiSettings.displayModels);
|
||||
ImGui::Checkbox("Display logos", &uiSettings.displayLogos);
|
||||
|
|
@ -358,7 +382,7 @@ public:
|
|||
ImGui::SliderFloat("Light speed", &uiSettings.lightSpeed, 0.1f, 1.0f);
|
||||
ImGui::End();
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
|
||||
//SRS - ShowDemoWindow() sets its own initial position and size, cannot override here
|
||||
ImGui::ShowDemoWindow();
|
||||
|
||||
// Render to generate draw buffers
|
||||
|
|
@ -499,6 +523,10 @@ public:
|
|||
camera.setPosition(glm::vec3(0.0f, 0.0f, -4.8f));
|
||||
camera.setRotation(glm::vec3(4.5f, -380.0f, 0.0f));
|
||||
camera.setPerspective(45.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||
|
||||
//SRS - Enable VK_KHR_get_physical_device_properties2 to retrieve device driver information for display
|
||||
enabledInstanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
|
||||
|
||||
// Don't use the ImGui overlay of the base framework in this sample
|
||||
settings.overlay = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ private:
|
|||
|
||||
uint32_t *frameBufferWidth;
|
||||
uint32_t *frameBufferHeight;
|
||||
float scale;
|
||||
|
||||
VkSampler sampler;
|
||||
VkImage image;
|
||||
|
|
@ -70,6 +71,7 @@ public:
|
|||
VkFormat depthformat,
|
||||
uint32_t *framebufferwidth,
|
||||
uint32_t *framebufferheight,
|
||||
float scale,
|
||||
std::vector<VkPipelineShaderStageCreateInfo> shaderstages)
|
||||
{
|
||||
this->vulkanDevice = vulkanDevice;
|
||||
|
|
@ -87,6 +89,7 @@ public:
|
|||
|
||||
this->frameBufferWidth = framebufferwidth;
|
||||
this->frameBufferHeight = framebufferheight;
|
||||
this->scale = scale;
|
||||
|
||||
cmdBuffers.resize(framebuffers.size());
|
||||
prepareResources();
|
||||
|
|
@ -490,8 +493,8 @@ public:
|
|||
|
||||
assert(mapped != nullptr);
|
||||
|
||||
const float charW = 1.5f / *frameBufferWidth;
|
||||
const float charH = 1.5f / *frameBufferHeight;
|
||||
const float charW = 1.5f * scale / *frameBufferWidth;
|
||||
const float charH = 1.5f * scale / *frameBufferHeight;
|
||||
|
||||
float fbW = (float)*frameBufferWidth;
|
||||
float fbH = (float)*frameBufferHeight;
|
||||
|
|
@ -700,23 +703,23 @@ public:
|
|||
{
|
||||
textOverlay->beginTextUpdate();
|
||||
|
||||
textOverlay->addText(title, 5.0f, 5.0f, TextOverlay::alignLeft);
|
||||
textOverlay->addText(title, 5.0f * UIOverlay.scale, 5.0f * UIOverlay.scale, TextOverlay::alignLeft);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << std::fixed << std::setprecision(2) << (frameTimer * 1000.0f) << "ms (" << lastFPS << " fps)";
|
||||
textOverlay->addText(ss.str(), 5.0f, 25.0f, TextOverlay::alignLeft);
|
||||
textOverlay->addText(ss.str(), 5.0f * UIOverlay.scale, 25.0f * UIOverlay.scale, TextOverlay::alignLeft);
|
||||
|
||||
textOverlay->addText(deviceProperties.deviceName, 5.0f, 45.0f, TextOverlay::alignLeft);
|
||||
textOverlay->addText(deviceProperties.deviceName, 5.0f * UIOverlay.scale, 45.0f * UIOverlay.scale, TextOverlay::alignLeft);
|
||||
|
||||
// Display current model view matrix
|
||||
textOverlay->addText("model view matrix", (float)width, 5.0f, TextOverlay::alignRight);
|
||||
textOverlay->addText("model view matrix", (float)width - 5.0f * UIOverlay.scale, 5.0f * UIOverlay.scale, TextOverlay::alignRight);
|
||||
|
||||
for (uint32_t i = 0; i < 4; i++)
|
||||
{
|
||||
ss.str("");
|
||||
ss << std::fixed << std::setprecision(2) << std::showpos;
|
||||
ss << uboVS.modelView[0][i] << " " << uboVS.modelView[1][i] << " " << uboVS.modelView[2][i] << " " << uboVS.modelView[3][i];
|
||||
textOverlay->addText(ss.str(), (float)width, 25.0f + (float)i * 20.0f, TextOverlay::alignRight);
|
||||
textOverlay->addText(ss.str(), (float)width - 5.0f * UIOverlay.scale, (25.0f + (float)i * 20.0f) * UIOverlay.scale, TextOverlay::alignRight);
|
||||
}
|
||||
|
||||
glm::vec3 projected = glm::project(glm::vec3(0.0f), uboVS.modelView, uboVS.projection, glm::vec4(0, 0, (float)width, (float)height));
|
||||
|
|
@ -724,8 +727,8 @@ public:
|
|||
|
||||
#if defined(__ANDROID__)
|
||||
#else
|
||||
textOverlay->addText("Press \"space\" to toggle text overlay", 5.0f, 65.0f, TextOverlay::alignLeft);
|
||||
textOverlay->addText("Hold middle mouse button and drag to move", 5.0f, 85.0f, TextOverlay::alignLeft);
|
||||
textOverlay->addText("Press \"space\" to toggle text overlay", 5.0f * UIOverlay.scale, 65.0f * UIOverlay.scale, TextOverlay::alignLeft);
|
||||
textOverlay->addText("Hold middle mouse button and drag to move", 5.0f * UIOverlay.scale, 85.0f * UIOverlay.scale, TextOverlay::alignLeft);
|
||||
#endif
|
||||
textOverlay->endTextUpdate();
|
||||
}
|
||||
|
|
@ -842,6 +845,7 @@ public:
|
|||
depthFormat,
|
||||
&width,
|
||||
&height,
|
||||
UIOverlay.scale,
|
||||
shaderStages
|
||||
);
|
||||
updateTextOverlay();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue