Results 1 to 5 of 5

Thread: ClanLib Layered Window design & performance issues

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009

    Default ClanLib Layered Window design & performance issues

    I'm experimenting with the layered window support and finding that it doesn't seem to "keep up", aka, 30fps, with full screen (1680x1050) flips/updates on midrange graphics hardware. I'm hoping the original designer of this code (or someone who has hacked it) is trolling this board.

    I have a guess as to why the implementation is sluggish, but it's just a theory I'm trying to get to the bottom of.

    I noticed with is_layered() == true a "shadow_window" is created for off-screen rendering and at update time the bits are sucked out of that into a DIB and then shown with the win32 UpdateLayeredWindow call.

    I did some profiling and I believe the "suck out of the shadow window into the DIB" is pretty expensive, probably due to the "one-way" optimization of graphics hardware, i.e., blitting from system RAM into graphics RAM is fast, but the other way ain't so fast. (Just a theory!)

    My question is (and I'll probably experiment with this): Why not render directly into a DIB, and then blit that? My hunch is much higher frame rates will be achievable. I noticed a commented out PFD_DRAW_TO_BITMAP in opengl_creation_helper.cpp so I wondered if someone has experimented with this technique.

    Any comments, tips, or wisdom from prior attempts are *more* than welcome!


  2. #2
    ClanLib Developer
    Join Date
    May 2007


    heh heh, Layered Windows.

    Layered windows will only work with OpenGL V1.1

    So to get it to work with OpenGL 1.3 and higher, we create a shadow window that is rendered to. Then we use OpenGL to get the pixel buffer and copy it to the real window.

    If you want a huge layered window, I would look at what you are trying to draw, and ask yourself, does all of it have to be layered?

    Have a look at the 3rd post at:

    - With an approx 500x500 "window", you can get over 1000fps

    Read that thread, it shows the layered window development history

    ClanLib 2.1.1 contains the two layered window examples

    Note the example was removed because it ran too slow (17fps)

  3. #3
    Master Sorcerer
    Join Date
    Sep 2006


    I'm afraid the PFD_DRAW_TO_BITMAP flag is rather useless because to my knowledge no graphics card out there supports this flag.

    The current strategy where we first render to a GPU frame buffer, then copy it down to the CPU and then send it back to the GPU using GDI naturally includes a lot of overhead. It basically affects the framerate in 3 ways:
    1. We stall the pipeline on the graphics card, because it has to finish all drawing commands on the frame before we can download the frame buffer image.
    2. Bringing down the image takes some time.
    3. Sending the image back up takes some time.

    It has been some time since I've looked at the layered OpenGL code, so I don't know if it currently does the 'pre-multiplied alpha' part on the GPU or the CPU. But if its currently the CPU that does this step, then that can be easilly moved to the GPU by changing the blend mode. If this step is currently done on the CPU, that would make some difference in performance.

    Another possible optimization is to simply not update the entire DIB each time. I.e. the CL_DisplayWindow::update(rect) function could be made so that only the update rectangle is downloaded from GPU memory. That would give better frame rates if the visual changes are local.

    I'm afraid the only other options are to either create a memory DC with an OpenGL context (I don't think that will work) or find some kind of WGL extension to OpenGL that allows us to transfer the image without a DIB.

  4. #4
    Join Date
    Dec 2009

    Thumbs up Got it! Where do I sign up?

    Thanks for the spot-on answers...saved me a lot of fiddling. Also explains why the PFD_DRAW_TO_BITMAP based app I'm porting actually works on VirtualBox VMs with no graphics h/w emulation (and OpenGL 1.3+ does not.)

    As a result I added some things:

    • Finished out the set_window_alpha and colorkey support in win32_window:update_layered() (and supporting functions in Window and Description classes)
    • Added "layered" bit and UpdateLayeredWindow support to GDI windows

    If you're interested I'll clean up my hacks and move them into a checked out branch for contrib...I'm sure there's a doc/article on it, but could you point me at your repo submit procedure, and patch review/test process?



  5. #5
    ClanLib Developer
    Join Date
    May 2007


    It would be interesting to have a look at.

    Attach the patch to this forum. If it's a simple patch, then you can just attach the modified code as text. Else use a patch file


Similar Threads

  1. X windows inside a sdl/clanlib window
    By l3thal in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 12-26-2009, 08:47 PM
  2. New Layered Window Example
    By rombust in forum Official ClanLib SDK Forums
    Replies: 8
    Last Post: 10-12-2009, 03:24 PM
  3. Preview of ClanLib 2.0.3 - Layered Windows In OpenGL
    By rombust in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 06-23-2009, 05:05 PM
  4. Performance Issues in Fedora
    By Starclopsofish in forum Novashell Game Creation System
    Replies: 4
    Last Post: 02-09-2009, 03:32 PM
  5. A patch to ClanLib 8.0: added RichEdit, remaked InputBox and some other issues.
    By ValkaVALES in forum Official ClanLib SDK Forums
    Replies: 7
    Last Post: 07-10-2007, 11:15 PM



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts