Improved support for mapping RGB to RGBA

76 views
Skip to first unread message

Robert Osfield

unread,
Mar 5, 2021, 1:10:31 PM3/5/21
to vsg-users : VulkanSceneGraph Developer Discussion Group
A topic many who are familiar with Vulkan have is that vkImageView and vkImage (vsg::ImageView and vsg::Image) don't support RGB formats.  Many image formats are just stored as RGB so generally applications have to convert to RGBA images before they can be used with the Vulkan/VSG.

This week I've added better support for RGB data with an automatic mapping to RGB when setting up vsg::ImageView, vsg::Image, and when copying RGB vsg::Data to the GPU using the vsg::CopyAndReleaseImage class.

The changes are all merged with VulkanSceneGraph, vsgXchange and vsgExamples master, the PR's are:


This support allows the vsgXchange image loaders to choose to load RGB data as images rather always mapping to RGBA, to allow users to select this preference I've added bool vsg::Options::mapRGBtoRGBAHint that defaults to true. 

I've updated the GDAL and OSG loaders in vsgXchange to honour this new vsg::Options::mapRGBtoRGBHint, but haven't touched the stbi, dds and ktx loaders yet. 

I have also updated vsgconv and vsgviewer examples to accept --rgb command line option to set the vsg::Options::mapRGBtoRGBHint to false so you can do:

   vsgconv myrgbimage.jpg image.vsgb --rgb
   vsgconv mymodel.flt model.vsgb --rgb
   vsgviewer mymodel.flt --rgb

One advantage with being able to load RGB images as RGB vsg::Data is it takes less CPU memory and less disk space, for example one OpenFlight test model I have is 18% smaller when converted .vsgb with the --rgb hint. 

It also means that OSG native and VSG native files for the same scene graph are now similar size:

    77397409 osg.osgb
    76523402 rgb.vsgb
    93251294 rgba.vsgb

The changes to vsg::CopyAndReleaseImage improve the convince of passing dynamic data to the GPU, the changes the vsgdynamictexture example now no longer needs to concern itself with copying data to a staging buffer, as the CopyAndReleaseImage::copy(ref_ptr<Data>, ImageInfo) handles the copy to the staging buffer for you, and even is able to convert the RGB vsg::Data to RGBA during the copy to the staging buffer.  The code now just looks like:

        // update texture data
        update(*textureData, time);

        // copy data to staging buffer and issue a copy command to transfer to the GPU texture image
        copyCmd->copy(textureData, textureImageInfo);

There is more work to keep converting RGB to RGBA during this copy, so if you can easily use RGBA in vsg::Data then it can be better to do this but if the source data is RGB it'll save memory and more no more expensive CPU wise to just let CopyAndReleaseImage::copy() do the conversion to RGBA for you.

Cheers,
Robert
Reply all
Reply to author
Forward
0 new messages