Android experiment

Jimmy

New member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
569
I'm learning OO and 3d graphics but before continouning with that I want to go through with seeing if I can make an experiment I said I would try with readpixels because it seems doable actually. I know it's old GLES2.0 but I won't try too hard. And if I need to make too much changes in the sourcecode that might induce problems then I guess I will just quit trying.

Do you have a preference about what option to plump for in Cerberus?

Pseudo/C++ code :

Code:
'  Improves GLES 2.0 readpixels from 100ms to 5ms on Android

' INIT
EGLImageKHR eglCreateImageKHR(EGLDisplay dpy,               ' any valid display
                              EGLContext ctx,               ' EGL_NO_CONTEXT
                              EGLenum target,               ' EGL_NATIVE_BUFFER_ANDROID
                              EGLClientBuffer buffer,       ' ANativeWindowBuffer
                              const EGLint *attrib_list)
' Allocate ANativeWindowBuffer using the wrapper Graphicbuffer
GraphicBuffer *window = new GraphicBuffer(width, height, PIXEL_FORMAT_RGBA_8888, GraphicBuffer::USAGE_SW_READ_OFTEN | GraphicBuffer::USAGE_HW_TEXTURE);
struct ANativeWindowBuffer *buffer = window->getNativeBuffer();
EGLImageKHR *image = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, *attribs);

' USAGE :

' FBO OPTION 1
void EGLImageTargetTexture2DOES(enum target, eglImageOES image)
uint8_t *ptr;
glBindTexture(GL_TEXTURE_2D, texture_id);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);

' FBO OPTION 2
void EGLImageTargetRenderbufferStorageOES(enum target, eglImageOES image)
window->lock(GraphicBuffer::USAGE_SW_READ_OFTEN, &ptr);
memcpy(pixels, ptr, width * height * 4);
window->unlock();
 
Last edited:

Jimmy

New member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
569
Did the comparison now

The existing old PIXELREAD works perfectly on most platforms :

* DESKTOP - you can read a lot of pixels, no problem at all. Amazing.

* HTML5 - same performance as DESKTOP actually (impressive progress of the web technologies) but readpixel introduces a constant stall here. It does not matter if you read 1x1 pixel or 1280x768 pixels. It is the same size of stall. Otherwise it is as quick as DESKTOP. Amazing, just a weird cosmetic tiny bump.

* iOS - same as DESKTOP. Amazing.

* Android - totally DISASTER, you will have to keep it to unusable small sized to even keep the renderloop not freezing on many Android devices.

The only reason I'm going to do this is to remove the cosmetic bump on HTML5 and to make Android usable.
 
Last edited:
Top Bottom