How can I read pixel buffer after 3D rendering with a low cost on Android platform?
1、Is your feature request related to a problem? Please describe. Now, I use off-screen rendering of filament, I know that isn't a recommended way. But, it's a very situation that I should get pixel buffer after 3D-rendering, and then transport the pixel buffer.
- codes below:
m_scene->addEntity(m_glb_instance);
if (m_renderer->beginFrame(m_swap_chain)) {
m_renderer->render(m_view);
m_renderer->readPixels(0, 0, width, height, std::move(pbd));
m_renderer->endFrame();
// todo: todo keria, bad performance here...
m_engine->flushAndWait();
} else {
LOGE("m_renderer->beginFrame() error!");
}
m_scene->remove(m_glb_instance);
The problem is, when we run the code on Android phone, it will cost so much time on the function flushAndWait(). For instance, flushAndWait() cost 7ms on the phone equipped with Qualcomm Snapdragon 865 cpu chip, but cost about 40ms on some medium performance phones.
So, how to reduce the cost time of function flushAndWait() execution, or, maybe I do the off-screen rendering with a wrong use. There are no sample for off-screen rendering in filament codes.
When I removed the function flushAndWait(), it would make crash when rendering. So, I felt confused...
2、Describe the solution you'd like I'd like a low time cost execution.
3、Describe alternatives you've considered Is there any configs or usages I made a mistake?
4、OS and backend Android, armeabi-v7a or arm-v8a. Filament with static libraries , v1.9.17.
flushAndWait() itself doesn't cost time, but flushAndWait() will do exactly what it says: flush all commands to the GPU and wait for completion of the frame. You don't need to use it to read pixels back. Instead you can use the pixel buffer descriptor's callback to know when the pixel data is ready.
flushAndWait()itself doesn't cost time, butflushAndWait()will do exactly what it says: flush all commands to the GPU and wait for completion of the frame. You don't need to use it to read pixels back. Instead you can use the pixel buffer descriptor's callback to know when the pixel data is ready.
I have tried it, when I get rendered pixel buffer from PixelBufferDescriptorCallback, the cost time is same as flushAndWait(), so, is there any ways to reduce the time of rendering?
To do that you could reduce the resolution, reduce scene complexity (avoid small triangles), use smaller textures (or better yet use compressed textures), turn off effects etc.
To do that you could reduce the resolution, reduce scene complexity (avoid small triangles), use smaller textures (or better yet use compressed textures), turn off effects etc.
okey, fine, thank you very much. I need try it with a usual way like what you said~