<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Crystal Space 1.2.1: csgfx/vertexlistwalker.h Source File (Crystal Space 1.2.1 Public API Reference)</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="head"> <tr height="59"> <td class="head" width="202" valign="bottom" style="padding-left:0;"><a href="http://www.crystalspace3d.org/"><img src="csblur.png" width="236" height="59" alt="CrystalSpace" border="0"></a></td> <td class="head"><h2>Public API Reference</h2></td> </tr> <tr height="11"> <td colspan="2" class="headshadow" valign="top" style="padding-left:0;"><img src="csblurb.png" width="236" height="11" alt="" border="0"></td> </tr> </table> <div class="content"> <!-- Generated by Doxygen 1.5.3 --> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul> </div> <h1>csgfx/vertexlistwalker.h</h1><a href="vertexlistwalker_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> Copyright (C) 2005 by Marten Svanfeldt</span> <a name="l00003"></a>00003 <span class="comment"> (C) 2006 by Frank Richter</span> <a name="l00004"></a>00004 <span class="comment"></span> <a name="l00005"></a>00005 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00006"></a>00006 <span class="comment"> modify it under the terms of the GNU Library General Public</span> <a name="l00007"></a>00007 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00008"></a>00008 <span class="comment"> version 2 of the License, or (at your option) any later version.</span> <a name="l00009"></a>00009 <span class="comment"></span> <a name="l00010"></a>00010 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00011"></a>00011 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00012"></a>00012 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00013"></a>00013 <span class="comment"> Library General Public License for more details.</span> <a name="l00014"></a>00014 <span class="comment"></span> <a name="l00015"></a>00015 <span class="comment"> You should have received a copy of the GNU Library General Public</span> <a name="l00016"></a>00016 <span class="comment"> License along with this library; if not, write to the Free</span> <a name="l00017"></a>00017 <span class="comment"> Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</span> <a name="l00018"></a>00018 <span class="comment">*/</span> <a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="preprocessor">#ifndef __CS_CSGFX_VERTEXLISTWALKER_H__</span> <a name="l00021"></a>00021 <span class="preprocessor"></span><span class="preprocessor">#define __CS_CSGFX_VERTEXLISTWALKER_H__</span> <a name="l00022"></a>00022 <span class="preprocessor"></span> <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="rbuflock_8h.html" title="Helper class for convenient locking/unlocking of an iRenderBuffer.">cstool/rbuflock.h</a>"</span> <a name="l00024"></a>00024 <a name="l00041"></a>00041 <span class="keyword">template</span><<span class="keyword">typename</span> Tbase, <span class="keyword">typename</span> Tcomplex = Tbase> <a name="l00042"></a><a class="code" href="classcsVertexListWalker.html">00042</a> <span class="keyword">class </span><a class="code" href="classcsVertexListWalker.html" title="Helper class to make it easier to iterate over elements from renderbuffers, with...">csVertexListWalker</a> <a name="l00043"></a>00043 { <a name="l00044"></a>00044 <span class="keyword">public</span>: <a name="l00055"></a><a class="code" href="classcsVertexListWalker.html#8bdddd21800fdeab268bce050656c267">00055</a> <a class="code" href="classcsVertexListWalker.html#8bdddd21800fdeab268bce050656c267" title="Construct new walker.">csVertexListWalker</a> (<a class="code" href="structiRenderBuffer.html" title="This is a general buffer.">iRenderBuffer</a>* buffer, <span class="keywordtype">size_t</span> desiredComponents = 0, <a name="l00056"></a>00056 <span class="keyword">const</span> Tbase* defaultComponents = 0) : currElement (0), bufLock (buffer), <a name="l00057"></a>00057 defaultComponents (defaultComponents) <a name="l00058"></a>00058 { <a name="l00059"></a>00059 bufferComponents = buffer-><a class="code" href="structiRenderBuffer.html#39e622dc64c4acc4a3ed2df051e10598" title="Gets the number of components per element.">GetComponentCount</a> (); <a name="l00060"></a>00060 components = (desiredComponents != 0) ? desiredComponents : <a name="l00061"></a>00061 bufferComponents; <a name="l00062"></a>00062 <a class="code" href="cssysdef_8h.html#c380bd47888ecfe73e7b7a40b6f827a1" title="Assertion.">CS_ASSERT</a> (components <= maxComponents); <a name="l00063"></a>00063 elements = buffer-><a class="code" href="structiRenderBuffer.html#2c43d2f649e4725a8e86abfa5dfbfffe" title="Number of elements in a buffer.">GetElementCount</a>(); <a name="l00064"></a>00064 compType = buffer-><a class="code" href="structiRenderBuffer.html#23e7848455338c7636d6a97e5a09c7c8" title="Gets the component type (float, int, etc).">GetComponentType</a>(); <a name="l00065"></a>00065 FetchCurrentElement(); <a name="l00066"></a>00066 } <a name="l00067"></a>00067 <a name="l00069"></a>00069 <a name="l00070"></a><a class="code" href="classcsVertexListWalker.html#01b038d7bdaa4f127a8e02cd0eae9ad6">00070</a> <a class="code" href="classcsVertexListWalker.html#01b038d7bdaa4f127a8e02cd0eae9ad6" title="Get current element.">operator Tbase const*</a>()<span class="keyword"> const</span> <a name="l00071"></a>00071 <span class="keyword"> </span>{ <a name="l00072"></a>00072 <a class="code" href="cssysdef_8h.html#c380bd47888ecfe73e7b7a40b6f827a1" title="Assertion.">CS_ASSERT</a>(currElement<elements); <a name="l00073"></a>00073 <span class="keywordflow">return</span> convertedComps; <a name="l00074"></a>00074 } <a name="l00075"></a><a class="code" href="classcsVertexListWalker.html#828af5a6ba8eb51b8f7a8a65584666fd">00075</a> <span class="keyword">const</span> Tcomplex& <a class="code" href="classcsVertexListWalker.html#828af5a6ba8eb51b8f7a8a65584666fd">operator*</a>()<span class="keyword"> const</span> <a name="l00076"></a>00076 <span class="keyword"> </span>{ <a name="l00077"></a>00077 <a class="code" href="cssysdef_8h.html#c380bd47888ecfe73e7b7a40b6f827a1" title="Assertion.">CS_ASSERT</a>(currElement<elements); <a name="l00078"></a>00078 <span class="keyword">const</span> Tbase* x = convertedComps; <a name="l00079"></a>00079 <span class="keyword">const</span> Tcomplex* y = (Tcomplex*)x; <a name="l00080"></a>00080 <span class="keywordflow">return</span> *y; <a name="l00081"></a>00081 } <a name="l00083"></a>00083 <a name="l00085"></a>00085 <a name="l00086"></a><a class="code" href="classcsVertexListWalker.html#cf29ddde83a5e8fd0f8350c8963b958c">00086</a> <a class="code" href="classcsVertexListWalker.html" title="Helper class to make it easier to iterate over elements from renderbuffers, with...">csVertexListWalker</a>& <a class="code" href="classcsVertexListWalker.html#cf29ddde83a5e8fd0f8350c8963b958c" title="Set current element to the next.">operator++ </a>() <a name="l00087"></a>00087 { <a name="l00088"></a>00088 currElement++; <a name="l00089"></a>00089 FetchCurrentElement(); <a name="l00090"></a>00090 <span class="keywordflow">return</span> *<span class="keyword">this</span>; <a name="l00091"></a>00091 } <a name="l00093"></a>00093 <a name="l00095"></a><a class="code" href="classcsVertexListWalker.html#1d120e497d5937e5238ba8296e2cdbbb">00095</a> <span class="keywordtype">void</span> <a class="code" href="classcsVertexListWalker.html#1d120e497d5937e5238ba8296e2cdbbb" title="Start from the beginning.">ResetState</a> () <a name="l00096"></a>00096 { <a name="l00097"></a>00097 currElement = 0; <a name="l00098"></a>00098 FetchCurrentElement(); <a name="l00099"></a>00099 } <a name="l00100"></a>00100 <span class="keyword">private</span>: <a name="l00102"></a>00102 <span class="keywordtype">size_t</span> elements; <a name="l00104"></a>00104 <span class="keywordtype">size_t</span> currElement; <a name="l00106"></a>00106 <a class="code" href="classcsRenderBufferLock.html" title="Helper class for convenient locking/unlocking of an iRenderBuffer.">csRenderBufferLock<uint8></a> bufLock; <a name="l00107"></a>00107 <a name="l00109"></a>00109 <span class="keywordtype">size_t</span> components; <a name="l00111"></a>00111 <span class="keywordtype">size_t</span> bufferComponents; <a name="l00113"></a>00113 <span class="keyword">enum</span> { maxComponents = 4 }; <a name="l00115"></a>00115 Tbase convertedComps[maxComponents]; <a name="l00117"></a>00117 <span class="keyword">const</span> Tbase* <span class="keyword">const</span> defaultComponents; <a name="l00119"></a>00119 <a class="code" href="group__gfx3d.html#g2e793d8189bb8566ed81c168875f452b" title="Type of components.">csRenderBufferComponentType</a> compType; <a name="l00120"></a>00120 <a name="l00122"></a>00122 <span class="keyword">const</span> Tbase GetDefaultComponent (<span class="keywordtype">size_t</span> n) <a name="l00123"></a>00123 { <a name="l00124"></a>00124 <span class="keywordflow">return</span> (defaultComponents != 0) ? defaultComponents[n] : <a name="l00125"></a>00125 ((n == 3) ? Tbase(1) : Tbase(0)); <a name="l00126"></a>00126 } <a name="l00128"></a>00128 <span class="keyword">template</span><<span class="keyword">typename</span> C> <a name="l00129"></a>00129 <span class="keywordtype">void</span> FetchCurrentElementReal() <a name="l00130"></a>00130 { <a name="l00131"></a>00131 <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a>* data = bufLock + (currElement * bufferComponents * <span class="keyword">sizeof</span> (C)); <a name="l00132"></a>00132 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> c = 0; c < components; c++) <a name="l00133"></a>00133 { <a name="l00134"></a>00134 convertedComps[c] = <a name="l00135"></a>00135 (c < bufferComponents) ? Tbase(*(C*)data) : <a name="l00136"></a>00136 GetDefaultComponent (c); <a name="l00137"></a>00137 data += <span class="keyword">sizeof</span> (C); <a name="l00138"></a>00138 } <a name="l00139"></a>00139 } <a name="l00141"></a>00141 <span class="keywordtype">void</span> FetchCurrentElement() <a name="l00142"></a>00142 { <a name="l00143"></a>00143 <span class="comment">/* Avoid reading beyond buffer end</span> <a name="l00144"></a>00144 <span class="comment"> * Don't assert here since FetchCurrentElement() is also called in</span> <a name="l00145"></a>00145 <span class="comment"> * legitimate cases (i.e. operator++ while on the last valid element.</span> <a name="l00146"></a>00146 <span class="comment"> * Assert in retrieval operators, though.</span> <a name="l00147"></a>00147 <span class="comment"> */</span> <a name="l00148"></a>00148 <span class="keywordflow">if</span> (currElement >= elements) <span class="keywordflow">return</span>; <a name="l00149"></a>00149 <span class="keywordflow">switch</span> (compType) <a name="l00150"></a>00150 { <a name="l00151"></a>00151 <span class="keywordflow">default</span>: <a name="l00152"></a>00152 <a class="code" href="cssysdef_8h.html#c380bd47888ecfe73e7b7a40b6f827a1" title="Assertion.">CS_ASSERT</a>(<span class="keyword">false</span>); <a name="l00153"></a>00153 <span class="keywordflow">case</span> <a class="code" href="group__gfx3d.html#gg2e793d8189bb8566ed81c168875f452b26ae57b4ddbceb9634861c68516a81d7">CS_BUFCOMP_BYTE</a>: <a name="l00154"></a>00154 FetchCurrentElementReal<char>(); <a name="l00155"></a>00155 <span class="keywordflow">break</span>; <a name="l00156"></a>00156 <span class="keywordflow">case</span> <a class="code" href="group__gfx3d.html#gg2e793d8189bb8566ed81c168875f452b25702e67abcd7290c92062ce2a867a0c">CS_BUFCOMP_UNSIGNED_BYTE</a>: <a name="l00157"></a>00157 FetchCurrentElementReal<unsigned char>(); <a name="l00158"></a>00158 <span class="keywordflow">break</span>; <a name="l00159"></a>00159 <span class="keywordflow">case</span> <a class="code" href="group__gfx3d.html#gg2e793d8189bb8566ed81c168875f452bab6038604aa2bd575bd4351c8343d3a0">CS_BUFCOMP_SHORT</a>: <a name="l00160"></a>00160 FetchCurrentElementReal<short>(); <a name="l00161"></a>00161 <span class="keywordflow">break</span>; <a name="l00162"></a>00162 <span class="keywordflow">case</span> <a class="code" href="group__gfx3d.html#gg2e793d8189bb8566ed81c168875f452b93ac3748f171605ca85ad3dd9e1827fc">CS_BUFCOMP_UNSIGNED_SHORT</a>: <a name="l00163"></a>00163 FetchCurrentElementReal<unsigned short>(); <a name="l00164"></a>00164 <span class="keywordflow">break</span>; <a name="l00165"></a>00165 <span class="keywordflow">case</span> <a class="code" href="group__gfx3d.html#gg2e793d8189bb8566ed81c168875f452ba95b8898b542f169190e6a49ea7cf2b8">CS_BUFCOMP_INT</a>: <a name="l00166"></a>00166 FetchCurrentElementReal<int>(); <a name="l00167"></a>00167 <span class="keywordflow">break</span>; <a name="l00168"></a>00168 <span class="keywordflow">case</span> <a class="code" href="group__gfx3d.html#gg2e793d8189bb8566ed81c168875f452b96a405b29bd36a67e0796c74424387de">CS_BUFCOMP_UNSIGNED_INT</a>: <a name="l00169"></a>00169 FetchCurrentElementReal<unsigned int>(); <a name="l00170"></a>00170 <span class="keywordflow">break</span>; <a name="l00171"></a>00171 <span class="keywordflow">case</span> <a class="code" href="group__gfx3d.html#gg2e793d8189bb8566ed81c168875f452b5df131ffd6ead0cdfa3dc9eea6a78e73">CS_BUFCOMP_FLOAT</a>: <a name="l00172"></a>00172 FetchCurrentElementReal<float>(); <a name="l00173"></a>00173 <span class="keywordflow">break</span>; <a name="l00174"></a>00174 <span class="keywordflow">case</span> <a class="code" href="group__gfx3d.html#gg2e793d8189bb8566ed81c168875f452bef38bb2295605b7e873b85cd273a66a1">CS_BUFCOMP_DOUBLE</a>: <a name="l00175"></a>00175 FetchCurrentElementReal<double>(); <a name="l00176"></a>00176 <span class="keywordflow">break</span>; <a name="l00177"></a>00177 } <a name="l00178"></a>00178 } <a name="l00179"></a>00179 }; <a name="l00180"></a>00180 <a name="l00181"></a>00181 <span class="preprocessor">#endif // __CS_CSGFX_VERTEXLISTWALKER_H__</span> </pre></div><hr size="1"><address><small>Generated for Crystal Space 1.2.1 by <a href="http://www.doxygen.org/index.html">doxygen</a> 1.5.3 </small></address> </div></body> </html>