StudioCherno / Walnut

Walnut is a simple application framework for Vulkan and Dear ImGui apps
MIT License
2.06k stars 378 forks source link

Image Resize makes images invisible #24

Open ZanzyTHEbar opened 2 years ago

ZanzyTHEbar commented 2 years ago

I am loving Walnut - create application framework.

I've run into an issue where when i try to resize an image, using the built-in method, my images are invisible - but rendered.I know that are rendered as my screen scales relative to the image as if it were there - but i see no image. Very odd.

This is the error:

[vulkan] Debug report from ObjectType: 6
Message: Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x2138b368f40, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x4dae5635 | vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer 0x2138b368f40[] expects VkImage 0x3fbcd60000000028[] (subresource: aspectMask 0x1 array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL--instead, current layout is VK_IMAGE_LAYOUT_UNDEFINED.

I am using the resize method like so in the OnAttach() method.

m_Image->Resize(64, 64);
x1nixmzeng commented 2 years ago

Not the author, but this framework is to wrap ImGui functionality - you can draw an image at a smaller size without needing to resize the underlying data:

ImGui::Image((GLuint*)textureID, ImVec2(image_size,image_size));

Also worth pointing out that the implementation of Resize doesn't setup any data like the constructors do:

https://github.com/TheCherno/Walnut/blob/cc26ee1cc875db50884fe244e0a3195dd730a1ef/Walnut/src/Walnut/Image.cpp#L287-L288

https://github.com/TheCherno/Walnut/blob/cc26ee1cc875db50884fe244e0a3195dd730a1ef/Walnut/src/Walnut/Image.cpp#L74-L80

ZanzyTHEbar commented 2 years ago

Yes, i am aware of the ImGui method - i was using ImGui::Image(m_Image->GetDescriptorSet(), { (float)m_Image->GetWidth(), (float)m_Image->GetHeight() }); to display the image as well as the simple: ImGui::Image(m_Image->GetDescriptorSet(), { (float)64, (float)64 }); The first method, i used after the call to Resize thinking i would get a cleaner image. The second method yields the result i am looking for (of course) but it's highly aliased - i have anti-aliasing turned as well in my init method :

ImGuiStyle& style = ImGui::GetStyle();
style.AntiAliasedFill = true;
style.AntiAliasedLines = true;
style.AntiAliasedLinesUseTex = true;

This does not change the way the image renders after resizing - it just looks like crap.