Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bad97183153701b09df5fae1052b1c30 > files > 4279

crystalspace-doc-1.2.1-5mdv2010.0.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created by texi2html 1.76 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people <dev@texi2html.cvshome.org>
Send bugs and suggestions to <users@texi2html.cvshome.org>

-->
<head>
<title>Crystal Space 1.2.1: 6.4 Rendering Loop</title>

<meta name="description" content="Crystal Space 1.2.1: 6.4 Rendering Loop">
<meta name="keywords" content="Crystal Space 1.2.1: 6.4 Rendering Loop">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.76">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="Rendering-Loop"></a>
<a name="0"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="Engine-Internal-Workings.html#0" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="Contributing.html#0" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="Internals.html#0" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="Internals.html#0" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Contributing.html#0" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="cs_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="cs_Index.html#0" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="cs_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<hr size="1">
<h2 class="section"> 6.4 Rendering Loop </h2>


<p><em>Written by Jorrit Tyberghein,
<a href="mailto:jorrit.tyberghein@gmail.com">jorrit.tyberghein@gmail.com</a>.</em>
</p>
<p>Here is a short run-through of the main rendering loop.  This document is not an
explanation of portal technology.  It just explains how the main rendering
loop in Crystal Space works so that you can have a quick idea of where you
have to go to see a particular part of the algorithm work.  This is a rather
technical document and not intended for people who are only interested in
using Crystal Space in their own projects.  It is intended for people who want
to know how Crystal Space works internally.
</p>
<p>To understand this you should know how portals are used in Crystal Space.  You
should also read the tutorial (see section <a href="Tutorial-Simple.html#0">Simple Tutorial 1: Basic Setup, World Creation</a>) as this explains the
basics for using Crystal Space.  This document is based upon the
<tt>&lsquo;simple&rsquo;</tt> application (<tt>&lsquo;CS/apps/tutorial/simple1/&rsquo;</tt>) because this
discussion looks a lot like a tutorial.
</p>
<p>First we start in <tt>&lsquo;apps/tutorial/simple1/simple1.cpp&rsquo;</tt>.  In the
<code>main()</code> function we initialize our engine.  This is an instance of the
plugin <samp>&lsquo;iEngine&rsquo;</samp> which actually represents the engine.  I will not
explain how all the initialization works.  This is explained in the tutorial.
But I will go straight to <code>iEngine::Draw()</code> which is called indirectly
from within <code>Simple::NextFrame()</code>.  It is called indirectly because first
we call <code>iView::Draw()</code> which then calls <code>iEngine::Draw()</code>.
</p>
<a name="1"></a>
<h3 class="subheading"> World Rendering (<code>iEngine::Draw()</code>) </h3>

<p>The method <code>iEngine::Draw()</code> is located in
<tt>&lsquo;CS/plugins/engine/3d/engine.cpp&rsquo;</tt>.
</p>
<p><code>iEngine::Draw()</code> first sets up the initial <samp>&lsquo;iRenderView&rsquo;</samp>
structure.  This structure is defined in
<tt>&lsquo;CS/include/iengine/rview.h&rsquo;</tt> and is the main structure which is
used throughout the entire rendering process.  It collects all data that
is required for rendering the recursive portal structure.
</p>
<p>Basically, it contains the following information:
</p>
<dl compact="compact">
<dt> <code>view</code></dt>
<dd><p>This is the current clipper.  A clipper is a 2D polygon which defines what is
visible.  Every object is clipped to the view first.  Every time we go through
a portal the view is modified.
</p>
</dd>
<dt> <code>g3d</code></dt>
<dt> <code>g2d</code></dt>
<dd><p>These are pointers to our 3D and 2D graphics subsystems.
</p>
</dd>
<dt> <code>clip_plane</code></dt>
<dd><p>This is a special plane.  If <samp>&lsquo;do_clip_plane&rsquo;</samp> is used then we clip all
geometry in 3D to <samp>&lsquo;clip_plane&rsquo;</samp>.  This is normally not used except in
special cases where we have portals that arrive in the middle of a sector.  In
that case the portal will be used as an extra clipping plane because we don't
want to render everything that is behind the arrival plane of the portal.
</p></dd>
</dl>

