Thread: DirectX8: Render Only Portions of Screen?

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    361

    DirectX8: Render Only Portions of Screen?

    Hullo all

    I'm curious about rendering when it comes to updating the screen for an application. For simplicity, let's say I'm making a game (see attatchment below).

    The middle portion is the actual screen. So every frame something new is there, hence, I need to refresh everything every frame. But, the buttons/border around the middle rarely (if ever) change.

    While learning DirectX, I noticed that in the code:
    D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    There is a "Target" you can clear.

    I was wondering, if this means I can make two (in DirectX7 terms) surfaces. I.e. one for the Scene Rendering, and another for the border. And Render to the Scene's Surface every time, but only Call a Second Render Procedure (that of my border) when an event triggers the need for re-drawing?

    My concern is that redrawing a border that doesn't need to be redrawn is a waste of time.

    I hope I've made what I'm asking understandable Any input/ideas/better methods of solving this are definitely appreciated

    Thanks for now

    Edit: I missed a bracket on that picture, ah well And those squiggly things are trees (meant to represent a part of the scene )

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Yes it is possible to do what you want. However, I don't think your method is faster than one complete blit of the screen.

    In a double buffering setup you draw everything to the double buffer and then copy the double buffer contents over to the primary buffer or the screen.

    push ds
    lds esi,[DoubleBuffer]
    les edi,[Screen]
    mov cx,[SizeOfScreenInDWORDS]
    rep stosd

    As well if this function is supported in hardware, you will gain the advantage of video acceleration which probably supports 64 to 128 bit blits depending on the board architecture and AGP setup. If the card does the blit, the CPU does not have to - extremely fast.

    But in your case you are wanting to draw from 2 buffers to place them into one and then blit each one seperately. This will most definitely be slower simply because 2 blits are always going to be slower than 1 - twice as many instructions - at best.

    Best bet is to place everything in the secondary buffer, including your not oft updated menu items, and then blit the entire thing using DirectX8Surface->Flip();

    For instance, in a shooter, even though the player is not moving the screen is redrawn at least 60 times per second - waste of time yes....but its so fast who cares. Most video cards will blit so fast you can write crappy code and it will still get good frame rates.

    So draw the whole thing every frame. You may not realize it, but it can actually be slower blitting a portion of the screen than blitting the whole thing. Not always true - but blitting a portion of the screen always requires several extra instructions. Granted the blit string will be shorter thus resulting in a fast blit, but sometimes the extra instructions to get the blit to stay within your 'window' make up the difference in cycles.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    Okie dokes Thanks for the tip Bubba.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Render text
    By Livijn in forum C++ Programming
    Replies: 6
    Last Post: 07-06-2007, 03:32 PM
  2. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  5. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM