Amend Vulkan code for formatting
parent
504473bcaf
commit
0423015a24
@ -577,12 +577,8 @@ uint32_t findMemoryType(uint32_t type_filter, VkMemoryPropertyFlags properties)
|
||||
vkGetPhysicalDeviceMemoryProperties(g_PhysicalDevice, &mem_properties);
|
||||
|
||||
for (uint32_t i = 0; i < mem_properties.memoryTypeCount; i++)
|
||||
{
|
||||
if ((type_filter & (1 << i)) && (mem_properties.memoryTypes[i].propertyFlags & properties) == properties)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 0xFFFFFFFF; // Unable to find memoryType
|
||||
}
|
||||
@ -595,12 +591,10 @@ 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);
|
||||
|
||||
if (image_data == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
VkResult err;
|
||||
|
||||
@ -798,8 +792,8 @@ void RemoveTexture(MyTextureData* tex_data)
|
||||
|
||||
Load our texture after initializing Vulkan loader (for example after `ImGui_ImplVulkan_Init()`):
|
||||
```cpp
|
||||
MyTextureData my_image_texture;
|
||||
bool ret = LoadTextureFromFile("../../MyImage01.jpg", &my_image_texture);
|
||||
MyTextureData my_texture;
|
||||
bool ret = LoadTextureFromFile("../../MyImage01.jpg", &my_texture);
|
||||
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:
|
||||
```cpp
|
||||
ImGui::Begin("Vulkan Texture Text");
|
||||
ImGui::Text("pointer = %p", my_image_texture.DS);
|
||||
ImGui::Text("size = %d x %d", my_image_texture.Width, my_image_texture.Height);
|
||||
ImGui::Image((ImTextureID)my_image_texture.DS, ImVec2(my_image_texture.Width, my_image_texture.Height));
|
||||
ImGui::Text("pointer = %p", my_texture.DS);
|
||||
ImGui::Text("size = %d x %d", my_texture.Width, my_texture.Height);
|
||||
ImGui::Image((ImTextureID)my_texture.DS, ImVec2(my_texture.Width, my_texture.Height));
|
||||
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()`
|
||||
|
||||
```cpp
|
||||
RemoveTexture(&my_image_texture);
|
||||
RemoveTexture(&my_texture);
|
||||
```
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user