How to :: ofFbo GL_RGB on OpenGLES

Hi,

I’m trying to send unsigned char values through using artnet in a format [R][G][B] on a Raspberry PI4 .
I’ve realised that assigning an ofFbo can’t be done with just RGB, but has to be RGBA in OpenGLES:
window initialisation:

// in main.cpp
#ifdef TARGET_OPENGLES
	ofGLESWindowSettings settings;
	settings.glesVersion=2;
#else
// [other sutff]
#endif
// [rst  of the code]

Therefore when doing : shader drawing into my Fbo, i then need to remove manually the alpha part of the buffer by doing :


 ofVec2f sPix = { 1, 500};

ofFbo f;
f.allocate(sPix.x, sPix.y, GL_RGB) ; >> give GL_RGBA
ofPixels pix;
pix.allocate(sPix.x, sPix.y, 3);
f.begin();
//shader
f.end();
f.readToPixels(pix);

unsigned char * newPixRGB = new unsigned char[sPix.x * sPix.y * 3];

int nIndex = 0;
for (int i = 0; i < sPix.x; i++) {
	for (int j = 0; j < sPix.y; j++) {
		int oIndex = j + i * sPix.y;

		newPixRGB[nIndex++] = pix[oIndex * 4];
		newPixRGB[nIndex++] = pix[oIndex * 4 + 1];
		newPixRGB[nIndex++] = pix[oIndex * 4 + 2];
	}
}

This is not the best way to do it:
I’m processing my colors in my shader, but then re processing it individually afterwards to remove the alpha…
How to make it more efficient?
I’ve looked at ofFboSettings, but no luck so far.
Any ideas?

Best,

P

Hi @pierre_tardif00 !
As far as I know you need to do it in a for loop, although it can be optimized. For example:
you can do it in a single for loop instead of 2
try using ++i instead of i++, as well as for nIndex. It is not the same.
Last but not least, remeber to delete taht array you created with new, otherwise you will be leaking memory (and a lot of it). or you can just use a vector, allocate it using resize or reserve and you can forget about leaking memory.

Hi @roymacdonald ,

Yeah the code is concatenated here from several classes, unsigned char * newPixRGB is only declared once. The size of thge buffer is set once so no need to resize it.
Thanks for the tips i’ll try them anyways.
I was more wondering about fast copy an array with special offset of some sort maybe?

Hi!
as far as I know there is no memcopy with an offset. Actually it is not called but stride.

cheers

Ah yeah thanks!

Will check it out.

++

I’ve used the same thing in a project in 2019, allocating a GL_RGB fbo directly and copying the pixels raw data to send to LEDs. I was not using OpenGLES, maybe that is the difference. Do you need to use specifically OpenGLES?

Hi @dimitre ,

Yes I had to use OPENGLES, as I was on a raspberry pi4.
Ended up removing the shader and doing pixels manipulations instead, since i was doing it to send to the Artnet controller…