Overv / VulkanTutorial

Tutorial for the Vulkan graphics and compute API
https://vulkan-tutorial.com
Creative Commons Attribution Share Alike 4.0 International
3.18k stars 519 forks source link

Adding helper function for filling buffers #122

Closed Krenodeno closed 5 years ago

Krenodeno commented 5 years ago

Hi, There are several use of the same little piece of code in the case of filling buffer with data, like for staging vertex buffers, uniform buffers and image buffers...

void* data;
vkMapMemory(device, stagingBufferMemory, 0, size, 0, &data);
    memcpy(data, pixels, static_cast<size_t>(size));
vkUnmapMemory(device, stagingBufferMemory);

Why not creating a little helper for that matter ? It could look like this:

void fillBuffer(VkDeviceMemory& memory, const void* dataToCopy, VkDeviceSize size) {
    void* data;
    VkMapMemory(device, memory, /*offset*/ 0, size, 0, &data);
        std::memcpy(data, dataToCopy, static_cast<size_t>(size));
    VkUnmapMemory(device, memory);
}
Overv commented 5 years ago

Sure, it's possible to create a helper for things like this but I don't think it's worth mentioning in the tutorial.

Krenodeno commented 5 years ago

The main reason for me is reducing code duplication, and it's quite convenient. But if it's not worth mentioning, I'll just close the issue. Thank you.

Overv commented 5 years ago

I didn't intend to come across as rude but instructions about code style are somewhat outside the scope of the tutorial, which is also why the code is one big C++ file. It's more about understanding the Vulkan API and interacting with it.

Krenodeno commented 5 years ago

I get your point, no problem. By the way, the tutorial is great, you do a great job.