[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.9.1 Render Priorities and Objects in Sectors

Renderpriorities give the map creator some extra control over when objects have to be rendered. In this section the basic rendering algorithm is explained. This is a more theoretical explanation. Later some examples are given of some commonly used configurations.

Meshes and Sectors

One of the most fundamental concepts in Crystal Space is a sector (interface iSector). A sector is basically empty space which needs to be filled with geometry.

To put geometry in a sector you use one or more mesh objects (see section Mesh Object Plug-In System). Note that a mesh object can also be in several sectors at once. This happens when some object is busy traversing some portal from one sector to another. The list of sectors that a mesh object is in and also the position (i.e. transform) is kept by an instance of iMovable (see section Mesh Movement).

Render Priorities

The engine supports the notion of render priorities. There is usually a limited set of render priority slots available. By default these are:

  1. `sky'
  2. `portal'
  3. `wall'
  4. `object'
  5. `alpha'

But you can setup your own render priorities. Objects which are in a lower render priority (i.e. `sky' is lower than `wall') will be rendered before objects with a higher priority. So using the render priority system you can choose in which order to render objects.

To set up render priorities from within a map file you can use the following construct:

 
<renderpriorities>
  <priority name="sky">
    <level>1</level>
    <sort>NONE</sort>
  </priority>
  <priority name="portal">
    <level>2</level>
    <sort>NONE</sort>
  </priority>
  <priority name="wall">
    <level>3</level>
    <sort>NONE</sort>
  </priority>
  <priority name="object">
    <level>4</level>
    <sort>NONE</sort>
  </priority>
  <priority name="alpha">
    <level>5</level>
    <sort>BACK2FRONT</sort>
  </priority>
</renderpriorities>

This example sets up the render priorities like they are by default. The first number for every render priority is the priority itself. This should be a low number to avoid having a render priority table that grows too big (every sector will have such a table). The second parameter is a keyword that indicates the order in which objects of that priority will be rendered. By default this is `NONE' which means no special sorting will happen. At this moment no other options are implemented but in the future you will be able to choose from:

For the `alpha' render priority (which is usually used by transparent objects) you should use `BACK2FRONT'.

To set up render priorities from within your application you can use the following:

 
engine->RegisterRenderPriority ("wall", 2);

This will setup a render priority named `wall' with numeric value 2. If there is already a render priority with that name then the render priority will be replaced. The engine will keep track of the render priorities named `wall', `sky', `object', and `alpha'.

To set the render priority for an object you can use the following in a map file:

 
<meshobj name="myObject">
  <plugin>...</plugin>
  <params>
    ...
  </params>
  <priority>object</priority>
</meshobj>

To set the render priority from within the code you can do:

 
iMeshWrapper* mesh;
mesh->SetRenderPriority (engine->GetRenderPriority ("object"));

By default objects will be put in the `object' render queue.

Z-Buffer Render Mode

In addition to render priorities you can also choose how the object will be rendered with regards to the Z-buffer. There are four possibilities:

To set the Z-buffer mode from a map file you can do the following:

 
<meshobj name="myObject">
  <plugin>...</plugin>
  <params>
    ...
  </params>
  <priority>object</priority>
  <zuse />
</meshobj>

To set the Z-buffer mode from the code you can use the following example:

 
  iMeshWrapper* mesh;
  mesh->SetZBufMode (CS_ZBUF_USE);

`ZUSE' is the default Z-buffer mode for objects created from within an application.

By using the z-buffer mode in combination with the render priorities we now have a very powerful system to control object rendering in a sector. In the following sections we will show some popular examples. But first we show in a table what the common usage is of the render priorities in combination with the Z-buffer modes:

Multiple Layers of Sky

The `sky' render priority queue is really only suitable for one sky layer (i.e. one skybox or one skydome). But it is possible to have two or more layers by using multiple sky priority queues (i.e. `sky1' and `sky2'). In the first sky queue you put an object with `ZFILL' or `ZNONE' Z-buffer mode. In the second sky queue you put a semi-transparent object using `ZNONE' mode (there is no need to either check or update the Z-buffer for the second object).

Note that sky objects are usually created with the `CAMERA' keyword (in map file) or the CS_ENTITY_CAMERA flag (in iMeshWrapper::GetFlags()). The camera keyword makes sure that the camera will always be in the center of that object. So you can move forever in some direction without ever reaching the bounds of the sky.

Include Files

The include files useful for this section are:

 
#include <iengine/mesh.h>
#include <iengine/sector.h>
#include <iengine/engine.h>
#include <ivideo/graph3d.h>

[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated using texi2html 1.76.