Advertisement
Guest User

Untitled

a guest
Feb 16th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int Texture2DVK::loadFromFile(std::string filename) {
  2.     const char * filename_char = filename.c_str();
  3.  
  4.     int texWidth, texHeight, texChannels;
  5.     stbi_uc* pixels = stbi_load(filename_char, &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
  6.     DeviceSize imageSize = texWidth * texHeight * 4;
  7.  
  8.     if (!pixels) {
  9.         return -1;
  10.     }
  11.  
  12.     ImageCreateInfo imageInfo = {};
  13.     imageInfo.imageType = ImageType::e2D;
  14.     imageInfo.extent.width = static_cast<uint32_t>(texWidth);
  15.     imageInfo.extent.height = static_cast<uint32_t>(texHeight);
  16.     imageInfo.extent.depth = 1;
  17.     imageInfo.mipLevels = 1;
  18.     imageInfo.arrayLayers = 1;
  19.     imageInfo.format = Format::eR8G8B8A8Unorm;
  20.     imageInfo.tiling = ImageTiling::eOptimal;
  21.     imageInfo.initialLayout = ImageLayout::eUndefined;
  22.     imageInfo.usage = ImageUsageFlagBits::eTransferDst | ImageUsageFlagBits::eSampled;
  23.     imageInfo.sharingMode = SharingMode::eExclusive;
  24.     imageInfo.samples = SampleCountFlagBits::e1;    //wrong?
  25.     imageInfo.flags = vk::ImageCreateFlags();
  26.  
  27.     if (device.createImage(&imageInfo, nullptr, &textureImage) != Result::eSuccess) {   //create empty Image space
  28.         return -1;
  29.     }
  30.  
  31.     MemoryRequirements memReq;
  32.     device.getImageMemoryRequirements();
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement