sdl 2 - unexpected behavior while using SDL_image for texture in Vulkan -
i managed load jpg images , use them textures in vulkan, different images give different results, images works fine, others not map well.
here code block related image loading , format transition:-
void vulkan::createtextureimage() { sdl_surface *tempimg; sdl_rwops *rwop; rwop = sdl_rwfromfile("textures/img1.jpg", "rb"); tempimg = img_loadjpg_rw(rwop); sdl_surface *image = sdl_convertsurfaceformat(tempimg, sdl_pixelformat_abgr8888, 0); vkdevicesize imagesize = image->format->bytesperpixel * image->h * image->w; if (!image) { throw std::runtime_error("failed load texture image!"); } vkimage stagingimage; vkdevicememory staingimagememory; createimage( image->w, image->h, vk_format_r8g8b8a8_unorm, vk_image_tiling_linear, vk_image_usage_transfer_src_bit, vk_memory_property_host_visible_bit | vk_memory_property_host_coherent_bit, stagingimage, staingimagememory); std::cout << "the image size " << imagesize << std::endl; void * data; vkmapmemory(device, staingimagememory, 0, imagesize, 0, &data); memcpy(data, image->pixels, (size_t)imagesize); vkunmapmemory(device, staingimagememory); createimage( image->w, image->h, vk_format_r8g8b8a8_unorm, vk_image_tiling_optimal, vk_image_usage_transfer_dst_bit | vk_image_usage_sampled_bit, vk_memory_property_device_local_bit, textureimage, textureimagememory); transitionimagelayout(stagingimage, vk_format_r8g8b8a8_unorm, vk_image_layout_preinitialized, vk_image_layout_transfer_src_optimal); transitionimagelayout(textureimage, vk_format_r8g8b8a8_unorm, vk_image_layout_preinitialized, vk_image_layout_transfer_dst_optimal); copyimage(stagingimage, textureimage, image->w, image->h); transitionimagelayout(textureimage, vk_format_r8g8b8a8_unorm, vk_image_layout_transfer_dst_optimal, vk_image_layout_shader_read_only_optimal); }
the modification have done flip v component of texture fix mirrored images
it looks row pitch of sdl doesn't match row pitch vulkan wants.
instead can use buffer image copy staging memory vkcmdcopybuffertoimage
instead of image image blit there pass row pitch explicitly in vkbufferimagecopy
struct.
Comments
Post a Comment