Copying OpenGL pixel data
Copy link to clipboard
Copied
Greetings everyone,
I’ll be straight to the point. I striped down the GLator (Effect plugin example) to copy an OpenGL pixel buffer onto a solid like so:
static PF_Err Render(PF_InData *in_data, PF_OutData *out_data, PF_ParamDef *params[], PF_LayerDef *output)
{
/// Render OpenGL stuff here!
PF_Err err = PF_Err_NONE;
AEGP_SuiteHandler l_suites(in_data->pica_basicP);
PF_EffectWorld l_world;
A_long l_width(output->width);
A_long l_height(output->height);
AEFX_CLR_STRUCT(l_world);
ERR(l_suites.WorldSuite1()->new_world(in_data->effect_ref,
l_width, l_height, PF_NewWorldFlag_CLEAR_PIXELS, &l_world));
PF_Pixel8 *l_data = NULL;
in_data->utils->get_pixel_data8(&l_world, NULL, &l_data);
glReadPixels(0, 0, l_width, l_height, GL_RGBA, GL_UNSIGNED_BYTE, l_data);
ERR(l_suites.WorldTransformSuite1()->copy_hq(in_data->effect_ref, &l_world, output, NULL, NULL));
ERR(l_suites.WorldSuite1()->dispose_world(in_data->effect_ref, &l_world));return err;
}
The frame is rendered but with 2 major hiccups:
1 – The Y of the resulting image is flipped upside-down.
2 – The Red and Alpha channels seem to be swap.
Now, I do have a good idea how to solve this manually but I would like to avoid extra memory allocation and/or swapping data unnecessarily to solve these issues.
1 – Is there any workaround that would flip the image without touching the layer transformations? (the solution must be transparent to users)
2 – Is there is any way to pass the pixel data as RGBA and/or BGRA to avoid manual swizzling?
Important: Since we’re so close to get this working properly, I’d like to find solutions that wouldn’t hit performance at all, if possible!
Thx,
Copy link to clipboard
Copied
I've edited the code sample for simplicity sake.
Copy link to clipboard
Copied
Hi!
old post, but I'm re-reading all the openGL realated posts trying to make a plugin work properly...
About your questions, no real answer, but here are some clues:
1_in my tests, the image isn't flipped. I think you should check the openGL side of your plugin. In Glator, there are two textures, and one of them is flipped. May be you based your code on the "reflection" texture instead of the main texture.
2_I didn't find any direct way to read pixels correctly. But if you use glReadPixels() with GL_ABGR_EXT instead of GL_RGBA, only colors will be swapped, and alpha operations (blending and so on...) will be OK. If you swap the BLUE/RED colors before rendering, it should work without losing speed.
I have questions for you too, cos' I have hard times with the openGL side:
_how did you deal with openGL, did you create your own context? If yes, how?
Cheers,
François

