Compositor System

The compositor is a system that renders every screen one after another and then overlays each screen into a single image. Even the main 3D view rendered from the camera is a screen for the compositor.

Take the image below as an example, you have 5 "Screens" rendering, the main 3D view, the FPS counter, the statistics (under the FPS counter), the instructions (under the statistics), and the engine logo. Any of the screens can be toggle on or off at any time.


Creating an IScreen

Creating an IScreen is very simple.

  • Make the class that you want to do rendering, derive from IScreen.
  • Handle all of the methods in IScreen. Most important the DrawScreen method is where you handle rendering for your class.
    • Generally you'll use IScreens to render 2D things like text, or other sprites you need to render. 3D rendering is handled by the GraphicsSystem, which is called from the SceneManager (which is an IScreen).
  • Make sure to add your screen to the compositor's draw chain. Your 'Game' class has an instance of Compositior. You'll need to call Compositor.InsertScreen() to add your screen. For example this is how it is done in the Sample Demo:
    // ============================================================            
    // Set up screen compositor
    this.Compositor.InsertScreen(new FPSScreen(10, 10, this), false);
    this.Compositor.InsertScreen(new QuickStartLogoScreen(false, false, 10, 150), false);
    this.Compositor.InsertScreen(new StatsScreen(this.Settings.Resolution.X - 330, 17, this), false);
    this.Compositor.InsertScreen(new InstructionsScreen(8, 37, this), false);
    // ===========================================================

    // This is the screen that renders the 3D world
    this.Compositor.InsertScreen(this.SceneManager, true);

  • The screens will render in the order they're inserted. Generally the order won't matter unless you have overlapping elements.
    • Setting the second parameter to InsertScreen() to true will cause it to insert at the head of the list. So in the above example the SceneManager is going to be at the head of the list, which means it will render first, and all other screens will render on top of it. You'll almost always want your SceneManager to be at the head of the list, otherwise your other screens may render behind the 3D world and never be seen.
    • The exception to the render order is GUI elements. The GUI system handles its own render order so the window overlapping acts like a standard GUI, where if someone clicks on a window it draws on top of other windows. It also allows the GUI system to make optimizations by not drawing elements of windows that will be unseen due to other windows overlapping them.
      • GUI elements are rendered by the GraphicsSystem, and are rendered after the rest of the 3D world has rendered. Since GUI is rendered immediately after 3D, that means any screens you have rendering non-GUI should render on top of any GUI you may have.
  • To turn off a screen you simply call this.Compositor.RemoveScreen(), and supply either the name of the screen, or the screen reference itself.
    • If you plan on turning a screen off/on, make sure you keep a reference to the screen around or when you turn it off you'll lose it forever. For example:
      IScreen fpsScreen = new FPSScreen(10, 10, this);
      this.Compositor.InsertScreen(fpsScreen, false);

      // Now you can remove the screen and re-insert it at a later time

      this.Compositor.InsertScreen(fpsScreen, false); 

Last edited Jan 12, 2012 at 3:29 PM by LordIkon, version 7


No comments yet.