Bit help to improve my Offscreen renderer?

Started by
3 comments, last by zico 17 years, 1 month ago
Hello I am porting an old game and currently I try to get some stuff working with OpenGL. I wrote an Offscreen renderer for some special parts, but I fear this code is still too slow and sometimes it creates some ugly glitches with several graphic cards settings. I am still sort of a Noob in OpenGL (have not much time to care about it as I would wish to) and I hope someone may be able to help. this is the code for now: GLubyte *pixels = NULL; void ogl_start_offscreen_render(int x, int y, int w, int h) { int y2; if (offscreen_canv) Error("ogl_start_offscreen_render: offscreen_canv!=NULL"); offscreen_save_canv = grd_curcanv; glDrawBuffer(GL_BACK); offscreen_canv = gr_create_sub_canvas(grd_curcanv, x, y, w, h); gr_set_current_canvas(offscreen_canv); y2 = last_height - offscreen_canv->cv_bitmap.bm_y - offscreen_canv->cv_bitmap.bm_h; glReadPixels(offscreen_canv->cv_bitmap.bm_x,y2,w,h,GL_RGBA,GL_UNSIGNED_BYTE,pixels); } void ogl_end_offscreen_render(void) { int y; if (!offscreen_canv) Error("ogl_end_offscreen_render: no offscreen_canv"); glDrawBuffer(GL_FRONT); glReadBuffer(GL_BACK); glDisable(GL_TEXTURE_2D); y = last_height - offscreen_canv->cv_bitmap.bm_y - offscreen_canv->cv_bitmap.bm_h; glRasterPos2f(offscreen_canv->cv_bitmap.bm_x/(float)last_width, y/(float)last_height); glDrawPixels(offscreen_canv->cv_bitmap.bm_w, offscreen_canv->cv_bitmap.bm_h,GL_RGBA,GL_UNSIGNED_BYTE,pixels); gr_free_sub_canvas(offscreen_canv); gr_set_current_canvas(offscreen_save_canv); offscreen_canv=NULL; } I suspect, that glDrawPixels is very slow but I am not sure where the glitches may come from. Here is an example image (I hope this works this way): http://www.descentforum.de/forum/useruploads/scrn0000.jpg Thanks :)
Advertisement
Why do you need copy whole buffer to you local memory and then draw it back??If you not using any kind of special effects you can just load everything you need as textures.. And ofcourse problem is in readpixels/drawpixels, because each call makes ur card transfer GPU memory to local memory and back.
Okay admitted, this is sorta hack.
On that screen you see a spinning object. I just try to prevent the flickering since this animation is not going trough the backbuffer.

EDIT: Probably I should also say that this code is a leftover from this unfinished port I just continue. Probably I should solve that whole problem in a different order.

[Edited by - zico on March 4, 2007 3:44:04 PM]
You could use FBOs or pbuffers for offscreen rendering so that you could eliminate making a copy of the backbuffer and restoring it back. Most likely, glReadPixels is the one that is bringing down your performance.
I now moved on to solve this problem from another side.


the code looks about this:

briefing()
{

draw_briefing_bitmap();

while (!key_pressed())
rotate_object();

}

All this "briefing" stuff normally gets drawed one time on the FRONT-buffer.

This way the object shown with rotate_object() flickers very heavy due to the clearing of the canvas it get's drawn to.

So I made the following (note again: I am still a noob):

while (!key_pressed()) {
glDrawBuffer(GL_BACK);
rotate_object();
SDL_GL_Swap_buffers();
}

glDrawBuffer(GL_FRONT);

This now works outstanding ... but with one single problem:
the briefing bitmap, that is shown above disappears from the screen. That is already the point that I am out of ideas again. :/

The code itself is a bit more complex and all the functions are very seperated. I would probably think I need to call draw_briefing_bitmap() withing this while loop, but is it also possible, to get it stored and shown otherwise?


EDIT:

Ah, I see now. I solved it. :)

All my menus are drawn by glDrawBuffer(GL_FRONT).
I now changed this at init to GL_BACK, flip at drawing and done. :)

[Edited by - zico on March 8, 2007 11:14:37 AM]

This topic is closed to new replies.

Advertisement