OpenGL selected depth testing -


i'd implement opengl scene (opengl es 2.0) in depth testing enabled between selected triangles.

to more specific: suppose have 4 triangles render. depth testing should enabled between triangles 1 , 2, between triangles 3 , 4, neither between triangles 1 , 3 nor triangles 2 , 4.

in other words: possible enable depth testing within 2 pairs of triangles not between them (to improve performance when rendering sequence of 2 pairs can calculated more on software level?

according opengl.org faq (see bottom of page - 12.080), scene can divided regions purpose, description doesn't go enough detail me comprehend how achieved.

a couple of possibilities come mind.

clear depth buffer multiple times per frame

the easiest approach clear depth buffer after rendered 1 group of objects. case in question:

glclear(gl_color_buffer_bit | gl_depth_buffer_bit); // draw triangle 1. // draw triangle 2. glclear(gl_depth_buffer_bit); // draw triangle 3. // draw triangle 4. 

since won't have depth testing between 1/2 , 3/4, triangles 3 , 4 drawn on top of triangles 1 , 2 if overlap, independent of relative depth.

one restriction of solution have draw geometry each group together. example, couldn't use if reason rendering triangles in order 1, 3, 2, 4.

fbo rendering multiple depth buffers

another option use multiple depth buffers. way using off-screen rendering fbos. in case, can create multiple depth renderbuffers. before each draw call, can attach depth buffer can use fbo.

after finished rendering frame fbo, have copy content default framebuffer.

this has advantage can draw triangles in order long switch depth buffer each time:

glframebufferrenderbuffer(gl_draw_framebuffer, gl_depth_attachment,                           gl_renderbuffer, depthbuf1); // draw triangle 1 glframebufferrenderbuffer(gl_draw_framebuffer, gl_depth_attachment,                           gl_renderbuffer, depthbuf2); // draw triangle 3 glframebufferrenderbuffer(gl_draw_framebuffer, gl_depth_attachment,                           gl_renderbuffer, depthbuf1); // draw triangle 2 glframebufferrenderbuffer(gl_draw_framebuffer, gl_depth_attachment,                           gl_renderbuffer, depthbuf2); // draw triangle 4 

however, switching render buffers can expensive operation, still want minimize how many times switch depth buffer.

so approach gives more flexibility, expect less efficient. still need clear depth buffers, have multiple depth clear operations in first approach. in addition, have overhead switching depth buffers, , copying color buffer default framebuffer @ end of frame.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -