Amend Vulkan code for formatting

omar 2022-11-15 11:10:00 +01:00
parent 504473bcaf
commit 0423015a24

@ -577,12 +577,8 @@ uint32_t findMemoryType(uint32_t type_filter, VkMemoryPropertyFlags properties)
vkGetPhysicalDeviceMemoryProperties(g_PhysicalDevice, &mem_properties); vkGetPhysicalDeviceMemoryProperties(g_PhysicalDevice, &mem_properties);
for (uint32_t i = 0; i < mem_properties.memoryTypeCount; i++) for (uint32_t i = 0; i < mem_properties.memoryTypeCount; i++)
{
if ((type_filter & (1 << i)) && (mem_properties.memoryTypes[i].propertyFlags & properties) == properties) if ((type_filter & (1 << i)) && (mem_properties.memoryTypes[i].propertyFlags & properties) == properties)
{
return i; return i;
}
}
return 0xFFFFFFFF; // Unable to find memoryType return 0xFFFFFFFF; // Unable to find memoryType
} }
@ -595,9 +591,7 @@ bool LoadTextureFromFile(const char* filename, MyTextureData* tex_data)
unsigned char* image_data = stbi_load(filename, &tex_data->Width, &tex_data->Height, 0, tex_data->Channels); unsigned char* image_data = stbi_load(filename, &tex_data->Width, &tex_data->Height, 0, tex_data->Channels);
if (image_data == NULL) if (image_data == NULL)
{
return false; return false;
}
// Calculate allocation size (in number of bytes) // Calculate allocation size (in number of bytes)
size_t image_size = tex_data->Width * tex_data->Height * tex_data->Channels; size_t image_size = tex_data->Width * tex_data->Height * tex_data->Channels;
@ -798,8 +792,8 @@ void RemoveTexture(MyTextureData* tex_data)
Load our texture after initializing Vulkan loader (for example after `ImGui_ImplVulkan_Init()`): Load our texture after initializing Vulkan loader (for example after `ImGui_ImplVulkan_Init()`):
```cpp ```cpp
MyTextureData my_image_texture; MyTextureData my_texture;
bool ret = LoadTextureFromFile("../../MyImage01.jpg", &my_image_texture); bool ret = LoadTextureFromFile("../../MyImage01.jpg", &my_texture);
IM_ASSERT(ret); IM_ASSERT(ret);
``` ```
@ -808,16 +802,16 @@ In the snippet of code above, we added an assert `IM_ASSERT(ret)` to check if th
Now that we have an Vulkan texture and its dimensions, we can display it in our main loop: Now that we have an Vulkan texture and its dimensions, we can display it in our main loop:
```cpp ```cpp
ImGui::Begin("Vulkan Texture Text"); ImGui::Begin("Vulkan Texture Text");
ImGui::Text("pointer = %p", my_image_texture.DS); ImGui::Text("pointer = %p", my_texture.DS);
ImGui::Text("size = %d x %d", my_image_texture.Width, my_image_texture.Height); ImGui::Text("size = %d x %d", my_texture.Width, my_texture.Height);
ImGui::Image((ImTextureID)my_image_texture.DS, ImVec2(my_image_texture.Width, my_image_texture.Height)); ImGui::Image((ImTextureID)my_texture.DS, ImVec2(my_texture.Width, my_texture.Height));
ImGui::End(); ImGui::End();
``` ```
In the cleanup stage remember to call the RemoveTexture function to avoid leaks, and angry Vulkan Validation Layers! Call it before `ImGui_ImplVulkan_Shutdown()` In the cleanup stage remember to call the RemoveTexture function to avoid leaks, and angry Vulkan Validation Layers! Call it before `ImGui_ImplVulkan_Shutdown()`
```cpp ```cpp
RemoveTexture(&my_image_texture); RemoveTexture(&my_texture);
``` ```