src/model_loaders/glTFModel.cpp
void glTFModel::Model::setTexture(std::basic_string<char, std::char_traits<char>, std::allocator<char>> fileName) {
    // Create texture image

    int texWidth, texHeight, texChannels;
    stbi_uc *pixels = stbi_load(fileName.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
    VkDeviceSize imageSize = texWidth * texHeight * 4;
    if (!pixels) {
        throw std::runtime_error("failed to load texture image!");
    }

    Texture2D texture;
    texture.fromBuffer(pixels, imageSize, VK_FORMAT_R8G8B8A8_SRGB, texWidth, texHeight, device, device->transferQueue);
    textureIndices.baseColor = 0;
    textures.push_back(texture);

    Texture::TextureSampler sampler{};
    sampler.magFilter = VK_FILTER_LINEAR;
    sampler.minFilter = VK_FILTER_LINEAR;
    sampler.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
    sampler.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
    sampler.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
    textureSamplers.push_back(sampler);


}
/**
 * Function to set texture other than the specified in embedded glTF file.
 * @param fileName Name of texture. Requires full path
 */
Function to set texture other than the specified in embedded glTF file.
@param fileName Name of texture. Requires full path
Function to set texture other than the specified in embedded glTF file . @param fileName Name of texture . Requires full path
void glTFModel::Model::setTexture(std::basic_string<char, std::char_traits<char>, std::allocator<char>> fileName) {
    int texWidth, texHeight, texChannels;
    stbi_uc *pixels = stbi_load(fileName.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
    VkDeviceSize imageSize = texWidth * texHeight * 4;
    if (!pixels) {
        throw std::runtime_error("failed to load texture image!");
    }
    Texture2D texture;
    texture.fromBuffer(pixels, imageSize, VK_FORMAT_R8G8B8A8_SRGB, texWidth, texHeight, device, device->transferQueue);
    textureIndices.baseColor = 0;
    textures.push_back(texture);
    Texture::TextureSampler sampler{};
    sampler.magFilter = VK_FILTER_LINEAR;
    sampler.minFilter = VK_FILTER_LINEAR;
    sampler.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
    sampler.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
    sampler.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
    textureSamplers.push_back(sampler);
}
void glTFModel :: Model :: setTexture ( std :: basic_string < char , std :: char_traits < char > , std :: allocator < char > > fileName ) { int texWidth , texHeight , texChannels ; stbi_uc * pixels = stbi_load ( fileName . c_str ( ) , & texWidth , & texHeight , & texChannels , STBI_rgb_alpha ) ; VkDeviceSize imageSize = texWidth * texHeight * 4 ; if ( ! pixels ) { throw std :: runtime_error ( " " ) ; } Texture2D texture ; texture . fromBuffer ( pixels , imageSize , VK_FORMAT_R8G8B8A8_SRGB , texWidth , texHeight , device , device -> transferQueue ) ; textureIndices . baseColor = 0 ; textures . push_back ( texture ) ; Texture :: TextureSampler sampler { } ; sampler . magFilter = VK_FILTER_LINEAR ; sampler . minFilter = VK_FILTER_LINEAR ; sampler . addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT ; sampler . addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT ; sampler . addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT ; textureSamplers . push_back ( sampler ) ; }
Function to set texture other than the specified in embedded glTF file.
Function to set texture other than the specified in embedded glTF file .
// Create texture image