Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码错误:纹理图像格式错误 #5

Open
AnpyDX opened this issue Aug 11, 2022 · 2 comments
Open

代码错误:纹理图像格式错误 #5

AnpyDX opened this issue Aug 11, 2022 · 2 comments

Comments

@AnpyDX
Copy link

AnpyDX commented Aug 11, 2022

错误简要

28节纹理 中创建 图像(Image)图像视图(ImageView) 时填写的格式(foramt)参数错误,原先填写的 VK_FORMAT_R8G8B8A8_UNORM 应全部改为 VK_FORMAT_R8G8B8A8_SRGB

该错误会造成纹理颜色显示异常。不知道是不是原作者进行了更新。

错误详细

1 - 28.5 纹理图像 ->> 创建图像时填写的 VkImageCreateInfo imageInfo{} 格式(format)参数错误

  • 位于 PDF 213页
imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM;

更改为

imageInfo.format = VK_FORMAT_R8G8B8A8_SRGB;

2 - 28.5 纹理图像 ->> 封装 createImage 函数后的格式(format)参数错误

  • 位于 PDF 218页
createImage(texWidth, texHeight, 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);

更改为

createImage(texWidth, texHeight, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, textureImage, textureImageMemory);

3 - 28.8 准备纹理图像 ->> 两次调用函数 transitionImageLayout 时填的写格式(format)参数错误

  • 位于 PDF 223页
transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
copyBufferToImage(stagingBuffer, textureImage, static_cast<uint32_t>(texWidth), static_cast<uint32_t>(texHeight));

transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);

更改为

transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
copyBufferToImage(stagingBuffer, textureImage, static_cast<uint32_t>(texWidth), static_cast<uint32_t>(texHeight));

transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);

4 - 28.10 清理 ->> 函数 transitionImageLayout 格式(format)参数错误

  • 位于 PDF 225页
transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);

    vkDestroyBuffer(device, stagingBuffer, nullptr);
    vkFreeMemory(device, stagingBufferMemory, nullptr);

更改为

transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);

    vkDestroyBuffer(device, stagingBuffer, nullptr);
    vkFreeMemory(device, stagingBufferMemory, nullptr);
@AnpyDX AnpyDX changed the title 代码错误 代码错误:纹理图像格式错误 Aug 11, 2022
@fangcun010
Copy link
Owner

Thanks.

@fangcun010
Copy link
Owner

你可以提交一个PR吗?我来合并~感谢~。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants