I'm trying to render multi-channel images (more than 4 channels, for the purposes of feeding it to a Neural Network). Since OpenGL doesn't support it natively, I have multiple 4-channel render buffers, into which I render a corresponding portion of channels.
For example, I need multi-channel image of size
512 x 512 x 16, in OpenGL I have 4 render buffers of size
512 x 512 x 4. Now the problem is that the Neural Network expects the data with strides
512 x 512 x 16, i.e. 16 values of channels of one pixel are followed by 16 values of channels from the next pixel. However currently I can efficiently read my 4 render buffers via 4 calls to
glReadPixels, basically making the data having strides
4 x 512 x 512 x 4. Manual reordering of data on the client side will not suffice me as it's too slow.
I've got an idea to render to a single 4-channel render buffer of size
512 x 512*4 x 4, because stride-wise it's equivalent to
512 x 512 x 16, we just treat a combination of 4 pixels in a row as a single pixel of 16-channel output image. Let's call it an "interleaved rendering"
But this requires me to magically adjust my fragment shader, so that every group of consequent 4 fragments would have exactly the same interpolation of vertex attributes. Is there any way to do that?