Clootie graphics pages - Articles

 CD3DApplication Demystified
  
Contents
  • Introduction
  • Diagram
  • Description
  • Greetings

  • Introduction

    In the newsgroups there have been lots of questions about how to proceed with the initialization in CD3DApplication (derived class CMyD3DApplication as you can see in most of samples).

    Just to note: CD3DApplication class is main "root" component of 3D3DFramework - library of usefull classes which is used by most of the Direct3D SDK samples, including original C++ and ObjectPascal ones.

    The following are some short notes that should help you understand what's going on here. This has been submitted to the DX docs team for the basis of a revised explanation of the sample framework in the next release of the docs (DirectX 9 timeframe).


    Diagram

    I hope this diagram will help you to see in whitch order functions are called and possible transitions between them.

    Diagram
      Legend:
    1. Plain green arrows show "normal" order in witch functions are called
    2. Circle arrow show what transition between FrameMove and Render could happen million times (if app is still running)
    3. Curved arrows shows possible transitions when user (or other system processes) forsed your application: change window size, exit fullscreen mode, change rendering device


    Description

    The following methods are all paired: one for initialization and one for destruction. They represent the different phases of initialization for a D3D application. The phases are as follows.
    Delphi: Create, Destroy
    C++: CMyD3DApplication, ~CMyD3Dapplication
    Object constructor and destructor. Member variables should be initialized to a known state here. The application window has not yet been created and no Direct3D device has been created, so any initialization that depends on a window or Direct3D should be deferred to a later stage.
    OneTimeSceneInit, FinalCleanup
    The window has been created and the IDirect3D8 interface has been created, but the device has not been created yet. Here you can perform application-related initialization and cleanup that does not depend on a device.
    InitDeviceObjects, DeleteDeviceObjects
    The device has been created. Resources that are not lost on Reset() can be created here -- resources in D3DPOOL_MANAGED, D3DPOOL_SCRATCH, or D3DPOOL_SYSTEMMEM. Image surfaces created via CreateImageSurface are never lost and can be created here. Vertex shaders and pixel shaders can also be created here as they are not lost on Reset().
    RestoreDeviceObjects, InvalidateDeviceObjects
    The device exists, but may have just been Reset(). Resources in D3DPOOL_DEFAULT and any other device state that persists during rendering should be set here. Render states, matrices, textures, etc., that don't change during rendering can be set once here to avoid redundant state setting during Render() or FrameMove().
    FrameMove, Render
    Everything is created and we actually are running. FrameMove function should recalculate scene physics, and Render function - actually render it. This division has been done to allow user pause sample and still watch scene rendering.


    Greetings

    Most of this info (except diagram and some additions) was posted by "Rich", frequent contributor of Direct3D newsgroups and author of upcoming book on Direct3D from Addison-Wesley!
    http://www.xmission.com/~legalize/book/


    Please inform me of any grammar or general errors, contained on these pages, Alexey Barkovoy
    Last updated: 12-Jun-2002