Rendering Static and Dynamic Graphics OpenGL -
i working on ios game using opengl pipeline. have been able render graphics want screen, however, calling gldrawelements
many times , have concerns running performance issues eventually. have several static elements in game not need render on every render cycle. there way can render static elements 1 frame buffer , dynamic elements another?
here's code have tried:
static bool renderthisframebuffer = yes; if (renderthisframebuffer) { glbindframebuffer(gl_framebuffer, interframebuffer); glclearcolor(0.0f, 0.0f, 0.0f, 0.0f); glclear(gl_color_buffer_bit | gl_depth_buffer_bit); glblendfunc(gl_src_alpha, gl_one_minus_src_alpha); glenable(gl_blend); glenable(gl_depth_test); // set projection matrix cc3glmatrix *projection = [cc3glmatrix matrix]; float h = 4.0f * openglview.frame.size.height / openglview.frame.size.width; [projection populatefromfrustumleft:-2 andright:2 andbottom:-h/2 andtop:h/2 andnear:4 andfar:50]; gluniformmatrix4fv(projectionuniform, 1, 0, projection.glmatrix); glviewport(0, 0, openglview.frame.size.width, openglview.frame.size.height); (boardspace *boardspace in spacearray){ [boardspace drawwithmatrix:modelview]; } [context presentrenderbuffer:gl_renderbuffer]; glbindframebuffer(gl_framebuffer, constframebuffer); renderthisframebuffer = false; }
in case have created 2 frame buffers previously: interframebuffer
static elements , constframebuffer
dynamic elements. missing something?
it should possible. straightforward approach render static elements fbo once. on each redraw, copy content of static fbo default framebuffer, , draw dynamic elements on top of it.
the feature set of es 2.0 kind of borderline support this. example, don't have glblitframebuffer()
, convenient way copy fbo content default framebuffer. can copy simple shader program feeds through coordinates in vertex shader, , uses texture sample operation in fragment shader. bind texture rendered static content to, , draw screen sized quad.
it gets more tricky if dynamic rendering needs depth buffer static rendering. example case if dynamic content obscured static content. in case, need copy depth buffer. refreshing memory of specs, don't see make possible in es 2.0. glblitframebuffer()
not there. , looks es 2.0 not support depth textures. you're entering es 3.0 territory if want go there.
with of this, want make sure helps performance. copying framebuffer not free. pays off if it's cheaper rendering static elements. benchmarking of both approaches in order before make decision.
Comments
Post a Comment