Sophie

Sophie

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

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: 4.15.6 Procedural Texture System</title>

<meta name="description" content="Crystal Space 1.2.1: 4.15.6 Procedural Texture System">
<meta name="keywords" content="Crystal Space 1.2.1: 4.15.6 Procedural Texture System">
<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="ProcTextures"></a>
<a name="0"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="Sequence-Manager.html#0" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="Map-Loader.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="Using-Crystal-Space.html#0" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="Animation.html#0" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Working-with-Engine-Content.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">
<h3 class="subsection"> 4.15.6 Procedural Texture System </h3>

<p>Crystal Space supports procedural textures.  These are textures that you can
change dynamically (at runtime) so that you get the appearance of an
animated texture.
</p>
<p>The current implementation of procedural textures works by rendering
the contents of the texture on screen and then doing a copy to the
texture memory.  This means that procedural textures must be updated before
the 3D view starts rendering and it also means that the 3D view must make
sure that that part of the screen is changed (i.e. either put geometry
there or manually clear screen every frame).  Note that all textures
can be updated with this technique. i.e. you don't need to mark a texture
as being procedural.
</p>
<a name="1"></a>
<h4 class="subsubheading"> Updating a Texture Image with 2D and 3D graphics </h4>

<p>The following code demonstrates how you can update a texture image:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">  bool UpdateTexture (iTextureWrapper* tex)
  {
    g3d-&gt;SetRenderTarget (tex-&gt;GetTextureHandle ());
    if (!g3d-&gt;BeginDraw (CSDRAW_2DGRAPHICS)) return false;
    ...
    // Do various operations on g2d.
    ...
    g3d-&gt;FinishDraw ();
    return true;
  }
</pre></td></tr></table>
<p>Similarly, it is also possible to do 3D graphics on a procedural texture. 
</p>
<p>Note that the code above may overwrite what is currently displayed on screen!  
So make sure to do it before anything you need is rendered.
</p>
<p><code>SetRenderTarget</code> also has a second parameter which is called
<samp>&lsquo;persistant&rsquo;</samp> and which is set to false by default.  If you set this to
true then the previous contents of the texture is copied on screen first.
That means you can make modifications to an existing texture.  With this
parameter set to false (default) you have to create the entire texture
again.  Note that setting <samp>&lsquo;persistant&rsquo;</samp> to true is slower if you intend
to update the entire texture area anyway.
</p>
<a name="2"></a>
<h4 class="subsubheading"> Updating a Texture Image with <small>RGBA</small> Pixel Data </h4>

<p>Another way to realize procedural textures is to use the function 
<code>iTextureHandle-&gt;Blit()</code> which can copy a <small>RGBA</small> or <small>BGRA</small> buffer 
from memory directly to a texture.  This is useful for procedural textures 
where you compute the pixel data directly or obtain it from some external 
source and hence don't need the 2D or 3D graphics functions.
</p>
<a name="3"></a>
<h4 class="subsubheading"> Using csProcTexture </h4>

<p>In the <samp>&lsquo;cstool&rsquo;</samp> module there is a convenience class you can use
to make updating of procedural textures easier.  This class is called
<code>csProcTexture</code>.  Basically you make a subclass of this class like this:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">#include &quot;cstool/proctex.h&quot;
class MyProcTexture : public csProcTexture
{
public:
  MyProcTexture () { }
  virtual ~MyProcTexture () { }
  virtual bool PrepareAnim ();
  virtual void Animate (csTicks current_time);
};

bool MyProcTexture::PrepareAnim ()
{
  if (anim_prepared) return true;
  if (!csProcTexture::PrepareAnim ()) return false;
  ...
  // Do your stuff.
  return true;
}

void MyProcTexture::Animate (csTicks current_time)
{
  g3d-&gt;SetRenderTarget (...);
  ...
  g3d-&gt;FinishDraw ();
}
</pre></td></tr></table>
<p>To use this procedural texture you must do the following:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">  MyProcTexture* proctex = new MyProcTexture ();
  if (proctex-&gt;Initialize (object_reg))
  {
    iTextureWrapper* txt = proctex-&gt;GetTextureWrapper ();
    iMaterialWrapper* mat = engine-&gt;CreateMaterial (&quot;mymaterial&quot;, txt);
    ...
  }
</pre></td></tr></table>
<p><code>csProcTexture</code> will make sure that your <code>Animate</code> routine
is called when needed.  In practice this means that your animate routine
will be called <small>AFTER</small> the first time the texture was needed.  This is
because <code>Animate</code> will change the display (because procedural textures
render on screen) so it can't be done while rendering other objects.  In
general this is not really a problem since typically the material will be
needed as soon as only a tiny part of the object is visible and this will
only be visible for one frame.
</p>
<p>To minimize the impact of this effect you can make sure that the initial
contents of the procedural texture is reasonable.  You can do that by
manually calling <code>Animate</code> for example.
</p>
<p>Another way to fix this is by letting your procedural texture subclass
set the <samp>&lsquo;always_animate&rsquo;</samp> flag to true.  Of course this will make
things slower.
</p>
<a name="4"></a>
<h4 class="subsubheading"> Performance Hints </h4>

<p>When supported by the hardware, mipmaps are generated for procedural textures.
While this improves the display quality it may have a noticeable impact on
performance. You can use the <code>CS_TEXTURE_NOMIPMAPS</code> texture flag to 
disable this behaviour.
</p>
<p><code>iTextureHandle-&gt;Blit()</code> performance might differ depending on hardware
and data format.  For example, <small>NVIDIA</small> hardware is fastest with <small>BGRA</small>
data but may suffer greatly when using <small>RGBA</small> data.  On the other hand,
documentation from <small>ATI</small>'s Software Development Kit suggests that modern
<small>ATI</small> hardware supports <small>RGBA</small> and <small>BGRA</small> equally well.  This means
there is no &ldquo;universal fastest format&rdquo; for using 
<code>iTextureHandle-&gt;Blit()</code>, albeit for the most widespread graphics chips
<small>BGRA</small> seems to be the most practical choice.
</p>

<hr size="1">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="Sequence-Manager.html#0" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="Map-Loader.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="Using-Crystal-Space.html#0" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="Animation.html#0" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Working-with-Engine-Content.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>