android - Unexpected pixel data layout when reading from GraphicBuffer -
i working on platform in native android framework use graphicbuffer allocate memory , create eglimage it. used texture in opengl render (with simple fullscreen quad).
the problem when read rendered pixel data graphicbuffer, expect in linear rgba format in memory result texture contains 3 parallell smaller clones of image , overlapping pixels. maybe description doesn't point actual pixel data makes sense memory layout seems other linear rgba. assume because graphics drivers store pixels in internal format other linear rgba.
if render standard opengl texture , read glreadpixels works fine, assume problem lies custom memory allocation graphicbuffer.
if reason drivers' internal memory layout, there way of forcing layout linear rgba? have tried of usage flags supplied graphicbuffer constructor no success. if not, there way output data differently in shader "cancel out" memory layout?
i building android 4.4.3 nexus 5.
//allocate graphicbuffer outputbuffer = new graphicbuffer(outputformat.width, outputformat.height, outputformat.bufferformat, graphicbuffer::usage_sw_read_often | graphicbuffer::usage_hw_render | graphicbuffer::usage_hw_texture); /* ... */ //create eglimage graphicbuffer eglint eglimageattributes[] = {egl_width, outputformat.width, egl_height, outputformat.height, egl_match_format_khr, outputformat.eglformat, egl_image_preserved_khr, egl_false, egl_none}; eglclientbuffer nativebuffer = outputbuffer->getnativebuffer(); eglimage = _eglcreateimagekhr(display, egl_no_context, egl_native_buffer_android, nativebuffer, eglimageattributes); /* ... */ //create output texture glgentextures(1, &outputtexture); glbindtexture(gl_texture_2d, outputtexture); gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_nearest); gltexparameteri(gl_texture_2d, gl_texture_mag_filter, gl_nearest); gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_clamp_to_edge); gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_clamp_to_edge); _gleglimagetargettexture2does(gl_texture_2d, eglimage); /* ... */ //create target fbo glgenframebuffers(1, &targetfbo); glbindframebuffer(gl_framebuffer, targetfbo); glframebuffertexture2d(gl_framebuffer, gl_color_attachment0, gl_texture_2d, outputtexture, 0); glbindframebuffer(gl_framebuffer, 0); /* ... */ //read graphicbuffer const rect lockboundsoutput(quadrenderer->outputformat.width, quadrenderer->outputformat.height); status_t statusgb = quadrenderer->getoutputbuffer()->lock(graphicbuffer::usage_sw_read_often, &result);
i managed find answer myself , wrong along. simple reason although rendering 480x1080 texture memory allocated padded 640x1080 needed remove padding after each row , output texture made sense.
Comments
Post a Comment