Efficient rendering of BGR(A) buffers in OpenGL?

187 views
Skip to first unread message

Ulrich Eck

unread,
Oct 3, 2019, 10:19:50 AM10/3/19
to Magnum Graphics Engine
Dear Magnum Community,

i'm wondering what is the intended / correct way to render BGR(A) image buffers as they are often obtained from cameras (e.g. realsense, azure kinect, opencv) efficiently using GL Textures with Magnum. I'm only targeting Desktop GL Targets (Win/OSX/Linux)

There is support for BGR(A) pixel formats in GL::PixelFormat, however GL::TextureFormat only supports all kinds of RGB(A).. pixel formats.

One obvious way is to convert the image buffer, but since i'm really caring about latency that is not an option.
Another method would be to (wrongly) choose RGB(A) and provide a custom shader to "fix" it .. but that doesn't sound right to me.

Is there another/better method, which I haven't found yet, to correctly and efficiently render BGR(A) image buffers as OpenGL Textures ??

Thanks for your support!

best
Ulrich

Vladimír Vondruš

unread,
Oct 3, 2019, 11:17:32 AM10/3/19
to Ulrich Eck, Magnum Graphics Engine
Hi Ulrich,

The BGRA support is currently a bit half-done -- the `GL::PixelFormat` has it, but not the generic `Magnum::PixelFormat` (yet -- those formats were originally added for TGA but caused so much pain that I ended up swizzing to RGBA on import instead). There are also various extensions providing these formats for OpenGL ES and WebGL that I have on my TODO list, but it's quite a mess and I didn't have a chance to look at that deeply yet.

Checking the OpenGL wiki, passing `GL::PixelFormat::BGRA` to `GL::TextureFormat::RGBA8` should actually work -- see https://www.khronos.org/opengl/wiki/Textures_-_more . There's no source for that though, but checking the spec and the full GL extension list, there isn't anything that would provide `GL::TextureFormat::BGRA8` (on desktop, that is -- OpenGL ES on the other hand *has* such extensions). Can you try if that works for you? I'll update the docs to make this more clear.

Alternatively (if the above doesn't work, but I'm pretty sure it would), there's `GL::Texture::setSwizzle()` that allows you to remap the components. So if you would load as `PixelFormat::RGBA`, then you could do `texture.setSwizzle<'b', 'g', 'r', 'a'>()` to reorder the components to the proper place.

Hope this helps!
Vladimir

______________________________________________________________
> Od: "Ulrich Eck" <ulri...@gmail.com>
> Komu: "Magnum Graphics Engine" <magnum...@googlegroups.com>
> Datum: 03.10.2019 16:26
> Předmět: [magnum] Efficient rendering of BGR(A) buffers in OpenGL?
>--
>You received this message because you are subscribed to the Google Groups "Magnum Graphics Engine" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to magnum-engin...@googlegroups.com.
>To view this discussion on the web visit https://groups.google.com/d/msgid/magnum-engine/e526d3ae-91e8-4a17-bc03-444be5d1b3af%40googlegroups.com.
>
>

ue...@net-labs.de

unread,
Oct 4, 2019, 3:20:39 AM10/4/19
to Ulrich Eck, Magnum Graphics Engine, Vladimír Vondruš
Dear Vladimir,

thanks for the quick response!
I’ll try your suggestions and will provide feedback once i’ve got a running version.

Best regards


Dr. Ulrich Eck

--
Senior Research Scientist
Computer Aided Medical Procedures & Augmented Reality
Fakultät für Informatik
Technische Universität München
Boltzmannstr. 3
85748 Garching bei München
room: MI 03.13.044
phone office: +49 (89) 289-19412
phone lab: +49 (89) 44005-4368

Ulrich Eck

unread,
Oct 4, 2019, 1:20:22 PM10/4/19
to Magnum Graphics Engine
Dear Vladimir,

your suggestion actually works fine - no need for swizzling the texture.

thanks for your support!

best
Ulrich
>To unsubscribe from this group and stop receiving emails from it, send an email to magnum...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages