aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/doc/html/example026.html
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/doc/html/example026.html')
-rw-r--r--libraries/irrlicht-1.8/doc/html/example026.html251
1 files changed, 0 insertions, 251 deletions
diff --git a/libraries/irrlicht-1.8/doc/html/example026.html b/libraries/irrlicht-1.8/doc/html/example026.html
deleted file mode 100644
index 090b61c..0000000
--- a/libraries/irrlicht-1.8/doc/html/example026.html
+++ /dev/null
@@ -1,251 +0,0 @@
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<title>Irrlicht 3D Engine: Tutorial 26: OcclusionQuery</title>
6
7<link href="tabs.css" rel="stylesheet" type="text/css"/>
8<link href="doxygen.css" rel="stylesheet" type="text/css" />
9<link href="navtree.css" rel="stylesheet" type="text/css"/>
10<script type="text/javascript" src="jquery.js"></script>
11<script type="text/javascript" src="resize.js"></script>
12<script type="text/javascript" src="navtree.js"></script>
13<script type="text/javascript">
14 $(document).ready(initResizable);
15</script>
16<link href="search/search.css" rel="stylesheet" type="text/css"/>
17<script type="text/javascript" src="search/search.js"></script>
18<script type="text/javascript">
19 $(document).ready(function() { searchBox.OnSelectItem(0); });
20</script>
21
22</head>
23<body>
24<div id="top"><!-- do not remove this div! -->
25
26
27<div id="titlearea">
28<table cellspacing="0" cellpadding="0">
29 <tbody>
30 <tr style="height: 56px;">
31
32 <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
33
34
35 <td style="padding-left: 0.5em;">
36 <div id="projectname">Irrlicht 3D Engine
37
38 </div>
39
40 </td>
41
42
43
44
45 <td> <div id="MSearchBox" class="MSearchBoxInactive">
46 <span class="left">
47 <img id="MSearchSelect" src="search/mag_sel.png"
48 onmouseover="return searchBox.OnSearchSelectShow()"
49 onmouseout="return searchBox.OnSearchSelectHide()"
50 alt=""/>
51 <input type="text" id="MSearchField" value="Search" accesskey="S"
52 onfocus="searchBox.OnSearchFieldFocus(true)"
53 onblur="searchBox.OnSearchFieldFocus(false)"
54 onkeyup="searchBox.OnSearchFieldChange(event)"/>
55 </span><span class="right">
56 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
57 </span>
58 </div>
59</td>
60
61
62 </tr>
63 </tbody>
64</table>
65</div>
66
67<!-- Generated by Doxygen 1.7.5.1 -->
68<script type="text/javascript">
69var searchBox = new SearchBox("searchBox", "search",false,'Search');
70</script>
71<script type="text/javascript" src="dynsections.js"></script>
72</div>
73<div id="side-nav" class="ui-resizable side-nav-resizable">
74 <div id="nav-tree">
75 <div id="nav-tree-contents">
76 </div>
77 </div>
78 <div id="splitbar" style="-moz-user-select:none;"
79 class="ui-resizable-handle">
80 </div>
81</div>
82<script type="text/javascript">
83 initNavTree('example026.html','');
84</script>
85<div id="doc-content">
86<div class="header">
87 <div class="headertitle">
88<div class="title">Tutorial 26: OcclusionQuery </div> </div>
89</div>
90<div class="contents">
91<div class="textblock"><div class="image">
92<img src="026shot.jpg" alt="026shot.jpg"/>
93</div>
94 <p>This Tutorial shows how to speed up rendering by use of the OcclusionQuery feature. The usual rendering tries to avoid rendering of scene nodes by culling those nodes which are outside the visible area, the view frustum. However, this technique does not cope with occluded objects which are still in the line of sight, but occluded by some larger object between the object and the eye (camera). Occlusion queries check exactly that. The queries basically measure the number of pixels that a previous render left on the screen. Since those pixels cannot be recognized at the end of a rendering anymore, the pixel count is measured directly when rendering. Thus, one needs to render the occluder (the object in front) first. This object needs to write to the z-buffer in order to become a real occluder. Then the node is rendered and in case a z-pass happens, i.e. the pixel is written to the framebuffer, the pixel is counted in the query. The result of a query is the number of pixels which got through. One can, based on this number, judge if the scene node is visible enough to be rendered, or if the node should be removed in the next round. Also note that the number of pixels is a safe over approximation in general. The pixels might be overdrawn later on, and the GPU tries to avoid inaccuracies which could lead to false negatives in the queries.</p>
95<p>As you might have recognized already, we had to render the node to get the numbers. So where's the benefit, you might say. There are several ways where occlusion queries can help. It is often a good idea to just render the bbox of the node instead of the actual mesh. This is really fast and is a safe over approximation. If you need a more exact render with the actual geometry, it's a good idea to render with just basic solid material. Avoid complex shaders and state changes through textures. There's no need while just doing the occlusion query. At least if the render is not used for the actual scene. This is the third way to optimize occlusion queries. Just check the queries every 5th or 10th frame, or even less frequent. This depends on the movement speed of the objects and camera. </p>
96<div class="fragment"><pre class="fragment"><span class="preprocessor">#ifdef _MSC_VER</span>
97<span class="preprocessor"></span><span class="comment">// We&#39;ll also define this to stop MSVC complaining about sprintf().</span>
98<span class="preprocessor">#define _CRT_SECURE_NO_WARNINGS</span>
99<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
100<span class="preprocessor"></span><span class="preprocessor">#endif</span>
101<span class="preprocessor"></span>
102<span class="preprocessor">#include &lt;<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt;</span>
103<span class="preprocessor">#include &quot;<a class="code" href="driver_choice_8h.html">driverChoice.h</a>&quot;</span>
104
105<span class="keyword">using namespace </span>irr;
106</pre></div><p>We need keyboard input events to switch some parameters </p>
107<div class="fragment"><pre class="fragment"><span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> IEventReceiver
108{
109<span class="keyword">public</span>:
110 <span class="comment">// This is the one method that we have to implement</span>
111 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)
112 {
113 <span class="comment">// Remember whether each key is down or up</span>
114 <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0ca6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">irr::EET_KEY_INPUT_EVENT</a>)
115 KeyIsDown[<span class="keyword">event</span>.KeyInput.Key] = <span class="keyword">event</span>.KeyInput.PressedDown;
116
117 <span class="keywordflow">return</span> <span class="keyword">false</span>;
118 }
119
120 <span class="comment">// This is used to check whether a key is being held down</span>
121 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> IsKeyDown(<a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3">EKEY_CODE</a> keyCode)<span class="keyword"> const</span>
122<span class="keyword"> </span>{
123 <span class="keywordflow">return</span> KeyIsDown[keyCode];
124 }
125
126 MyEventReceiver()
127 {
128 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=0; i&lt;<a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a205b48c0c4ed7489ab8980657343283e">KEY_KEY_CODES_COUNT</a>; ++i)
129 KeyIsDown[i] = <span class="keyword">false</span>;
130 }
131
132<span class="keyword">private</span>:
133 <span class="comment">// We use this array to store the current state of each key</span>
134 <span class="keywordtype">bool</span> KeyIsDown[<a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a205b48c0c4ed7489ab8980657343283e">KEY_KEY_CODES_COUNT</a>];
135};
136</pre></div><p>We create an <a class="el" href="classirr_1_1_irrlicht_device.html" title="The Irrlicht device. You can create it with createDevice() or createDeviceEx().">irr::IrrlichtDevice</a> and the scene nodes. One occluder, one occluded. The latter is a complex sphere, which has many triangles. </p>
137<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main()
138{
139 <span class="comment">// ask user for driver</span>
140 <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> driverType=driverChoiceConsole();
141 <span class="keywordflow">if</span> (driverType==<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae685cada50f8c100403134d932d0414c" title="No driver, just for counting the elements.">video::EDT_COUNT</a>)
142 <span class="keywordflow">return</span> 1;
143
144 <span class="comment">// create device</span>
145 MyEventReceiver receiver;
146
147 IrrlichtDevice* device = <a class="code" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice</a>(driverType,
148 core::dimension2d&lt;u32&gt;(640, 480), 16, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, &amp;receiver);
149
150 <span class="keywordflow">if</span> (device == 0)
151 <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
152
153 video::IVideoDriver* driver = device-&gt;getVideoDriver();
154 scene::ISceneManager* smgr = device-&gt;getSceneManager();
155
156 smgr-&gt;getGUIEnvironment()-&gt;addStaticText(L<span class="stringliteral">&quot;Press Space to hide occluder.&quot;</span>, <a class="code" href="namespaceirr_1_1core.html#a628365d56b9d3ca9c887cd7f651f7b45" title="Rectangle with int values.">core::recti</a>(10,10, 200,50));
157</pre></div><p>Create the node to be occluded. We create a sphere node with high poly count. </p>
158<div class="fragment"><pre class="fragment"> scene::ISceneNode * node = smgr-&gt;addSphereSceneNode(10, 64);
159 <span class="keywordflow">if</span> (node)
160 {
161 node-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,60));
162 node-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/wall.bmp&quot;</span>));
163 node-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
164 }
165</pre></div><p>Now we create another node, the occluder. It's a simple plane. </p>
166<div class="fragment"><pre class="fragment"> scene::ISceneNode* plane = smgr-&gt;addMeshSceneNode(smgr-&gt;addHillPlaneMesh(
167 <span class="stringliteral">&quot;plane&quot;</span>, <a class="code" href="namespaceirr_1_1core.html#af6dc5c45ff13e7712758c827ff58676b" title="Typedef for an f32 dimension.">core::dimension2df</a>(10,10), <a class="code" href="namespaceirr_1_1core.html#ad2e562e3219072e2f7fc7c2bba0ef0cb" title="Typedef for an unsigned integer dimension.">core::dimension2du</a>(2,2)), 0, -1,
168 <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,20), <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(270,0,0));
169
170 <span class="keywordflow">if</span> (plane)
171 {
172 plane-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/t351sml.jpg&quot;</span>));
173 plane-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
174 plane-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3ae1d176d0ce05ccc5df9e43ce854393bb" title="Is backface culling enabled? Default: true.">video::EMF_BACK_FACE_CULLING</a>, <span class="keyword">true</span>);
175 }
176</pre></div><p>Here we create the occlusion query. Because we don't have a plain mesh scene node (ESNT_MESH or ESNT_ANIMATED_MESH), we pass the base geometry as well. Instead, we could also pass a simpler mesh or the bounding box. But we will use a time based method, where the occlusion query renders to the frame buffer and in case of success (occlusion), the mesh is not drawn for several frames. </p>
177<div class="fragment"><pre class="fragment"> driver-&gt;addOcclusionQuery(node, ((scene::IMeshSceneNode*)node)-&gt;getMesh());
178</pre></div><p>We have done everything, just a camera and draw it. We also write the current frames per second and the name of the driver to the caption of the window to examine the render speedup. We also store the time for measuring the time since the last occlusion query ran and store whether the node should be visible in the next frames. </p>
179<div class="fragment"><pre class="fragment"> smgr-&gt;addCameraSceneNode();
180 <span class="keywordtype">int</span> lastFPS = -1;
181 <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> timeNow = device-&gt;getTimer()-&gt;getTime();
182 <span class="keywordtype">bool</span> nodeVisible=<span class="keyword">true</span>;
183
184 <span class="keywordflow">while</span>(device-&gt;run())
185 {
186 plane-&gt;setVisible(!receiver.IsKeyDown(<a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a52c3b1744ca8ae7b6da19fc00fbb8ee8">irr::KEY_SPACE</a>));
187
188 driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, video::SColor(255,113,113,133));
189</pre></div><p>First, we draw the scene, possibly without the occluded element. This is necessary because we need the occluder to be drawn first. You can also use several scene managers to collect a number of possible occluders in a separately rendered scene. </p>
190<div class="fragment"><pre class="fragment"> node-&gt;setVisible(nodeVisible);
191 smgr-&gt;drawAll();
192 smgr-&gt;getGUIEnvironment()-&gt;drawAll();
193</pre></div><p>Once in a while, here every 100 ms, we check the visibility. We run the queries, update the pixel value, and query the result. Since we already rendered the node we render the query invisible. The update is made blocking, as we need the result immediately. If you don't need the result immediately, e.g. because you have other things to render, you can call the update non-blocking. This gives the GPU more time to pass back the results without flushing the render pipeline. If the update was called non-blocking, the result from getOcclusionQueryResult is either the previous value, or 0xffffffff if no value has been generated at all, yet. The result is taken immediately as visibility flag for the node. </p>
194<div class="fragment"><pre class="fragment"> <span class="keywordflow">if</span> (device-&gt;getTimer()-&gt;getTime()-timeNow&gt;100)
195 {
196 driver-&gt;runAllOcclusionQueries(<span class="keyword">false</span>);
197 driver-&gt;updateAllOcclusionQueries();
198 nodeVisible=driver-&gt;getOcclusionQueryResult(node)&gt;0;
199 timeNow=device-&gt;getTimer()-&gt;getTime();
200 }
201
202 driver-&gt;endScene();
203
204 <span class="keywordtype">int</span> fps = driver-&gt;getFPS();
205
206 <span class="keywordflow">if</span> (lastFPS != fps)
207 {
208 <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> tmp(L<span class="stringliteral">&quot;OcclusionQuery Example [&quot;</span>);
209 tmp += driver-&gt;getName();
210 tmp += L<span class="stringliteral">&quot;] fps: &quot;</span>;
211 tmp += fps;
212
213 device-&gt;setWindowCaption(tmp.c_str());
214 lastFPS = fps;
215 }
216 }
217</pre></div><p>In the end, delete the Irrlicht device. </p>
218<div class="fragment"><pre class="fragment"> device-&gt;drop();
219
220 <span class="keywordflow">return</span> 0;
221}
222</pre></div><p>That's it. Compile and play around with the program. </p>
223</div></div>
224</div>
225 <div id="nav-path" class="navpath">
226 <ul>
227<!-- window showing the filter options -->
228<div id="MSearchSelectWindow"
229 onmouseover="return searchBox.OnSearchSelectShow()"
230 onmouseout="return searchBox.OnSearchSelectHide()"
231 onkeydown="return searchBox.OnSearchSelectKey(event)">
232<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>
233
234<!-- iframe showing the search results (closed by default) -->
235<div id="MSearchResultsWindow">
236<iframe src="javascript:void(0)" frameborder="0"
237 name="MSearchResults" id="MSearchResults">
238</iframe>
239</div>
240
241
242 <li class="footer">
243<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
244Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Tue Nov 6 2012 11:06:02 for Irrlicht 3D Engine by
245<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
246 </ul>
247 </div>
248
249
250</body>
251</html>