<p>Another important thing is that <samp>&lsquo;iRenderView&rsquo;</samp> is actually a subclass of
<samp>&lsquo;iCamera&rsquo;</samp> (<tt>&lsquo;CS/include/iengine/camera.h&rsquo;</tt>) so all camera
functionality is present as well.
</p>
<p>To set up the initial <samp>&lsquo;iRenderView&rsquo;</samp> structure <code>iEngine::Draw()</code>
creates a new instance based upon the given camera.
</p>
<p>After this <code>iEngine::Draw()</code> gets the current sector from the camera and
calls <code>iSector::Draw()</code> (<tt>&lsquo;CS/plugins/engine/3d/sector.cpp&rsquo;</tt>).  This
will essentially draw the whole screen as discussed below.
</p>
<p>After doing this (now that the screen is fully updated) we optionally draw
halos.  Halos are drawn on top of everything else since they are an effect in
the eyes.
</p>
<a name="2"></a>
<h3 class="subheading"> Sector Rendering (<code>iSector::Draw()</code>) </h3>

<p>This method <code>iSector::Draw()</code> is located in
<tt>&lsquo;CS/plugins/engine/3d/sector.cpp&rsquo;</tt>.
</p>
<p><code>iSector::Draw()</code> is responsible for rendering everything in the current
sector. Before it does that it will ask the current visibility culler
(<samp>&lsquo;frustvis&rsquo;</samp> or <samp>&lsquo;dynavis&rsquo;</samp>) what objects are likely to be visible
or not. It will then render all visible objects sorted by render priority
(see section <a href="HOWTO-Render-Priorities.html#0">Render Priorities and Objects in Sectors</a>) and using the z-buffer mode that is
associated with every object. It is up to the map designer to make sure
that the objects in their render priority and z-buffer mode will actually
cause the sector to be rendered ok.
</p>
<p>Every object that is rendered will get the current camera transformation
so it can correctly transform its coordinates from world to camera space:
(0,0,0) is the camera pointer, (1,0,0) is one to the right, (0,1,0) is one
unit above the camera, and (0,0,1) is one unit in front of the camera.
</p>
<p>Every object also gets the current movable (<code>iMovable</code>) which indicates
where the object currently is in the world. The transform created from
the camera and the movable can be used to transform from object space
to camera space. Note that some objects leave this transformation up to
the 3D renderer which is good because that means hardware accelerated
transforms can be used.
</p>
<p>Every mesh object is responsible for drawing itself (see section <a href="MeshObject.html#0">Mesh Object Plug-In System</a>).
The engine decides when to render an object, the object decides on how
to render itself. Finally the 3D renderer will process the actual rendering
operations done by the mesh object.
</p>
<p>The <samp>&lsquo;thing&rsquo;</samp> mesh object type supports portals. When such a thing containing
a portal is rendered the destination sector will be rendered recursively.
This means that rendering of the current sector will be temporarily
suspended while first the destination sector through that portal is rendered.
Going through a portal results in the current <samp>&lsquo;iRenderView&rsquo;</samp>
instance to get a new clipper (a smaller clipper usually). Objects can use
that clipper to decide if they want to be rendered or not. In some special
cases a portal can also transform space (like a mirror). In that case the
world=&gt;camera transformation will also be modified in the current
<code>iRenderView</code>.
</p>
<p>When a sector has finished rendering we conclude by optionally fogging the
current sector if this is needed.
</p>


<hr size="1">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="Engine-Internal-Workings.html#0" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="Contributing.html#0" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="Internals.html#0" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="Internals.html#0" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Contributing.html#0" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="cs_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="cs_Index.html#0" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="cs_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
 <font size="-1">
  This document was generated using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>.
 </font>
 <br>

</p>
</body>
</html>