#Best way to drawn pixels from cpu ?

9 messages · Page 1 of 1 (latest)

mild hill
#

Hi,

I have a raycasting project in C++ that uses SFML to render an array of pixels. I set the pixels one by one of an image and then draw it.
Here is what the render loop looks like:

for (uint32_t y = 0; y < height; ++y)
{
    for (uint32_t x = 0; x < width; ++x)
    {
        ray.dir = rayDirections[x + (y * width)];
        Vector4f32 color = traceRay(scene, ray);
        color = clamp(color, Vector4f32(0.0f), Vector4f32(1.0f));
        image.setPixel(x, height - 1 - y, sf::Color(utils::convertToRgba(color)));
    }
}

I want to switch from SFML to Vulkan but still keep the computation on the CPU side, so no shaders.
What would be the "Vulkan way" to do this? I found VkImage in the API but I'm not sure about the best practices for using it or even if that's what I should use.

Thanks ! 👍

vocal gulch
#

Use vkCmdCopyBufferToImage to upload your CPU side results to an image and display that

#

though it you want to do all the calculation on the CPU, Vulkan may not be your best option. Just displaying things is much easier with other apis or libraries.

mild hill
#

Do you know a good guide that covers that ? Because there is a lot of different parameters of allocator, image layout, ect ... and I don't know which to choose for optimal performance.

vocal gulch
#

exactly. You create a buffer from your result and upload it to the GPU. You can take a look at pretty much every sample that displays an image. What you'l be doing is pretty much the same as rendering a texture.

mild hill
#

I can't find any resource on how to set pixel individually on a buffer, how can I do it ?

tranquil goblet
#

Find an example that loads and renders an image from a PNG or whatever. Copy it. Then replace the bit where the PNG is decompressed into the buffer (which just contains a big 2D array of RGBA values) with your loop.

glad silo