Hello !
I am trying to load textures with Vulkan. I want to load png, or jpg or bmp or whatever. To have a row major order textures, I am using linear tiling, and after I will copy it into one with optimal tiling.
But maybe I am wrong, and please tell me if it is the case.
Before loading real texture, I am just “emulating” a simple gradient texture (dark on top and white on bottom).
So, I am creating an image like that :
VkImageCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
info.pNext = nullptr;
info.flags = 0;
info.imageType = VK_IMAGE_TYPE_2D;
info.format = VK_FORMAT_R8G8B8A8_SRGB;
info.extent.width = 1024;
info.extent.height = 1024;
info.mipLevels = 1;
info.arrayLayers = 1;
info.samples = VK_SAMPLE_COUNT_1_BIT;
info.tiling = VK_IMAGE_TILING_LINEAR;
info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
... Get memory Requirement, alloc and binding
Since I am using linear tiling, I thought that piece of code will make it dark on top and white on bottom, but it is not the case (unfortunately).
(4096 should be the size in bytes of the line, but maybe it is not… (1024 * 4)).
for(int i = 0; i < 1024; ++i)
memset(std::get<3>(mAllocation) + i * 4096, i * 255. / 1024, 4096);
After, I am using 4D position and 2D textures (4float, 2float) is a vertex
float vertices[] = {-1, -1, 1, 1, 0, 0,
1, -1, 1, 1, 1, 0,
-1, 1, 1, 1, 0, 1,
1, 1, 1, 1, 1};
And instead of getting a beautiful gradient, I got that …
Thanks for help !