<p>I'm decoding an <code>.mp4</code> to use as a texture on a tristrip. It's easy enough to use an unsigned byte array of RGB triplets to create this texture, but frames come out of an <code>.mp4</code> as three separate buffers. One for each channel. In other words, instead of having <code>uint8_t * buf = {RGBRGBRGBRGB.....}</code>, I have <code>uint8_t * r_buf = {RRRRR....}; uint8_t * g_buf = {GGGGG....}; uint8_t * b_buf = {BBBBBB....};</code> Can I pack all of this into one texture so my fragment shader just treats it the same as it did the current texture? I don't have any great objection to having three separate 1-channel textures that I mix in the shader, but that'll ugly up my shader code a bit.</p>

CC BY-SA 4.0
2020-11-12T01:57:00.160Z
"*RGB triplets*" You really don't want to do that. It'd be best to use four channels, even if the alpha channel is 1. Your upload times to the GPU will improve.
Nicol Bolas
CC BY-SA 4.0
2020-11-13T18:06:51.353Z
You're right, I don't want to do that, but I don't have a choice since that's how the data comes to me from the ffmpeg library. The problem turned out to be a helluva lot more complicated than I realized - ffmpeg is giving me YUV streams in 8:4:4 grouping instead of RGB. However, other formats I deal with will still present the problem posed in the question, so I'll leave it up.
Sniggerfardimungus
CC BY-SA 4.0
2020-11-13T18:08:42.703Z
Why would you expect that RGBA would be faster than RGB? It's 33% more data to have to transfer to the graphics hardware every frame (the video in question is 1920x1080 @ 30fps, so adding an alpha channel increases the data transfer demand by 60 million bytes per second.
Sniggerfardimungus
CC BY-SA 4.0
2020-11-13T19:39:52.767Z
"*Why would you expect that RGBA would be faster than RGB?*" Because GPUs generally cannot do misaligned reads. So they don't *have* RGB formats; they're a fiction created by the API. If you upload from RGB data, the driver will internally have to copy each pixel of data to a 4-channel format, then DMA that into GPU memory. That's slower than you simply preparing the data correctly ahead of time.
Nicol Bolas
<opengl><texture>
Packing a GL_RGB from three separate buffers?
Sniggerfardimungus
# Packing a GL_RGB from three separate buffers?

(Asked by: username_0 on 2020-11-11)

I'm decoding an `.mp4` to use as a texture on a tristrip. It's easy enough to use an unsigned byte array of RGB triplets to create this texture, but frames come out of an `.mp4` as three separate buffers. One for each channel. In other words, instead of having `uint8_t * buf = {RGBRGBRGBRGB.....}`, I have `uint8_t * r_buf = {RRRRR....}; uint8_t * g_buf = {GGGGG....}; uint8_t * b_buf = {BBBBBB....};` Can I pack all of this into one texture so my fragment shader just treats it the same as it did the current texture? I don't have any great objection to having three separate 1-channel textures that I mix in the shader, but that'll ugly up my shader code a bit.

**Tags:** opengl, texture

> **Comments:**
> **username_1**: "*RGB triplets*" You really don't want to do that. It'd be best to use four channels, even if the alpha channel is 1. Your upload times to the GPU will improve.  
> **username_0**: You're right, I don't want to do that, but I don't have a choice since that's how the data comes to me from the ffmpeg library. The problem turned out to be a helluva lot more complicated than I realized - ffmpeg is giving me YUV streams in 8:4:4 grouping instead of RGB. However, other formats I deal with will still present the problem posed in the question, so I'll leave it up.  
> **username_0**: Why would you expect that RGBA would be faster than RGB? It's 33% more data to have to transfer to the graphics hardware every frame (the video in question is 1920x1080 @ 30fps, so adding an alpha channel increases the data transfer demand by 60 million bytes per second.  
> **username_1**: "*Why would you expect that RGBA would be faster than RGB?*" Because GPUs generally cannot do misaligned reads. So they don't *have* RGB formats; they're a fiction created by the API. If you upload from RGB data, the driver will internally have to copy each pixel of data to a 4-channel format, then DMA that into GPU memory. That's slower than you simply preparing the data correctly ahead of time.  

---

## 0 answers

