Can't retrieve multiple gl_Fragdata buffers in OpenGL in IOS (NV12 -> YV12/i420 conversion) -


i'm attempting convert camera frames in yuv 4.2.2 (nv12) format yuv 4.2.0 (yv12/i420) format. u , v channels of nv12 interleaved, while yv12 not.

for performance reasons, i'm trying conversion in opengl es 2.0 shader.

the shaders easy. separate out y , uv channels , pass uv shader separates out u channel in gl_fragdata[0] , v channel in gl_fragdata[1]

here fragment shader:

precision mediump float; uniform sampler2d t_texture_uv; varying highp vec2 uvvarying; void main() {     /*     vec2 uvu,uvv;     int x,y;     x = uvvarying.x;     y = uvvarying.y;     uvu = vec2(x*2,y);     uvv = vec2((x*2)+1,y);     gl_fragdata[0] = texture2d(t_texture_uv, uvu);     gl_fragdata[1] = texture2d(t_texture_uv, uvv);      */      // same logic above, less processor intensive     gl_fragdata[0] = texture2d(t_texture_uv, vec2( uvvarying.x*2   ,uvvarying.y)); // u-plane     gl_fragdata[1] = texture2d(t_texture_uv, vec2((uvvarying.x*2)+1,uvvarying.y)); // v-plane  } 

and vertex shader:

attribute vec2 position; attribute vec2 uv; uniform mat4 proj_matrix; varying vec2 uvvarying;  void main() {     gl_position = proj_matrix * vec4(vec3(position.xy, 0.0), 1.0);     uvvarying = uv; } 

my problem i'm lost @ how retrieve data gl_fragdata buffers in objective c code. tried glreadpixels, doesn't seem work.

this code, think i've gone down wrong path.

- (void) nv12_to_yv12_converter:(unsigned char*)ybuf uvbuff:(unsigned char*)uvbuf width:(glsizei)uvwidth height:(glsizei)uvheight {     unsigned char *ubufout;     unsigned char *vbufout;      eaglcontext *context;     context = [[eaglcontext alloc] initwithapi:keaglrenderingapiopengles2];     if (!context || ![eaglcontext setcurrentcontext:context]) {         nslog(@"failed create es context");     }      [self loadshaders];      glgenframebuffers(1, &_framebuffer);     glgenrenderbuffers(1, &_renderbuffer);     glbindframebuffer(gl_framebuffer, _framebuffer);     glbindrenderbuffer(gl_renderbuffer, _renderbuffer);     ;     glrenderbufferstorage(gl_renderbuffer, gl_depth_component16, uvwidth, uvheight); //    [context renderbufferstorage:gl_renderbuffer fromdrawable:(caeagllayer*)self.view.layer];     glgetrenderbufferparameteriv(gl_renderbuffer, gl_renderbuffer_width, &_backingwidth);     glgetrenderbufferparameteriv(gl_renderbuffer, gl_renderbuffer_height, &_backingheight);     glframebufferrenderbuffer(gl_framebuffer, gl_color_attachment0, gl_renderbuffer, _renderbuffer);       _vertices[0] = -1.0f;  // x0     _vertices[1] = -1.0f;  // y0     _vertices[2] =  1.0f;  // ..     _vertices[3] = -1.0f;     _vertices[4] = -1.0f;     _vertices[5] =  1.0f;     _vertices[6] =  1.0f;  // x3     _vertices[7] =  1.0f;  // y3       int orientation = 0;     static const glfloat texcoords[] = {         0.0f, 1.0f,         1.0f, 1.0f,         0.0f, 0.0f,         1.0f, 0.0f,     };      glviewport(0, 0, _backingwidth, _backingheight);     glclearcolor(0.0f, 0.0f, 0.0f, 1.0f);     glclear(gl_color_buffer_bit);     gluseprogram(_program);       if (!validateprogram(_program))     {         nslog(@"failed validate program");         return;     }      glpixelstorei(gl_unpack_alignment, 1);      gldeletetextures(1, &_textures[0]);      glactivetexture(gl_texture0);     glgentextures(1, &_textures[0]);     glbindtexture(gl_texture_2d, _textures[0]);     gltexparameteri(gl_texture_2d, gl_texture_mag_filter, gl_linear);     gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_linear);     gltexparameterf(gl_texture_2d, gl_texture_wrap_s, gl_clamp_to_edge);     gltexparameterf(gl_texture_2d, gl_texture_wrap_t, gl_clamp_to_edge);     glenable(gl_texture_2d);     gluniform1i(glgetuniformlocation(_program, "t_texture_uv"), 0);      glteximage2d(gl_texture_2d,                  0,                  gl_luminance,                  16,                  8,                  0,                  gl_luminance,                  gl_unsigned_byte,                  uvbuf);        _uniformmatrix = glgetuniformlocation(_program, "proj_matrix");     glfloat modelviewproj[16];     mat4f_loadortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, modelviewproj);     gluniformmatrix4fv(_uniformmatrix, 1, gl_false, modelviewproj);      //draw rect     glvertexattribpointer(attrib_vertex, 2, gl_float, 0, 0, _vertices);     glenablevertexattribarray(attrib_vertex);      //attrib_texturepositon     glvertexattribpointer(attrib_uv, 2, gl_float, 0, 0, texcoords);     glenablevertexattribarray(attrib_uv);      gldrawarrays(gl_triangle_strip, 0, 4);      glreadpixels(0, 0, uvwidth, uvheight, gl_color_attachment0, gl_unsigned_byte, &ubufout);     glreadpixels(0, 0, uvwidth, uvheight, gl_color_attachment0+1, gl_unsigned_byte, &vbufout);       nslog(@"complete");  } 

can shed light on how retrieve gl_fragdata buffers?


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -