Read the depth buffer of OpenGL ES on Android -


i trying read depth buffer in opengl es on android, values zero. can explain why that.

    public void onsurfacechanged(gl10 unused, int width, int height) {     // adjust viewport based on geometry changes,     // such screen rotation     gles20.glclearcolor(0.0f, 0.0f, 1.0f, 1.0f);     gles20.glcleardepthf(1.0f);     gles20.glclear(gles20.gl_color_buffer_bit | gles20.gl_depth_buffer_bit);      gles20.glenable(gles20.gl_depth_test);     gles20.gldepthmask( false );      gles20.glviewport(0, 0, width, height);      float ratio = (float) width / height;      // projection matrix applied object coordinates     // in ondrawframe() method     matrix.frustumm(mprojectionmatrix, 0, -ratio, ratio, -1, 1, 4, 9); } 

read depth buffer:

        floatbuffer buffer = floatbuffer.allocate(720*945);     gles20.glreadpixels(0, 0, 720, 945, gles20.gl_depth_component, gles20.gl_float, buffer);     float[] depth = buffer.array();     (int = 0; < 720*945; i++){             log.i("depth", ""+depth[i]);     } 

the model has been draw on screen: screenshot

edit

i moved project es 3.0. create framebuffer, color , depth texture , attach.i error gl_framebuffer_incomplete_attachment

 gles30.glenable(gles30.gl_texture_2d);      gles30.glgentextures(1, colortex, 0);     gles30.glbindtexture(gles30.gl_texture_2d, colortex[0]);     gles30.gltexparameteri(gles30.gl_texture_2d, gles30.gl_texture_wrap_s, gles30.gl_clamp_to_edge);     gles30.gltexparameteri(gles30.gl_texture_2d, gles30.gl_texture_wrap_t, gles30.gl_clamp_to_edge);     gles30.gltexparameteri(gles30.gl_texture_2d, gles30.gl_texture_mag_filter, gles30.gl_nearest);     gles30.gltexparameteri(gles30.gl_texture_2d, gles30.gl_texture_min_filter, gles30.gl_nearest);     gles30.glteximage2d(gles30.gl_texture_2d, 0, gles30.gl_rgba, fbowidth, fboheight, 0, gles30.gl_rgba, gles30.gl_float, null);      gles30.glgentextures(1, depthtex, 0);     gles30.glbindtexture(gles30.gl_texture_2d, depthtex[0]);     gles30.gltexparameteri(gles30.gl_texture_2d, gles30.gl_texture_wrap_s, gles30.gl_clamp_to_edge);     gles30.gltexparameteri(gles30.gl_texture_2d, gles30.gl_texture_wrap_t, gles30.gl_clamp_to_edge);     gles30.gltexparameteri(gles30.gl_texture_2d, gles30.gl_texture_mag_filter, gles30.gl_nearest);     gles30.gltexparameteri(gles30.gl_texture_2d, gles30.gl_texture_min_filter, gles30.gl_nearest);     gles30.glteximage2d(gles30.gl_texture_2d, 0, gles30.gl_depth_component24, fbowidth, fboheight, 0, gles30.gl_depth_component, gles30.gl_float, null);       gles30.glgenframebuffers(1, fb, 0);     gles30.glbindframebuffer(gles30.gl_framebuffer, fb[0]);      gles30.glframebuffertexture2d(gles30.gl_framebuffer, gles30.gl_color_attachment0, gles30.gl_texture_2d, colortex[0], 0);      checkstatus("color test");      gles30.glframebuffertexture2d(gles30.gl_framebuffer, gles30.gl_depth_attachment, gles30.gl_texture_2d, depthtex[0], 0);      checkstatus("depth test");  } 

q1: how can resolve above error?

q2: how check depth value in depth texture

opengl es not support glreadpixels() on depth buffer. if call glgeterror() after glreadpixels() call, should see gl_invalid_operation returned.

i found vendor specific extension functionality: nv_read_depth_stencil. functionality still not standard in latest es spec (3.2).

other extension, can't think of way reading depth values in es 2.0.

in es 3.0 , later, there @ least indirect way. these versions support depth textures. using this, can depth using following steps.

  1. render scene fbo, using texture depth attachment.
  2. render screen sized quad shader samples depth texture generated in previous step, , writes value color buffer.
  3. use glreadpixels() on color buffer.

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -