tag:blogger.com,1999:blog-51599393808657504072024-03-14T02:16:50.076+01:003D-Spieleentwicklung - Vulkan - OpenGL - GLSL - OpenCL - OpenALAlexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comBlogger176125tag:blogger.com,1999:blog-5159939380865750407.post-21292875196923060732023-09-12T11:48:00.002+02:002023-09-12T11:48:50.718+02:00AIDemoProgramsGPU-Programmbeispiele zu meiner Artikelserie "Classic Games Reloaded" (Entwickler-Magazin)<p>An dieser Stelle könnt Ihr euch einen weiteren Satz von KI-bezogenen Programmbeispielen herunterladen, auf die ich in meinen im Entwickler-Magazin publizierten Artikeln zu sprechen komme.</p><p>Die meisten der Programmbeispiele (deren Anzahl sich in Zukunft noch erhöhen wird), greifen auf die Vulkan-API zurück, um die Durchführung ihrer jeweiligen (KI-)Berechnungen auf die GPU auszulagern.<br /></p><p>Viel Vergnügen!</p><p><br /><b><a href="https://drive.google.com/uc?export=download&id=1-cPYZvvVpwJMdFPO38D5-ejaxLit0BYi" target="">Download Link: AIDemoProgramsGPU.zip</a></b></p><p></p>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-8633633766181461622022-09-12T17:38:00.000+02:002022-09-12T17:38:16.406+02:00AIDemoPrograms-Programmbeispiele zu meiner Artikelserie "Classic Games Reloaded" (Entwickler-Magazin)<p>An dieser Stelle könnt Ihr die zu meiner im Entwickler-Magazin publizierten Artikelserie "Classic Games Reloaded" zugehörigen <b>aktualisierten</b> KI-bezogenen Programmbeispiele herunterladen.</p><p>Viel Vergnügen!</p><p><br /><b><a href="https://drive.google.com/uc?export=download&id=1-YH9A8fOLxyPzTd8zseTBrDTaiHZUhMU" target="">Download Link: AIDemoPrograms.zip</a></b></p>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-9933258923032610012021-10-10T10:46:00.002+02:002021-10-10T10:51:41.049+02:00SimpleNeuralNets-Programmbeispiele zu meiner Artikelserie "Classic Games Reloaded" (Entwickler-Magazin)<p>An dieser Stelle könnt Ihr die zu meiner im Entwickler-Magazin publizierten Artikelserie "Classic Games Reloaded" zugehörigen KI-bezogenen Programmbeispiele herunterladen. Viel Vergnügen:</p><p></p><p><span style="font-size: large;"><b><a href="https://drive.google.com/uc?export=download&id=1q2XG2Js8f4uPtuKVPMTs-dA7vB1Va21a" target="_blank">Download Link: SimpleNeuralNets.zip</a></b></span><br />
<br /> <span style="font-size: large;"><b><br /></b></span></p>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-4427151711371232722019-01-20T13:36:00.000+01:002019-01-20T15:26:01.082+01:00Ausleihbares E-Book: C++ Programmierung – Die ersten Schritte auf einem langen WegAn dieser Stelle finden sich sämtliche Programmbeispiele aus unserem neuesten E-Book, mit dessen Hilfe ich Ihnen die Grundlagen der <b>C++ Programmierung</b> näher bringen möchte.<br />
<br />
Über den nachfolgenden Amazon-Partnerlink gelangen Sie zur Detailseite des besagten E-Books:<br />
<br />
<a href="https://www.amazon.de/gp/product/B07L8ZLL29/ref=as_li_tl?ie=UTF8&camp=1638&creative=6742&creativeASIN=B07L8ZLL29&linkCode=as2&tag=3dspieleentw-21&linkId=3d898516ca7143c53696a5824c7aa0a4" target="_blank">C++ Programmierung – Die ersten Schritte auf einem langen Weg</a><img alt="" border="0" height="1" src="//ir-de.amazon-adsystem.com/e/ir?t=3dspieleentw-21&l=am2&o=3&a=B07L8ZLL29" style="border: none !important; margin: 0px !important;" width="1" /> (<b>kostenlos ausleihbar</b>)<br />
<br />
Auch wenn Sie nicht an diesem E-Book interessiert sind und sich lediglich mit den Grundlagen der C++-Programmierung vertraut machen wollen, können Sie den nachfolgenden Download-Link verwenden, um sich eine Vielzahl von einfach nachvollziehbaren Programmbeispielen herunterzuladen. Doch erwarten Sie bitte nicht allzu viel, C++ ist eine so mächtige Programmiersprache, dass die besagten Programmbeispiele allenfalls ein wenig an der Oberfläche der einzelnen Themengebiete (Variablen, Funktionen, Kontrollstrukturen, Klassen- und Strukturobjekte, Templates, Vererbung, Multithreading, usw.) kratzen können. Und wer sich beispielsweise für die vielfältigen Einsatzmöglichkeiten der STL (<b>S</b>tandard <b>T</b>emplate<b> L</b>ibrary) interessiert, der wird an dieser Stelle lediglich in begrenztem Maße fündig werden.<br />
<br />
Die meisten Programmieranfänger werden sich meiner Meinung nach sowieso erst einmal für ganz andere Dinge interessieren. Genau genommen ist es bereits eine nicht zu verachtende Leistung, wenn man beispielsweise einen Text auf dem Bildschirm ausgeben kann oder wenn man weiß, wie sich Zahlenwerte addieren, multiplizieren, subtrahieren oder dividieren lassen.<br />
<br />
<span style="font-size: large;"><b><a href="https://drive.google.com/uc?export=download&id=1Ssw5STED3h7pke27Wq2SKmW_jBrvUATO" target="_blank">Download Link: Learning_Cpp.zip</a> </b></span>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-80451721186411186672018-12-18T14:02:00.000+01:002018-12-18T13:43:22.178+01:00Unser neues E-Book: Vulkan API Programmierung – Vektoren und Matrizen, Beleuchtung, GLSL Shader, Post Processing<div class="separator" style="clear: both; text-align: center;">
<a href="https://abload.de/img/vulkandemoscreenshot1cqsbm.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="300" src="https://abload.de/img/vulkandemoscreenshot1cqsbm.jpg" width="400" /></a></div>
Wieder einmal hatten es die letzten Wochen so richtig in sich – ein neuer Vulkan-Artikel musste pünktlich für das Entwickler-Magazin fertig gestellt werden, und die Arbeiten an meinem neuen E-Book<br />
<br />
<b>Vulkan API Programmierung – Vektoren und Matrizen, Beleuchtung, GLSL Shader, Post Processing</b><br />
<br />
wollten und wollten einfach kein Ende nehmen.<br />
<br />
<br />
<br />
Über den nachfolgenden Amazon-Partnerlink gelangen Sie zur Detailseite des neuen E-Books:<br />
<a href="https://www.amazon.de/gp/product/B06XS7BLSY/ref=as_li_tl?ie=UTF8&camp=1638&creative=6742&creativeASIN=B06XS7BLSY&linkCode=as2&tag=3dspieleentw-21" rel="nofollow">Vulkan API Programmierung - Vektoren und Matrizen, Beleuchtung, GLSL Shader, Post Processing</a><img alt="" border="0" height="1" src="https://ir-de.amazon-adsystem.com/e/ir?t=3dspieleentw-21&l=as2&o=3&a=B06XS7BLSY" style="border: none !important; margin: 0px !important;" width="1" /><br />
<br />
<a name='more'></a>Als es mit Einsetzen des Smartphone- und Tablet-Booms zunehmend wichtiger wurde, sowohl grafisch wie auch inhaltlich anspruchsvolle Spieleanwendungen für so viele Endgeräte wie möglich entwickeln zu können, rückte OpenGL (ES) immer stärker in den Fokus der Entwickler. Nichtsdestotrotz kann aber auch die in der letzten Zeit stetig zunehmende Popularität von OpenGL nicht darüber hinwegtäuschen, dass die bereits im Jahr 1992 vorgestellte Grafik-API niemals für den Einsatz auf modernen Mehrkernprozessoren konzipiert worden war.<br />
Dank der neuen Vulkan-API gehören jedoch die Limitierungen, mit denen man sich bislang als OpenGL-Entwickler herumschlagen musste, nun aber endgültig der Vergangenheit an. Vulkan ist ähnlich wie OpenGL auf unterschiedlichen Endgeräten und Betriebssystemen einsetzbar, zeichnet sich jedoch durch einem sehr viel geringeren Treiber-Overhead aus und gibt uns darüber hinaus auch die Möglichkeit, die Kommunikation zwischen Hauptprogramm und Grafikkarte (Rendering, GPU-basierte Berechnungen, Ressourcen- sowie Buffer-Updates) auf beliebig viele Threads aufzuteilen.<br />
Im Rahmen dieses Buches werden wir uns mit den Grundlagen der Vulkan-Programmierung auseinandersetzen und in diesem Zusammenhang ein kleines Framework (ein schrittweise erweiterbares Programmiergerüst) entwerfen, mit deren Hilfe sich die Entwicklung einer auf der Vulkan-API basierenden Grafikanwendung enorm vereinfachen lässt.<br />
<br />
Die zugehörigen Programmbeispiele zur weiteren Vertiefung der im E-Book behandelten Themen finden Sie unter:<br />
<br />
<a href="https://www.graphics-and-physics-framework.spieleprogrammierung.net/" target="_blank">https://www.graphics-and-physics-framework.spieleprogrammierung.net/</a><br />
<br />
<br />
<b>Aus dem Inhalt:</b><br />
<ul>
<li>Vektor- und Matrizenrechnung</li>
<li>Grundlagen der GLSL-Shader-Programmierung (Vertex-, Fragment- sowie Compute-Shader)</li>
<li>Entwicklung eines einfachen Vulkan-Frameworks</li>
<li>Multithreading (Rendering, Ressourcen- sowie Buffer-Updates)</li>
<li>HDR-Rendering</li>
<li>Offscreen Rendering</li>
<li>Grundlagen des Post Processings</li>
<li>Deferred Lighting (direktionale Beleuchtung, punktförmige Lichtquellen sowie Spotlights)</li>
</ul>
<br />
<br />
<ul></ul>
Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-34684106426984023072016-08-07T10:23:00.000+02:002018-05-01T22:12:59.022+02:00E-Books zu unserer Tutorial-Serie rundum die OpenGL-Programmierung<div class="MsoNormal"><div class="separator" style="clear: both; text-align: center;"><a href="https://abload.de/img/earthtypenewgeuom.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://abload.de/img/earthtypenewgeuom.jpg" height="240" width="320" /></a></div>Mit dem Ziel, Sie beim Durcharbeiten der einzelnen OpenGL Tutorials zu unterstützen, beleuchten die nachfolgend genannten E-Books gleichermaßen Grundlagen wie auch fortgeschrittene Techniken der modernen OpenGL-Programmierung sowie das für die Spieleentwicklung erforderliche mathematische Handwerkszeug.<br />
<div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
<ul><li>Beim ersten Buch liegt der Fokus primär auf der OpenGL-Programierung.</li>
</ul></div><div class="MsoNormal"><ul><li>Buch 2 behandelt gleichermaßen die OpenGL-Programmierung wie auch die für die Spieleentwicklung erforderlichen mathematischen Grundlagen.</li>
</ul></div><div class="MsoNormal"><ul><li>Beim dritten Buch liegt der Fokus primär auf die für die Spieleentwicklung erforderlichen mathematischen Grundlagen.</li>
</ul><br />
</div></div><div class="MsoNormal">Über die nachfolgenden <b>Amazon-Partnerlinks</b> gelangen Sie zu den Detailseiten der jeweiligen E-Books:<br />
<br />
</div><div style="text-align: left;"><ul><li><b><a href="https://www.amazon.de/gp/product/B00MGHXMB4/ref=as_li_tl?ie=UTF8&camp=1638&creative=6742&creativeASIN=B00MGHXMB4&linkCode=as2&tag=3dspieleentw-21&linkId=NG53CMDPVEOQ7SVA">OpenGL-Programmierung - Mathematik, GLSL Shader, Post Processing, Beleuchtung, Animation</a><img alt="" border="0" src="https://ir-de.amazon-adsystem.com/e/ir?t=3dspieleentw-21&l=as2&o=3&a=B00MGHXMB4" height="1" style="border: none !important; margin: 0px !important;" width="1"></b></li>
</ul><ul><li> <b><a href="https://www.amazon.de/gp/product/B00T7ZVUS0/ref=as_li_tl?ie=UTF8&camp=1638&creative=6742&creativeASIN=B00T7ZVUS0&linkCode=as2&tag=3dspieleentw-21&linkId=O2JFDRGJ2ZRWWGDE">Spieleentwicklung - OpenGL, Mathematik, Physik, KI, Animation, Beleuchtung, GLSL Shader, Post Processing</a><img alt="" border="0" src="https://ir-de.amazon-adsystem.com/e/ir?t=3dspieleentw-21&l=as2&o=3&a=B00T7ZVUS0" height="1" style="border: none !important; margin: 0px !important;" width="1"></b></li>
</ul><ul><li> <b><a href="https://www.amazon.de/gp/product/B00T7ZVYTK/ref=as_li_tl?ie=UTF8&camp=1638&creative=6742&creativeASIN=B00T7ZVYTK&linkCode=as2&tag=3dspieleentw-21&linkId=D66R7FX265PXLP7P">Spieleentwicklung - Mathematik, Physik, KI, Animation, Beleuchtung, GLSL Shader, Post Processing</a><img alt="" border="0" src="https://ir-de.amazon-adsystem.com/e/ir?t=3dspieleentw-21&l=as2&o=3&a=B00T7ZVYTK" height="1" style="border: none !important; margin: 0px !important;" width="1"></b></li>
</ul></div><div style="text-align: center;">(Amazon Partnerlinks)</div><br />
<div class="MsoNormal"><b>Zahlreiche Programmbeispiele zur weiteren Vertiefung der im E-Book behandelten Themen finden Sie auf unseren Internetseiten:</b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-size: small;"><a href="https://www.spieleprogrammierung.net/" target="_blank">https://www.spieleprogrammierung.net/</a></span></div><div class="MsoNormal"><span style="font-size: small;"><a href="https://www.graphics-and-physics-framework.spieleprogrammierung.net/" target="_blank">https://www.graphics-and-physics-framework.spieleprogrammierung.net/</a></span></div><span style="font-size: small;"><a href="https://www.space-combat-and-strategy.spieleprogrammierung.net/" target="_blank">https://www.space-combat-and-strategy.spieleprogrammierung.net/</a></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://abload.de/img/newwater2xiuqm.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://abload.de/img/newwater2xiuqm.jpg" height="240" width="320" /></a></div><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<a name='more'></a><b><span style="mso-bidi-font-weight: bold;">Hier eine kleine Inhaltsübersicht (Buch 2):</span></b><br />
<ul><li>Vektoren, Matrizen, 3D-Transformationen, Koordinatensysteme, Polarkoordinaten</li>
<li>SSE-Programmierung</li>
<li>Numerische Integrationsverfahren</li>
<li>Bodenreibung, Luftwiderstand, dynamischer und statischer Auftrieb</li>
<li>Geschossflugbahnen, Planetenbewegung, Masse-Feder-Systeme</li>
<li>scheinbare Sonnenbahnen im Wechsel der Jahreszeiten</li>
<li>Wegfindung, Schwarmverhalten, Flugmodelle für Raumschiffe und Lenkwaffen</li>
<li>Stoßprozesse und Kollisionen</li>
<li>Hash-Grid-Sektorisierung</li>
<li>Bewegung des Cursors (Mauszeigers) im 3D-Raum</li>
<li>Objekt-Picking, Bildschirm- und Viewport-Koordinaten, Sichtbarkeitstests, Portale</li>
<li>Kamera- und Projektionstransformationen, z-Fighting, Kameradrehungen</li>
<li>Bounding-Boxen, Kollisions- und Schnittpunkttests mit Ebenen, Dreiecken, Bounding-Sphären, Ellipsoiden</li>
<li>OpenGL-Initialisierungsschritte und Aufräumarbeiten</li>
<li>Texture-, Texture-Array- sowie Sampler-Objekte</li>
<li>Vertex-Buffer- und Index-Buffer-Objekte</li>
<li>GLSL-Shader-Programmierung</li>
<li>Billboard-Transformationsfunktionen (für Hintergrundobjekte, Partikeleffekte, Strahlenwaffen, Leucht-, Rauch- und Explosionsspuren)</li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Geometry Instancing (Uniform Buffer Instancing und Texture Buffer Instancing)</span></li>
<li><span lang="SV" style="mso-ansi-language: SV;">skelettbasierte Animationen (Kinematik, GPU-Skinning, Instancing)</span></li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Post Processing</span></li>
<li>Szenenkomposition (Layered Rendering)</li>
<li>Flimmer- und Verzerrungseffekte (Hitzeflimmern)</li>
<li>HDR-Rendering, Tone Mapping, Helligkeits-Adaption und Blend-Effekte</li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Anti-Aliasing</span></li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Beleuchtungsmodelle und Normal Mapping</span></li>
<li>Deferred Lighting (direktionale Beleuchtung, punktförmige Lichtquellen)</li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Screen Space Ambient Occlusion (Surface Height Occlusion, Distance Based Occlusion)</span></li>
<li>Deferred Shadow Calculations (direktionale Beleuchtung, Spotlights, punktförmige Lichtquellen)</li>
<li>Bewegungsunschärfe (Motion Blur)</li>
<li>Schärfentiefe (Depth of Field)</li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Warpflug-Effekte</span></li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Volumetric Light Scattering/Light Shafts (God Rays)</span></li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Screen Space </span>Lens Flares (Linsenreflektionen)</li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Deferred Damage Calculations</span></li>
<li>Deferred Atmosphere Rendering (Atmosphärendarstellung bis hinauf in den Weltraum basierend auf Rayleigh- und Mie-Streuung)</li>
<li>Deferred Water Rendering</li>
<li>lokale Wasserspiegelungen (Screen Space Reflections)</li>
</ul><br />
Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-27990358896344968322013-06-11T12:15:00.000+02:002018-05-01T22:07:14.082+02:00Prozedurale Terrain-Generierung und -Darstellung (Demoprogramm)<div class="MsoNormal"><div class="separator" style="clear: both; text-align: center;"><a href="https://abload.de/img/terrain_renderdemo54pnq.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://abload.de/img/terrain_renderdemo54pnq.jpg" height="240" width="320" /></a></div>Die Terrain-Generierung und -Darstellung zählt zu den interessantesten aber auch anspruchsvollsten Themenkomplexen im Bereich der Spieleprogrammierung. Das hier vorliegende Beispielprogramm soll Ihnen als Einstiegshilfe dienen und demonstriert in diesem Zusammenhang den Einsatz von OpenGL-Texture-Buffer- und Texture-Array-Objekten bei der Darstellung von virtuellen Landschaften, die aus einer großen Anzahl von Terrain-Tiles zusammengesetzt sind (Texture Buffer Instancing).<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://abload.de/img/terrainholesolzep.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://abload.de/img/terrainholesolzep.jpg" height="240" width="320" /></a></div>Angefangen beim einfachen 2D-Terrain bis hin zum deutlich komplexeren 3D-LOD-Terrain mit Texture Splatting unterstützt das Programm die folgenden vier Render-Techniken (letzter Eintrag in der Datei <i style="mso-bidi-font-style: normal;">DemoConfig.txt</i> im Ordner <i style="mso-bidi-font-style: normal;">Bin</i>):</div><div class="MsoNormal"><ul><li>Einfaches 2D-Terrain (0)</li>
<li style="text-align: justify;">Einfaches 2D-Terrain mit Texture Splatting (1)</li>
<li style="text-align: justify;">Einfaches 3D-Terrain mit Texture Splatting (2)</li>
<li style="text-align: justify;">3D-LOD-Terrain mit Texture Splatting (3)</li>
</ul></div><ul></ul><div class="MsoNormal"><br />
<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://abload.de/img/terrainwithouttexture0tymg.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://abload.de/img/terrainwithouttexture0tymg.jpg" height="240" width="320" /></a></div>Die Terrain-Generierung (3D-LOD-Terrain) erfolgt skriptbasiert (siehe <i style="mso-bidi-font-style: normal;">LODTerrainGenerationDesc.txt</i> im Ordner <i style="mso-bidi-font-style: normal;">Terrains</i>), wobei die folgenden prozeduralen Techniken miteinander kombiniert werden können:</div><div class="MsoNormal"><br />
<br />
</div><ul><li>Diamond Square</li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Cell Noise (Voronoi)</span></li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Perlin Noise</span></li>
<li><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Square Value Noise</span></li>
<li>Definition einzelner Hügel/Berge/flacher Flächen</li>
<li>Erosion</li>
<li>Digitale Filterung</li>
<li>Höhen- bzw. Steigungsabhängige Texturierung</li>
<li>usw.</li>
</ul><div class="MsoNormal"><br />
<a name='more'></a><br />
<div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Hinweise zum Erstellen eines neuen Projekts:</b></div><div class="MsoNormal"><br />
</div><ul style="margin-top: 0cm;" type="disc"><li class="MsoNormal" style="mso-list: l1 level1 lfo1; tab-stops: list 36.0pt;">Kopieren Sie den Ordner <i style="mso-bidi-font-style: normal;">GraphicsAndPhysicsFrameworkImports</i> ins Projektverzeichnis</li>
<li class="MsoNormal" style="mso-list: l1 level1 lfo1; tab-stops: list 36.0pt;">Kopieren sie alle <i style="mso-bidi-font-style: normal;">dll</i>-Dateien sowie die Konfigurationsdatei <i style="mso-bidi-font-style: normal;">ResolutionAndRendering.txt</i> aus besagtem Ordner ins gleiche Verzeichnis, in dem sich auch die exe-Datei befindet (in unseren Programmbeispielen ist dies das Bin-Verzeichnis)</li>
<li class="MsoNormal" style="mso-list: l1 level1 lfo1; tab-stops: list 36.0pt;">Binden Sie die folgenden Dateien in Ihr Projekt ein: <i style="mso-bidi-font-style: normal;">GraphicsAndPhysics_Framework_Imports.h</i>, <i style="mso-bidi-font-style: normal;">GraphicsAndPhysics_Framework_Imports.lib</i>, <i style="mso-bidi-font-style: normal;">glew32.lib</i>, <i style="mso-bidi-font-style: normal;">glew32s.lib</i>, <i style="mso-bidi-font-style: normal;">glut32.lib</i>. Die Glew- und Glut-Bibliotheken ermöglichen die Nutzung der aktuellen OpenGL-Spezifikationen unabhängig vom Framework.</li>
</ul><br />
<span style="font-size: large;"><b><a href="https://drive.google.com/uc?export=download&id=0B-5xhdD71xAtSXFua3dqVDJBcEU" target="_blank">TerrainRenderingDemonstrations.zip</a></b></span><br />
<br />
<span style="font-size: large;"><b> </b> </span></div><div class="MsoNormal"><br />
</div>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-78435465525985762772012-10-04T22:58:00.000+02:002015-02-17T17:06:57.542+01:00Unser neues E-Book: Spieleentwicklung – Mathematik, Physik, KI, Animation, Beleuchtung<div class="MsoNormal">
<div class="separator" style="clear: both; text-align: center;">
<a href="http://abload.de/img/solarsystemplanet1cqdi1.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://abload.de/img/solarsystemplanet1cqdi1.jpg" height="240" width="320" /></a></div>
Die letzten Wochen hatten es mal wieder in sich – ein neuer OpenGL-Artikel musste pünktlich für das Entwickler-Magazin fertig gestellt werden, ich habe mein bei Amazon erhältliches E-Book <b style="mso-bidi-font-weight: normal;">Spieleentwicklung – Mathematik mit Fun-Faktor</b> vollständig generalüberholt und ganz nebenbei noch ein weiteres E-Book veröffentlicht:<br />
<br />
<br />
<br />
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Spieleentwicklung – Mathematik, Physik, KI, Animation, Beleuchtung</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Motivation hierfür war der Wunsch vieler Leser nach einem Buch, das deutlich über den Rahmen des E-Books <b style="mso-bidi-font-weight: normal;">Spieleentwicklung – Mathematik mit Fun-Faktor</b> hinausgeht. Ein Buch, das zum einen die mathematischen Grundlagen behandelt und zum anderen veranschaulicht, wie sich diese in unterschiedlichen Bereichen der Spieleentwicklung (Physik, KI (künstliche Intelligenz), Animation sowie Beleuchtungsmodelle) einsetzen lassen.</div>
<div class="MsoNormal">
</div>
<br />
<div class="MsoNormal">
Über den nachfolgenden Amazon-Partnerlink gelangen Sie zur Detailseite des neuen E-Books:</div>
<a href="http://www.amazon.de/gp/product/B00HGUD6NU/ref=as_li_tf_tl?ie=UTF8&camp=1638&creative=6742&creativeASIN=B00HGUD6NU&linkCode=as2&tag=3dspieleentw-21">Spieleentwicklung - Mathematik, Physik, KI, Animation u. Beleuchtung</a><img alt="" border="0" src="http://ir-de.amazon-adsystem.com/e/ir?t=3dspieleentw-21&l=as2&o=3&a=B00HGUD6NU" height="1" style="border: none !important; margin: 0px !important;" width="1" /><br />
<br />
<a name='more'></a><br />
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Hier eine kleine Inhaltsübersicht:</b></div>
<div class="MsoNormal">
<br /></div>
<ul style="margin-top: 0cm;" type="disc">
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Vektoren, Matrizen, 3D-Transformationen, Koordinatensysteme, Polarkoordinaten</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">SSE-Programmierung</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">skelettbasierte Animationen (Kinematik, GPU-Skinning, Instancing)</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Beleuchtungsmodelle und Normal Mapping</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Deferred Lighting</span></li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Deferred Shadow Calculations</span></li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Screen Space Ambient Occlusion (SSAO)</span></li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Wegfindung, Schwarmverhalten, Flugmodelle für Raumschiffe und Lenkwaffen</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">scheinbare Sonnenbahnen im Wechsel der Jahreszeiten</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Planetenbewegung, Geschossflugbahnen, Masse-Feder-Systeme</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Bodenreibung, Luftwiderstand, dynamischer und statischer Auftrieb</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Billboard-Transformationsfunktionen (für Hintergrundobjekte, Partikeleffekte, Strahlenwaffen, Leucht-, Rauch- und Explosionsspuren)</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Bewegung des Cursors (Mauszeigers) im 3D-Raum</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Stoßprozesse und Kollisionen</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Hash-Grid-Sektorisierung</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Numerische Integrationsverfahren</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Objekt-Picking, Bildschirm- und Viewport-Koordinaten, Sichtbarkeitstests, Portale</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Kamera- und Projektionstransformationen, z-Fighting, Kameradrehungen</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Kollisions- und Schnittpunkttests mit Ebenen, Dreiecken, Bounding-Sphären, Ellipsoiden und Bounding-Boxen</li>
</ul>
<div class="MsoNormal">
<br /></div>
<br />
<br />Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-68361049240260999642012-10-03T12:35:00.005+02:002014-01-10T15:32:42.755+01:00Spieleentwicklung – OpenGL mit Fun-Faktor<div class="MsoNormal">Zugegeben, in der letzten Zeit wurde es ein wenig still auf <span class="MsoHyperlink">spieleprogrammierung.net</span> und meinen anderen Seiten. Es gab weder neue Artikel zu lesen noch habe ich neue Programmbeispiele veröffentlicht. Stattdessen habe ich die letzten Wochen damit verbracht, fieberhaft an der Fertigstellung meines neuen E-Books <b style="mso-bidi-font-weight: normal;">Spieleentwicklung – OpenGL mit Fun-Faktor</b> zu arbeiten.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Das E-Book richtet sich an Leser, die eigene Computerspiele entwickeln wollen oder sich in die Basics der 3D-Programmierung einarbeiten möchten und vermittelt die hierfür erforderlichen Grundlagen der modernen OpenGL-Programmierung.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Hier eine kleine Inhaltsübersicht:</b></div><div class="MsoNormal"><br />
</div><ul style="margin-top: 0cm;" type="disc"><li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Post Processing</span></li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Deferred Lighting</span></li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Screen Space Ambient Occlusion (SSAO)</span></li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Deferred Shadow Calculations</span></li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span lang="EN-GB" style="mso-ansi-language: EN-GB;">HDR-Rendering, Tone Mapping, Helligkeits-Adaption und Blend-Effekte</span></li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Szenenkomposition (Layered Rendering)</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Frame-Buffer- und Render-Buffer-Objekte</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Skelettanimation</span></li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Uniform-Buffer-, Texture-Buffer- und Texture-Array-Objekte</span></li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Geometry Instancing (Uniform Buffer Instancing und Texture Buffer Instancing)</span></li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Managed Rendering</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">GLSL-Shader-Programmierung</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Ressourcenmanagement</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Beleuchtungsmodelle und Normal Mapping</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Texture- und Sampler-Objekte</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Vertex-Buffer- und Index-Buffer-Objekte</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">OpenGL-Initialisierungsschritte und Aufräumarbeiten</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Grafik-Framework-Programmierung</li>
</ul><div class="MsoNormal"><br />
</div><div class="MsoNormal">Über den nachfolgenden Amazon-Partnerlink gelangen Sie zur Detailseite des neuen eBooks:<br />
</div><a href="http://www.amazon.de/gp/product/B009KQ3KUM/ref=as_li_tf_tl?ie=UTF8&camp=1638&creative=6742&creativeASIN=B009KQ3KUM&linkCode=as2&tag=3dspieleentw-21">Spieleentwicklung - OpenGL mit Fun-Faktor</a><img alt="" border="0" height="1" src="http://www.assoc-amazon.de/e/ir?t=3dspieleentw-21&l=as2&o=3&a=B009KQ3KUM" style="border: none !important; margin: 0px !important;" width="1" /><br />
<br />Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-12813170415706113352012-08-01T20:44:00.000+02:002014-01-10T15:37:13.129+01:00Spieleentwicklung – Mathematik mit Fun-FaktorDie letzten Wochen waren recht arbeitsintensiv, doch nun ist es vollbracht und unser neues E-Book<br />
<div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Spieleentwicklung – Mathematik mit Fun-Faktor</b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">ist endlich fertiggestellt.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Das E-Book richtet sich an Leser, die eigene Computerspiele entwickeln wollen oder sich in die Grundlagen der 3D-Programmierung einarbeiten möchten und vermittelt das hierfür erforderliche mathematische Handwerkszeug.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Hier eine kleine Inhaltsübersicht:</b></div><div class="MsoNormal"><br />
</div><ul style="margin-top: 0cm;" type="disc"><li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Vektoren und Matrizen</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Transformationen im 3D-Raum</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Koordinatensysteme</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Polarkoordinaten</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Kameradrehungen</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Portale</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Sichtbarkeitstests</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Objekt-Picking, Bildschirm- und Viewport-Koordinaten</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Kamera- und Projektionstransformationen, z-Fighting</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Stoßprozesse und Kollisionen</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Kollisions- und Schnittpunkttests mit Ebenen, Dreiecken, Bounding-Sphären, Ellipsoiden und Bounding-Boxen</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Hash-Grid-Sektorisierung</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Diffuse und spiegelnde Reflexion</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Normal Mapping</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Numerische Integration</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Planetenbewegung</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Kinematik als Grundlage skelettbasierter Animationen</li>
</ul><div class="MsoNormal"><br />
</div><div class="MsoNormal">Über den nachfolgenden <b>Amazon-Partnerlink</b> gelangen Sie zur Detailseite des neuen eBooks:</div><br />
<a href="http://www.amazon.de/gp/product/B008RJR9S2/ref=as_li_tf_tl?ie=UTF8&camp=1638&creative=6742&creativeASIN=B008RJR9S2&linkCode=as2&tag=3dspieleentw-21">Spieleentwicklung - Mathematik mit Fun-Faktor</a><img alt="" border="0" height="1" src="http://www.assoc-amazon.de/e/ir?t=3dspieleentw-21&l=as2&o=3&a=B008RJR9S2" style="border: none !important; margin: 0px !important;" width="1" /><br />
<br />
Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-42436038876108590832012-07-01T12:03:00.000+02:002012-07-01T12:03:33.157+02:00Kurz Notiert: OpenCL verleiht Flügel, Ruder und Räder (Entwickler Magazin 4/12)<br />
<div class="MsoNormal">
Unter dem Titel <b style="mso-bidi-font-weight: normal;">OpenCL
verleiht Flügel, Ruder und Räder</b> ist in der aktuellen Ausgabe des <b style="mso-bidi-font-weight: normal;">Entwickler Magazins</b> mein neuester
Artikel zum Thema <b style="mso-bidi-font-weight: normal;">Spieleprogrammierung
mit OpenCL</b> erschienen.</div>
<div class="MsoNormal">
Erläutert wird die Implementierung von Fahrzeugmodellen im
Rahmen einer OpenCL-basierten Physik-Engine.<br />
<br />
<div class="MsoNormal">
Download-Links zu allen Artikel-Beispielprogrammen finden
Sie auf der</div>
<div class="MsoNormal">
Webseite<br />
<br /></div>
<div class="MsoNormal">
<b><a href="http://www.graphics-and-physics-framework.spieleprogrammierung.net/" target="_blank">http://www.graphics-and-physics-framework.spieleprogrammierung.net/</a></b>.<br />
<br />
</div>
</div>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-64123287256107532082012-06-09T18:10:00.000+02:002012-09-14T09:28:03.506+02:00Texture Buffer Geometry InstancingIm Rahmen der Entwicklung eines <a href="http://www.space-combat-and-strategy.spieleprogrammierung.net/" target="_blank">Prototypen für ein Weltraum-Strategiespiel</a> galt es die Frage zu klären, wie sich eine prozedural erzeugte Galaxie mit tausenden Sternen und 3D-Nebelwolken mit nur wenigen Draw Calls darstellen lässt. Nach einer längeren Testphase mit <a href="http://www.spieleprogrammierung.net/2010/09/geometry-instancing-teil-2-verwendung.html" target="_blank">Uniform-Buffer-basiertem Geometry Instancing</a> fiel die Wahl letztlich auf den Einsatz von <a href="http://www.spieleprogrammierung.net/2012/06/opengl-texture-buffer-objekte.html" target="_blank">Texture-Buffer-Objekten</a>, da sich auf diese Weise alle Sterne und alle Nebelwolken mit jeweils einem einzigen Draw Call rendern lassen.<br />
<a name='more'></a><br />
<img src="http://vg01.met.vgwort.de/na/263d5019a0a046caa47724c221dd1901" width="1" height="1" alt=""><br />
Verantwortlich für die Initialisierung der für das Geometry Instancing benötigten Texture-Buffer-Objekte sind die <span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt;">Set_NumSunsMax()</span>-Methode der <span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt;">CGalaxyGraphics</span>-Klasse sowie die <span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt;">Set_NumNebulaObjectsMax()</span>-Methode der <span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt;">C3DNebulaSystem</span>-Klasse. Bitte haben Sie dafür Verständnis, dass wir im Rahmen dieses Artikels unser Augenmerk lediglich auf die Darstellung der Sterne richten werden:<br />
<div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: "Courier New"; font-size: 9.5pt;">void</span><span style="font-family: "Courier New"; font-size: 9.5pt;"> CGalaxyGraphics::Set_NumSunsMax(<span style="color: blue;">long</span> numSunsMax)<br />
{<br />
SAFE_DELETE_ARRAY(InstanceWorldViewProjectionMatrix)<br />
SAFE_DELETE_ARRAY(WorldSpacePosition)<br />
SAFE_DELETE_ARRAY(SunScale)<br />
SAFE_DELETE_ARRAY(SunTextureID)<br />
SAFE_DELETE_ARRAY(CameraSpacePosition)<br />
SAFE_DELETE_ARRAY(IDOfSunsNearTheCamera)<br />
<br />
SAFE_DELETE(InstanceDataArray)<br />
SAFE_DELETE(SunInstancesTBO)<br />
<br />
IDOfSunNearTheCamera = 0;<br />
MaxLocalGroupDistanceSq = 0.0f;<br />
NumOfSunsInsideLocalGroup = 0;<br />
<br />
NumSunsMax = numSunsMax;<br />
NumSunsDefined = 0;<br />
NumSunsVisible = 0;<br />
<br />
InstanceWorldViewProjectionMatrix = <span style="color: blue;">new</span> D3DXMATRIXA16[NumSunsMax];<br />
WorldSpacePosition<span style="mso-spacerun: yes;"> </span>= <span style="color: blue;">new</span> D3DXVECTOR3[NumSunsMax];<br />
SunScale<span style="mso-spacerun: yes;"> </span>= <span style="color: blue;">new</span> <span style="color: blue;">float</span>[NumSunsMax];<br />
SunTextureID<span style="mso-spacerun: yes;"> </span>= <span style="color: blue;">new</span> <span style="color: blue;">float</span>[NumSunsMax];<br />
CameraSpacePosition<span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>= <span style="color: blue;">new</span> D3DXVECTOR3[NumSunsMax];<br />
IDOfSunsNearTheCamera<span style="mso-spacerun: yes;"> </span>= <span style="color: blue;">new</span> <span style="color: blue;">long</span>[NumSunsMax];<br />
<br />
<b>SunInstancesTBO = <span style="color: blue;">new</span> CTextureBufferObject;<br />
<br />
<span style="color: green;">// Pro Sonne werden 16 float-Parameter im Texture Buffer<br />
// gespeichert:<br />
</span>SunInstancesTBO->Init_TextureBuffer(4*NumSunsMax, 4);</b> <b><br />
InstanceDataArray = <span style="color: blue;">new</span> <span style="color: blue;">float</span>[16*NumSunsMax];</b><br />
}</span></div><br />
<br />
Bei Programmstart werden zunächst alle Sterne bzw. Nebelwolken im Weltraum positioniert:<br />
<br />
<div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CGalaxyGraphics::Init_Sun(D3DXVECTOR3* pWorldSpacePosition,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">float</span> sunScale, <span style="color: blue;">long</span> sunTextureID)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(NumSunsDefined >= NumSunsMax)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span>;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">WorldSpacePosition[NumSunsDefined] = *pWorldSpacePosition;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">SunScale[NumSunsDefined] = sunScale;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">SunTextureID[NumSunsDefined] = sunTextureID;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">NumSunsDefined++;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Die <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Update_InstanceWorldViewProjectionMatrices()</span>-Methoden der <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CGalaxyGraphics</span>-Klasse sind für die Überprüfung der Sichtbarkeit der einzelnen Sterne sowie für die Berechnung der für die korrekte Darstellung benötigten World-View-Projection-Matrizen verantwortlich:</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CGalaxyGraphics::Update_InstanceWorldViewProjectionMatrices(</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">long</span> IdOfCenteredSun, <span style="color: blue;">float</span> CenteredSunScaleMultiplier,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> D3DXVECTOR3* pCameraPosition, D3DXVECTOR3* pCameraViewDirection,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> D3DXMATRIXA16* pViewProjectionMatrix, <span style="color: blue;">float</span> maxVisibilityDistanceSq)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// Diese Methode kommt immer dann zum Einsatz, wenn sich der Spieler</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// (und mit ihm die Kamera) innerhalb eines Sonnensystems (</span></b><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">IdOfCenteredSun</span><b style="mso-bidi-font-weight: normal;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">)</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// befindet! Alle weiteren Sterne liegen im Hintergrund.</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">float</span><span style="font-family: "Courier New"; font-size: 10pt;"> angle = 0.0f;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">IDOfSunNearTheCamera = 0; </span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">NumOfSunsInsideLocalGroup = 0;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">float</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> minDistanceSq = 100000000000000.0f;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">float</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> DistanceSq;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">NumSunsVisible = 0;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">float</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> modifiedScale;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">for</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(<span style="color: blue;">long</span> i = 0; i < NumSunsDefined; i++)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(IdOfCenteredSun == i)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// Position des Zentralgestirns relativ zur Kamera im Sonnensystem,</span></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;"> // in dem sich der Spieler momentan befindet:</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> </span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">CameraSpacePosition[i] = WorldSpacePosition[i] - *pCameraPosition;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">else</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// Der Abstand aller Hintergrundsterne ist unabhängig von der</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;"> </span><span lang="SV" style="color: green; font-family: "Courier New"; font-size: 10pt;">// aktuellen Position der Kamera:</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="SV" style="font-family: "Courier New"; font-size: 10pt;"> CameraSpacePosition[i] = WorldSpacePosition[i] –</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="SV" style="font-family: "Courier New"; font-size: 10pt;"> </span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">WorldSpacePosition[IdOfCenteredSun];</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// Sichtbarkeitstest:</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">DistanceSq = D3DXVec3LengthSq(&CameraSpacePosition[i]);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(DistanceSq > maxVisibilityDistanceSq)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">continue</span>;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(D3DXVec3Dot(&CameraSpacePosition[i], pCameraViewDirection) < 0.0f)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">continue</span>;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// Sichtbarkeitstest abgeschlossen</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// Speichern der Indizes aller Sterne in der näheren Umgebung</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// (wichtig sowohl für die Anzeige der Sternennamen als auch für</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// die Darstellung von Lens-Flare-Effekten!).</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(DistanceSq < MaxLocalGroupDistanceSq)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> IDOfSunsNearTheCamera[NumOfSunsInsideLocalGroup] = i;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> NumOfSunsInsideLocalGroup++;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(DistanceSq < minDistanceSq)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> minDistanceSq = DistanceSq;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> IDOfSunNearTheCamera = i;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// Berechnung der </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;">World-View-Projection-Matrizen:</span><span lang="EN-GB" style="color: green; font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(IdOfCenteredSun == i)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> modifiedScale = CenteredSunScaleMultiplier*SunScale[i];</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Positioning_2DObject_rotated(</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> &InstanceWorldViewProjectionMatrix[NumSunsVisible],</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> &CameraSpacePosition[i], modifiedScale, angle);</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">else</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <b>Positioning_2DObject_rotated(</b></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> &InstanceWorldViewProjectionMatrix[NumSunsVisible],</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> &CameraSpacePosition[i], SunScale[i], angle);</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">InstanceWorldViewProjectionMatrix[NumSunsVisible] =</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> InstanceWorldViewProjectionMatrix[NumSunsVisible]*</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> (*pViewProjectionMatrix);</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// Null-Element zum Speichern des Textur-Index zweckentfremden:</span></b><b style="mso-bidi-font-weight: normal;"><span style="font-family: "Courier New"; font-size: 10pt;"></span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">InstanceWorldViewProjectionMatrix[NumSunsVisible]._14 = SunTextureID[i];</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">NumSunsVisible++;</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Im zweiten Schritt müssen die für die Darstellung der Instanzen benötigten Daten – die Indizes der zu verwendenden Texturen sowie die Elemente der zuvor berechneten World-View-Projection-Matrizen – mithilfe der <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Update_SunInstancesTBO()</span>-Methode in den Texture Buffer kopiert werden:</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CGalaxyGraphics::Update_SunInstancesTBO(<span style="color: blue;">void</span>)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">Build_ShaderMatrix4X4Array(InstanceDataArray,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">InstanceWorldViewProjectionMatrix, NumSunsVisible);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// Pro Instance/Matrix 64 Byte (4x4=16 Elemente mit je 32 Bit bzw. 4 Byte):</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">SunInstancesTBO->Update_Buffer(InstanceDataArray, 0, 64*NumSunsVisible);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Im letzten Schritt können die sichtbaren Sterne schließlich unter Verwendung der beiden <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CGalaxyGraphics</span>-Methoden <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Render_Galaxy()</span> sowie <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Render_Galaxy_AsBackground()</span> gerendert werden:</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CGalaxyGraphics::Render_Galaxy_AsBackground(<span style="color: blue;">void</span>)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glDisable(GL_DEPTH_TEST);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glEnable(GL_BLEND);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glEnable(GL_CULL_FACE);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glCullFace(GL_FRONT); </span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">BillboardBackgroundShader->Use_Shader();</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">BillboardBackgroundShader->Set_TextureBuffer(0,</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">SunInstancesTBO->Texture, <span style="color: #a31515;">"SunInstancesTextureBuffer"</span>);</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">BillboardBackgroundShader->Set_TextureArray(1,</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">pSunTextureArray, g_MipMappingSamplerID, <span style="color: #a31515;">"SunTextureArray"</span>);</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glBindBuffer( GL_ARRAY_BUFFER, VertexBufferId);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, IndexBufferId);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">BillboardBackgroundShader->Set_VertexAttributes();</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glDrawElementsInstanced(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, NULL,</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> NumSunsVisible);</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">BillboardBackgroundShader->Stop_Using_Shader();</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glDisable(GL_BLEND);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glEnable(GL_DEPTH_TEST);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">glCullFace(GL_BACK); </span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Der Zugriff auf einen <a href="http://www.spieleprogrammierung.net/2012/06/opengl-texture-buffer-objekte.html" target="_blank">Texture Buffer</a> innerhalb eines Shader-Programms sowie die Verwendung von <a href="http://www.spieleprogrammierung.net/2012/06/opengl-texture-array-objekte.html" target="_blank">Texture Arrays</a> beim Geometry Instancing wurden bereits in den vorangegangenen Beiträgen thematisiert. Für die Sternen- und Nebeldarstellung werden nun beide Techniken wie folgt miteinander kombiniert:</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB">Vertex Shader:</span></b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">uniform samplerBuffer SunInstancesTextureBuffer;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> main()</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">int</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Index = 4*gl_InstanceID;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">mat4 matWorldViewProjection = mat4(texelFetch(SunInstancesTextureBuffer,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Index++),</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> texelFetch(SunInstancesTextureBuffer,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Index++),</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> texelFetch(SunInstancesTextureBuffer,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Index++),</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> texelFetch(SunInstancesTextureBuffer,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Index));</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: green; font-family: "Courier New"; font-size: 10pt;">// <b style="mso-bidi-font-weight: normal;">Texture-ID</b> ist im Matrixelement <b style="mso-bidi-font-weight: normal;">matWorldViewProjection[0][3]</b></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// gespeichert</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">gs_TexCoord[0] = vec4(gs_MultiTexCoord0.xy, matWorldViewProjection[0][3],</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> 1.0);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// <b style="mso-bidi-font-weight: normal;">Texture-ID</b> löschen, damit die Transformation der Vertexdaten mithilfe<br />
// <b style="mso-bidi-font-weight: normal;">matWorldViewProjection</b>-Matrix wieder korrekt funktioniert:</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">matWorldViewProjection[0][3] = 0.0;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">gl_Position = matWorldViewProjection*gs_Vertex;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB">Fragment Shader:</span></b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">uniform sampler2DArray SunTextureArray;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span style="font-family: "Courier New"; font-size: 10pt;"> main()</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// Hinweise:</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// gs_TexCoord[0].z: Index der zu verwendenden Textur (</span><span lang="EN-GB" style="color: green; font-family: "Courier New"; font-size: 10pt;"><b style="mso-bidi-font-weight: normal;">Texture-ID</b></span><span style="color: green; font-family: "Courier New"; font-size: 10pt;">)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// gs_TexCoord[0].xy: die normalen Texturkoordinaten</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">vec4 SunColor = texture(SunTextureArray, gs_TexCoord[0].xyz);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(SunColor.a < 0.01)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> discard;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> gs_FragColor = SunColor;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-60098141753216486452012-06-08T09:53:00.000+02:002012-08-23T14:00:33.523+02:00OpenGL-Texture-Buffer-ObjekteTexture-Buffer-Objekte wurden mit der OpenGL-Spezifikation 3.0 eingeführt und dienen im Unterschied zu den <a href="http://www.spieleprogrammierung.net/2010/09/opengl-uniform-buffer-objekte.html" target="_blank">Uniform-Buffer-Objekten</a> dem dynamischen Austausch <b>sehr großer</b> Datenmengen zwischen dem Haupt- und dem Grafikspeicher. Zu den Einsatzmöglichkeiten zählt die Speicherung der Geometriedaten eines 3D-Modells oder die der <a href="http://www.graphics-and-physics-framework.spieleprogrammierung.net/2011/07/tutorial-17-terrain-generation-terrain.html" target="_blank">Höhenwerte und Textur-Gewichtungsfaktoren eines Terrains</a> sowie die Darstellung einer sehr großen Anzahl von 3D-Objekten im Rahmen des Geometry-Instancings mit nur einem einzigen Draw Call.<br />
<div class="MsoNormal">Wie im nachfolgenden Beispiel gezeigt, erfolgt der Zugriff auf einen Texture Buffer in einem Shader-Programm mithilfe der <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">texelFetch()</span>-GLSL-Shaderfunktion:</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">uniform samplerBuffer SunInstancesTextureBuffer;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">[...]</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> main()</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">int</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Index = 4*gl_InstanceID;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">mat4 matWorldViewProjection = mat4(texelFetch(SunInstancesTextureBuffer,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Index++),</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> texelFetch(SunInstancesTextureBuffer,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Index++),</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> texelFetch(SunInstancesTextureBuffer,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Index++),</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> </span><span style="font-family: "Courier New"; font-size: 10pt;">texelFetch(SunInstancesTextureBuffer,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> Index));</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">[...]</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
<a name='more'></a><br />
</div><img src="http://vg01.met.vgwort.de/na/e80cdbe812f9497f9e962458fb9191bd" width="1" height="1" alt=""><br />
<div class="MsoNormal">Die Übergabe eines Texture-Buffer-Objekts an einen Shader erfolgt in unseren Programmbeispielen mithilfe der <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CGLSLShader</span>-Methode <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Set_TextureBuffer()</span>:</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CGLSLShader::Set_TextureBuffer(<span style="color: blue;">long</span> Stage, CTexture* pTexture,</span><br />
<span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">char</span>* pParameter)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// Textur bereits gesetzt:</span></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(g_StageTexture[Stage] == pTexture)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span>;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(pTexture)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> {</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(Stage > TextureStagesUsed)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> TextureStagesUsed = Stage;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glActiveTexture(GL_TEXTURE0+Stage);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glBindTexture(GL_TEXTURE_BUFFER, pTexture->TextureID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glUniform1i(glGetUniformLocation(ShaderProgram, pParameter), Stage);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> }</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> g_StageTexture[Stage] = pTexture;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Für die praktische Handhabung dieser Buffer-Objekte nutzen wir ferner die <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CTextureBufferObject</span>-Klasse unseres <a href="http://www.graphics-and-physics-framework.spieleprogrammierung.net/" target="_blank">OpenGL/OpenCL-basierten Grafik- und Physik-Frameworks</a>:</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">class</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CTextureBufferObject</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">public</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">:</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CTexture* Texture;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> GLuint TextureBufferID;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> long</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> NumBufferElements;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> long</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> NumBufferElementsTU;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> long</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> NumBufferElementsTV;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CTextureBufferObject();</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> ~CTextureBufferObject();</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Init_TextureBuffer(<span style="color: blue;">long</span> numBufferElements, <span style="color: blue;">long</span> numColorChannels,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">float</span>* pData = NULL);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Init_TextureBuffer(<span style="color: blue;">long</span> numBufferElementsTU,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">long</span> numBufferElementsTV,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">long</span> numColorChannels, <span style="color: blue;">float</span>* pData = NULL);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Update_Buffer(<span style="color: blue;">float</span>* pData, <span style="color: blue;">long</span> Size);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Update_Buffer(<span style="color: blue;">float</span>* pData, <span style="color: blue;">long</span> Offset, <span style="color: blue;">long</span> Size);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">};</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">CTextureBufferObject::CTextureBufferObject()</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Texture = NULL;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> TextureBufferID = 0;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> NumBufferElements = 0;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> NumBufferElementsTU = 0;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> NumBufferElementsTV = 0;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Texture = <span style="color: blue;">new</span> CTexture;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 9.5pt;">CTextureBufferObject::~CTextureBufferObject()</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 9.5pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 9.5pt;"> <span style="color: blue;">if</span>(TextureBufferID > 0)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 9.5pt;"> glDeleteBuffers(1, &TextureBufferID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 9.5pt;"> SAFE_DELETE(Texture)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 9.5pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Im Rahmen der täglichen Arbeit stellt man sich einen Texture Buffer sinnvollerweise als eine Kombination aus einem eindimensionalen Textur- und einem separaten Buffer-Objekt vor (das Textur-Objekt verweist auf den Speicherbereich des Buffer-Objekts). Während der Zugriff auf die im Buffer gespeicherten Daten – wie im einleitenden Source-Code-Beispiel gezeigt – innerhalb eines Shader-Programms über ein der Textur zugeordnetes <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">samplerBuffer</span>-Objekt erfolgt, so ist der Zugriff auf die im Buffer gespeicherten Daten aus dem Hauptprogramm heraus auf direkte Weise möglich. Für die Aktualisierung dieser Daten können die beiden <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Update_Buffer()</span>-Methoden der <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CTextureBufferObject</span>-Klasse verwendet werden:</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CTextureBufferObject::Update_Buffer(<span style="color: blue;">float</span>* pData, <span style="color: blue;">long</span> Size)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glBindBuffer(GL_TEXTURE_BUFFER, TextureBufferID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glBufferData(GL_TEXTURE_BUFFER, Size, pData, GL_STATIC_DRAW);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glBindBuffer(GL_TEXTURE_BUFFER, 0);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CTextureBufferObject::Update_Buffer(<span style="color: blue;">float</span>* pData, <span style="color: blue;">long</span> Offset,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">long</span> Size)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glBindBuffer(GL_TEXTURE_BUFFER, TextureBufferID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glBufferSubData(GL_TEXTURE_BUFFER, Offset, Size, pData);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> </span><span style="font-family: "Courier New"; font-size: 10pt;">glBindBuffer(GL_TEXTURE_BUFFER, 0);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Bevor nun ein Texture-Buffer-Objekt genutzt werden kann, sind die folgenden Initialisierungsschritte erforderlich:</div><div class="MsoNormal"><br />
</div><ul><li>Initialisierung des Buffer-Objekts (<span style="color: blue; font-family: "Courier New"; font-size: 10pt;">TextureBufferID</span>).</li>
<li>Initialisierung des Textur-Objekts (<span style="color: blue; font-family: "Courier New"; font-size: 10pt;">TextureID</span>).</li>
<li>Anbinden des Buffer-Objekts an das Textur-Objekt.</li>
</ul><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CTextureBufferObject::Init_TextureBuffer(<span style="color: blue;">long</span> numBufferElementsTU,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">long</span> numBufferElementsTV, <span style="color: blue;">long</span> numColorChannels, <span style="color: blue;">float</span>* pData)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(TextureBufferID > 0)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glDeleteBuffers(1, &TextureBufferID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(Texture->TextureID > 0)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glDeleteBuffers(1, &Texture->TextureID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">NumBufferElementsTU = numBufferElementsTU;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">NumBufferElementsTV = numBufferElementsTV;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">NumBufferElements = NumBufferElementsTU*NumBufferElementsTV;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: green; font-family: "Courier New"; font-size: 10pt;">// Buffer-Objekt initialisieren:</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glGenBuffers(1, &TextureBufferID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glBindBuffer(GL_TEXTURE_BUFFER, TextureBufferID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">unsigned</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">long</span> BufferSize;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> </span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(numColorChannels == 4)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> BufferSize = NumBufferElements * 4 * <span style="color: blue;">sizeof</span>(<span style="color: blue;">float</span>);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">else</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(numColorChannels == 3)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> BufferSize = NumBufferElements * 3 * <span style="color: blue;">sizeof</span>(<span style="color: blue;">float</span>);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">else</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(numColorChannels == 2)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> BufferSize = NumBufferElements * 2 * <span style="color: blue;">sizeof</span>(<span style="color: blue;">float</span>);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">else</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> BufferSize = NumBufferElements * <span style="color: blue;">sizeof</span>(<span style="color: blue;">float</span>);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(pData == NULL)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glBufferData(GL_TEXTURE_BUFFER, BufferSize, 0, GL_STATIC_DRAW);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">else</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glBufferData(GL_TEXTURE_BUFFER, BufferSize, pData, GL_STATIC_DRAW);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: green; font-family: "Courier New"; font-size: 10pt;">// Textur-Objekt initialisieren:</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glGenTextures(1, &Texture->TextureID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glBindTexture(GL_TEXTURE_BUFFER, Texture->TextureID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// Buffer-Objekt an das Textur-Objekt anbinden:</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(numColorChannels == 4)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, TextureBufferID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">else</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(numColorChannels == 3)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, TextureBufferID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">else</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(numColorChannels == 2)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, TextureBufferID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">else</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glTexBuffer(GL_TEXTURE_BUFFER, GL_R32F, TextureBufferID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glBindTexture(GL_TEXTURE_BUFFER, 0);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glBindBuffer(GL_TEXTURE_BUFFER, 0);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-67116126970945876202012-06-05T16:00:00.001+02:002012-08-24T18:49:14.075+02:00OpenGL-Texture-Array-ObjekteGeometry Instancing bietet uns die Möglichkeit, eine große Anzahl von 3D-Objekten (Terrain Tiles, Nebelwolken, Sterne, Asteroiden, etc.) mit nur wenigen Draw Calls darzustellen. Während man sich zunächst darauf beschränkte, die einzelnen Objekte lediglich individuell zu skalieren, wurde es mit der Einführung der Texture-Arrays zum ersten Male möglich, die Objekte auch gesondert zu texturieren, ohne dass man hierfür jede Textur einzeln an einen Shader übergeben muss. Auch kann bei der Auswahl der zu verwendenden Textur auf komplexe Conditional Statements verzichtet werden. Wie das nachfolgende Fragment-Shader-Beispiel zeigt, ist der Zugriff auf ein Texture-Array denkbar einfach:<br />
<div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">uniform sampler2DArray NebulaTextureArray;</span></div><div class="MsoNormal"><br />
<div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">[...]</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> main()</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// Hinweise:</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// gs_TexCoord[0].z: Index der zu verwendenden Textur</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;">// gs_TexCoord[0].xy: die normalen Texturkoordinaten</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">vec4 NebulaColor = texture(NebulaTextureArray, gs_TexCoord[0].xyz);</span></div><div class="MsoNormal"><br />
<div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">[...]</span></div><div class="MsoNormal"><br />
</div><span style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
<a name='more'></a><br />
</div><img src="http://vg01.met.vgwort.de/na/7f1c30690bfa4f00aab7f87c4385b517" width="1" height="1" alt=""><br />
<div class="MsoNormal">Für die Übergabe eines Texture-Arrays an einen Fragment Shader verwenden wir in unseren Programmbeispielen die <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CGLSLShader</span>-Framework-Methode <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Set_TextureArray()</span>:</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">Shader->Set_TextureArray(0, pNebulaTextureArray, g_MipMappingSamplerID,</span><br />
<span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: #a31515;">"NebulaTextureArray"</span>);</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CGLSLShader::Set_TextureArray(<span style="color: blue;">long</span> Stage, CTexture* pTexture,</span><br />
<span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> GLuint SamplerID, <span style="color: blue;">char</span>* pParameter)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// Textur bereits gesetzt:</span></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(g_StageTexture[Stage] == pTexture)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> </span><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">return</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> if</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(pTexture)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> {</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(Stage > TextureStagesUsed)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> TextureStagesUsed = Stage;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glActiveTexture(GL_TEXTURE0+Stage);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glBindTexture(GL_TEXTURE_2D_ARRAY, pTexture->TextureID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(g_IdOfUsedSamplerObject[Stage] != SamplerID)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> {</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> g_IdOfUsedSamplerObject[Stage] = SamplerID;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glBindSampler(Stage, SamplerID); </span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> }</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glUniform1i(glGetUniformLocation(ShaderProgram, pParameter), Stage);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> </span><span style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> g_StageTexture[Stage] = pTexture;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Bei der Initialisierung eines neuen Texture-Arrays bietet sich die folgende Vorgehensweise an:</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;">Zunächst werden die Bildinformationen sämtlicher Texturen nacheinander mithilfe von <i style="mso-bidi-font-style: normal;">SDL_Image</i> in den RAM-Speicher kopiert. In diesem Zusammenhang verhindern die beiden Helper-Funktionen <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Enable_TextureArrayGeneration()</span> sowie <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Disable_TextureArrayGeneration()</span>, dass diese Daten nicht auch automatisch in den Texturspeicher der Grafikkarte übertragen werden.</div><div class="MsoNormal">Als konkretes Beispiel betrachten wir die Erzeugung eines Texture-Arrays, welches im Rahmen des Graphics-And-Physics-Framework-Programmbeispiels <a href="http://www.graphics-and-physics-framework.spieleprogrammierung.net/2011/09/tutorial-20-procedural-galaxy-rendering.html" target="_blank"><b style="mso-bidi-font-weight: normal;">Procedural Galaxy Rendering</b></a> für die volumetrische Nebeldarstellung benötigt wird:</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> C3DNebulaSystem::Set_NewTexture(<span style="color: blue;">char</span>* pTextureFile)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(NumTexturesUsed >= NumTexturesMax)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span>;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// Texturdaten werden zunächst in ein Daten-Array im RAM-Speicher</span></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;"> // kopiert (ppNebulaTexture</span><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">beansprucht keinerlei Texturspeicher!):</span></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> </span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">Enable_TextureArrayGeneration();</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> ppNebulaTexture[NumTexturesUsed] = Load_Texture_And_Get_ResourceID(</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> &NebulaTextureResourceID[NumTexturesUsed],</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> pTextureFile, TRUE);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> NumTexturesUsed++;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Disable_TextureArrayGeneration();</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Enable_TextureArrayGeneration(<span style="color: blue;">void</span>)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// Texturdaten sollen nicht in den Grafikspeicher übertragen werden</span></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;"> // Dies geschieht erst dann, wenn das Texture Array erzeugt wird!!</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> </span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">g_Enable_TextureArrayGeneration = <span style="color: blue;">true</span>;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Disable_TextureArrayGeneration(<span style="color: blue;">void</span>)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> g_Enable_TextureArrayGeneration = <span style="color: blue;">false</span>;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Nachdem alle benötigten Texturen mithilfe der <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">C3DNebulaSystem</span>-Methode <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Set_NewTexture()</span> in den RAM-Speicher eingelesen wurden, wird das eigentliche Texture-Array nun auf folgende Weise erzeugt:</div><br />
<ul><li>Anlegen eines leeren Texture-Array-Objekts (<span style="color: blue; font-family: "Courier New"; font-size: 10pt;">pNebulaTextureArray</span>).</li>
<li>Anlegen eines temporären Arrays (<span style="color: blue; font-family: "Courier New"; font-size: 10pt;">pTextureArray</span>), in dem die Speicheradressen der einzelnen Textur-Ressourcen (<span style="color: blue; font-family: "Courier New"; font-size: 10pt;">ppNebulaTexture</span>) abgelegt werden.</li>
<li>Kopieren der Grafikdaten aus dem RAM- in den Grafikspeicher des Texture-Arrays unter Zuhilfenahme des temporären <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">pTextureArray</span>-Arrays mithilfe der <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CTexture</span>-Methode <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Build_TextureArray()</span>.</li>
<li>Löschen des temporären Arrays sowie Freigabe der nun nicht mehr benötigten <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">ppNebulaTexture</span>-Ressourcen.</li>
</ul><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> C3DNebulaSystem::Build_TextureArray(<span style="color: blue;">void</span>)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(NumTexturesUsed < 1)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span>;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// einzigartige Bezeichnung für das Texture Array generieren:</span></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> </span><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">long</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> UniqueID = GetTickCount();</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">char</span> strBuffer[100];</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> sprintf(strBuffer,<span style="color: #a31515;">"3DNebulaTextureArray_%d"</span>, UniqueID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;"> // leeres Texture-Array-Objekt anlegen:</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> pNebulaTextureArray = Get_Texture_And_ResourceID(</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> &NebulaTextureArrayResourceID, strBuffer);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CTexture** pTextureArray = <span style="color: blue;">new</span> CTexture*[NumTexturesUsed];</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> long</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> i;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> for</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(i = 0; i < NumTexturesUsed; i++)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> pTextureArray[i] = ppNebulaTexture[i];</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// alle Grafikdaten in das Texture-Array-Objekt kopieren:</span></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> </span><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">pNebulaTextureArray->Build_TextureArray(pTextureArray, NumTexturesUsed);</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> SAFE_DELETE_ARRAY(pTextureArray)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(NumTexturesUsed > 0)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> {</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">for</span>(i = 0; i < NumTexturesUsed; i++)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> Release_Texture(&ppNebulaTexture[i]);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> </span><span style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;">}</span><br />
<br />
<div class="MsoNormal"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Normale Tabelle";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style> <![endif]--> <br />
<div class="MsoNormal">Um den entscheidenen Schritt – das Kopieren der Texturdaten aus dem RAM- in den Grafikspeicher – besser nachvollziehen zu können, betrachten wir uns die <span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">Build_TextureArray()</span>-Methode unserer <span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">CTexture</span>-Klasse im Folgenden einmal etwas genauer:</div></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CTexture::Build_TextureArray(CTexture** ppTextureList,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">long</span> NumTextures)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">{</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(TextureObject_Initialized == <span style="color: blue;">true</span>)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span>;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">if</span>(TextureID > 0)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glDeleteTextures(1, &TextureID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;">// leeres Texture-Array-Objekt im Grafikspeicher anlegen:</span></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> glGenTextures(1, &TextureID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: "Courier New"; font-size: 10pt;"> </span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glBindTexture( GL_TEXTURE_2D_ARRAY, TextureID);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, ppTextureList[0]->Width,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> ppTextureList[0]->Height, NumTextures, 0, GL_BGRA,</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> GL_UNSIGNED_BYTE, NULL);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">long</span> i;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> for</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(i = 0; i < NumTextures; i++)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> </span><span style="font-family: "Courier New"; font-size: 10pt;">{<br />
<b style="mso-bidi-font-weight: normal;"><span style="color: green;">// Texturdaten nacheinander in den Grafikspeicher des Texture-Arrays</span></b></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;"> // kopieren:</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span style="font-family: "Courier New"; font-size: 10pt;"> </span></b><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i,</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> ppTextureList[i]->Width, ppTextureList[i]->Height, 1,</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> GL_BGRA, GL_UNSIGNED_BYTE,</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><b style="mso-bidi-font-weight: normal;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> ppTextureList[i]->TextureDataRAM);</span></b></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> }</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> glGenerateMipmap(GL_TEXTURE_2D_ARRAY); </span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;"> for</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">(i = 0; i < NumTextures; i++)</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> ppTextureList[i]->Delete_Texture();</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> RenderToTexture = FALSE;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> GenerateMipMaps = TRUE;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> TextureObject_Initialized = <span style="color: blue;">true</span>;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-57130327362549133982012-04-17T10:03:00.001+02:002012-07-01T12:02:20.858+02:00Kurz Notiert: Die Einstein-Engine (Entwickler Magazin 3/12)<div class="separator" style="clear: both; text-align: center;">
<a href="http://img718.imageshack.us/img718/9050/openclrigidbodies.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="240" src="http://img718.imageshack.us/img718/9050/openclrigidbodies.jpg" width="320" /></a></div>
Unter dem Titel <b style="mso-bidi-font-weight: normal;">Die Einstein-Engine</b>
ist in der aktuellen Ausgabe des <b style="mso-bidi-font-weight: normal;">Entwickler
Magazins</b> mein neuester Artikel zum Thema <b style="mso-bidi-font-weight: normal;">Spieleprogrammierung mit OpenCL</b> erschienen.<br />
<div class="MsoNormal">
Erläutert werden der Aufbau und die Funktionsweise einer
OpenCL-basierten Physik-Engine.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Download-Links zu allen Artikel-Beispielprogrammen finden
Sie auf der</div>
<div class="MsoNormal">
Webseite<br />
<br /></div>
<div class="MsoNormal">
<b><a href="http://www.graphics-and-physics-framework.spieleprogrammierung.net/" target="_blank">http://www.graphics-and-physics-framework.spieleprogrammierung.net/</a></b>.<br />
<br />
</div>
</div>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-54298732135512071822012-04-02T20:13:00.001+02:002012-04-03T19:46:36.848+02:00Neufassung des Artikels: Thread-basierte (Kollisions)berechnungen – Worker-Threads, Events und Interlocked-FunktionenDer Artikel zum Thema <b style="mso-bidi-font-weight: normal;">Thread-basierte
Kollisionsberechnungen</b> wurde komplett neu verfasst. Besonderes Augenmerk
gilt nun dem praktischen Einsatz und der Funktionsweise von:<br />
<br />
<ul>
<li><b style="mso-bidi-font-weight: normal;">Worker-Threads</b></li>
<li><b style="mso-bidi-font-weight: normal;">Events sowie </b></li>
<li><b style="mso-bidi-font-weight: normal;">Interlocked-Funktionen</b></li>
</ul>
<br />
<b style="mso-bidi-font-weight: normal;">Link zum Artikel:</b>
<a href="http://www.spieleprogrammierung.net/2010/09/thread-basierte-kollisionsberechnungen.html" target="_blank">Thread-basierte (Kollisions)berechnungen – Worker-Threads, Events und Interlocked-Funktionen</a>
<br />
<br />Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-24515319144963517082012-02-18T12:27:00.004+01:002012-02-19T11:02:52.272+01:00Kurz Notiert: Spieleprogrammierung mit OpenCL (Entwickler Magazin 2/12)Interessieren Sie sich für OpenCL oder den Einsatz von
physikalischen Simulationen in Computerspielen (Spielephysik / Game Physics)?<br />
<br />
<div class="MsoNormal">
Unter dem Titel <b style="mso-bidi-font-weight: normal;">„Asteroidenhagel
selbst gemacht“</b> behandelt mein neuester Artikel im <b style="mso-bidi-font-weight: normal;">Entwickler-Magazin (Ausgabe 2/12)</b> die Grundlagen der
OpenCL-Programmierung und beleuchtet darüber hinaus verschiedene
Einsatzmöglichkeiten im Rahmen der Spieleentwicklung.</div>
<div class="MsoNormal">
<br />
<a name='more'></a><br /></div>
<div class="MsoNormal">
Download-Links zu allen Artikel-Beispielprogrammen finden
Sie auf der</div>
<div class="MsoNormal">
Webseite<br />
<br /></div>
<div class="MsoNormal">
<b><a href="http://www.graphics-and-physics-framework.spieleprogrammierung.net/" target="_blank">http://www.graphics-and-physics-framework.spieleprogrammierung.net/</a></b> (Tutorial 21 und 22).</div>
<div class="MsoNormal">
<br />
<br /></div>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-50711595286353451882012-01-22T17:36:00.000+01:002012-01-22T17:36:34.154+01:00Update der OpenGL ProgrammbeispieleKurz Notiert – alle Programmbeispiele sind dahingehend überarbeitet worden, um mögliche Kompatibilitätsprobleme mit dem neuesten AMD Catalyst Treiber 12.1 zu beheben. Die überarbeiteten Demoprogramme stehen ab sofort zum Download bereit.Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-63858451040766898342012-01-05T20:50:00.024+01:002017-03-14T18:47:29.073+01:00OpenCL Tutorial – Offline Compilation (Download)<div class="separator" style="clear: both; text-align: center;">
<a href="http://img694.imageshack.us/img694/8013/asteroids1.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://img694.imageshack.us/img694/8013/asteroids1.jpg" height="240" width="320" /></a></div>
In der Regel werden OpenCL-Programme zur Laufzeit für ein zuvor ausgewähltes Gerät – beispielsweise für die in einem Rechner verbaute Grafikkarte – kompiliert. Alternativ zu diesem als Online Compilation bekannten Verfahren, lassen sich auch bereits im Vorfeld kompilierte Programme verwenden (Offline Compilation). Der Nachteil der Offline Compilation besteht jedoch darin, dass ein vorkompiliertes Programm immer nur auf einer einzigen Plattform und einem einzigen Gerät lauffähig ist.<br />
<br />
<br />
<br />
<br />
Für das heutige Tutorial wurde die <span style="color: blue; font-family: "courier new"; font-size: 10pt;">COpenCLProgram</span>-Klasse aus dem letzten Programmbeispiel dahingehend erweitert,<br />
<br />
<br />
<ul>
<li>dass sich OpenCL-Programme kompilieren und im Anschluss daran abspeichern lassen (Offline Compilation, <span style="color: blue; font-family: "courier new"; font-size: 10pt;">Build_PrecompiledClBinary()</span>) und<br />
</li>
<li>dass nunmehr auch vorkompilierte Programme verwendet werden können (<span style="color: blue; font-family: "courier new"; font-size: 10pt;">Build_ProgramFromPrecompiledClBinary()</span>).</li>
</ul>
<br />
<ul></ul>
<ul></ul>
<div class="MsoNormal" style="margin: 0cm 0cm 0pt;">
</div>
<a name='more'></a><b>Hinweis:</b> <br />
<div class="MsoNormal">
Für die Ausführung dieses Programmbeispiels muss der Treiber Ihrer Grafikkarte die OpenGL Version 3.3 unterstützen.</div>
<br />
<b>Visual C++ 2010: <a href="https://drive.google.com/uc?export=download&id=0B-5xhdD71xAteE5aUmY3S1k0a1k" target="_blank">DemoWithOpenGL2010_Tut49</a></b> <b> </b><br />
<b> </b> <br />
<div class="MsoNormal">
</div>
Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-18339468008365078252011-11-16T15:14:00.004+01:002012-06-29T12:53:55.358+02:00Speicherverwaltung – Random Memory AllocationGutes Ressourcenmanagement zählt zu den wichtigsten Herausforderungen bei der Entwicklung eines Computerspiels. Bei der Darstellung von detailreichen und weitläufigen Spielewelten müssen kontinuierlich die hierfür benötigten Geometrie- und Textur-Daten geladen und die nicht mehr benötigten Daten aus dem Speicher entfernt werden (Streaming). Betrachten wir als Beispiel das Spiel <b style="mso-bidi-font-weight: normal;">Minecraft</b>. Lediglich die Teile der Spielewelt, die sich im näheren Umfeld des Spielers befinden, werden auch wirklich in den Speicher geladen. Die Welt wird hierbei in sogenannte Chunks eingeteilt, wobei jeder Chunk aus 16 (Breite) mal 16 (Länge) mal 128 (Höhe) Blöcken besteht. Insgesamt werden 81 Chunks im Speicher gehalten, die in einem 9 mal 9 Quadrat um den Spieler herum gruppiert sind.<br />
Betrachten wir als zweites Beispiel kurzlebige Spieleobjekte wie Waffenprojektile und Trümmerteile die noch dazu in großer Zahl auftreten. Der für diese Objekte benötigte Speicher muss sich möglichst schnell dynamisch allozieren (zuweisen) und wieder freigeben lassen. Kurzum, ohne eine vernünftige Speicherverwaltung sind wir völlig aufgeschmissen.<br />
<a name='more'></a><img src="http://vg01.met.vgwort.de/na/f0ef0f945b764ec39046bdabe5aca5b0" width="1" height="1" alt="">In C++ lassen sich dynamische Speicherbereiche mithilfe der Operatoren <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">new</span> und <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">delete</span> anfordern und wieder freigeben. Man hat jedoch keine Kontrolle darüber, welche Speicherbereiche man zugeteilt bekommt, was bei übermäßigem Gebrauch letzten Endes zu einer zunehmenden Fragmentierung des Speichers führt.<br />
<div class="MsoNormal">Zweckmäßigerweise sollten <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">new</span> und <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">delete</span> lediglich bei Programmstart (Anfordern des maximal benötigten Speichers) und Programmende (Freigabe des bei Programmstarts angeforderten Speichers) verwendet werden. Zur Laufzeit sollte die dynamische Speicherzuteilung und -freigabe mittels eines eigenen Speichermanagers erfolgen.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Betrachten wir als Beispiel die Klasse <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CSimpleObjectInstance</span> als Prototypen für ein beliebiges Spieleobjekt. Bei Programmstart würden wir zunächst ein Array aus Klasseninstanzen anlegen, wobei die Anzahl der Arrayelemente der maximal möglichen Anzahl von Spieleobjekten entspricht. Zunächst sind die einzelnen Arrayelemente noch unbenutzt (<span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">used == <span style="color: blue;">true</span></span>).</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">class</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CSimpleObjectInstance<br />
{<br />
<span style="color: blue;">public</span>:<br />
<br />
<span style="color: blue;">bool</span> used;<br />
<span style="color: blue;">long</span> ID;<br />
<br />
CSimpleObjectInstance();<br />
~CSimpleObjectInstance();<br />
<br />
<span style="color: blue;">void</span> Initialize(<span style="color: blue;">long</span> id);<br />
<span style="color: blue;">void</span> TurnBack(<span style="color: blue;">void</span>);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">};</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">CSimpleObjectInstance::CSimpleObjectInstance()<br />
{<br />
used = <span style="color: blue;">false</span>;<br />
ID = -1;<br />
}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CSimpleObjectInstance::Initialize(<span style="color: blue;">long</span> id)<br />
{<br />
used = <span style="color: blue;">true</span>;<br />
ID = id;<br />
}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CSimpleObjectInstance::TurnBack(<span style="color: blue;">void</span>)<br />
{<br />
used = <span style="color: blue;">false</span>;<br />
ID = -1;<br />
}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span lang="EN-GB">Die Klasse </span><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">CSimpleObjectInstancePool</span><span lang="EN-GB"> übernimmt die Aufgabe de</span>s Speichermanagers und ist für die Verwaltung des <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CSimpleObjectInstance</span>-Arrays verantwortlich.</div><div class="MsoNormal"><br />
</div><ul style="margin-top: 0cm;" type="disc"><li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Die Methode <b style="mso-bidi-font-weight: normal;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Init_ObjectInstancePool()</span></b> erzeugt zunächst ein Array aus <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CSimpleObjectInstance</span>-Klasseninstanzen.</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Die <b style="mso-bidi-font-weight: normal;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Get_Unused_ObjectInstance()</span></b>-Methode sucht nach einem aktuell unbenutzten Arrayelement und liefert einen Zeiger auf ein solches zurück. Die <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CSimpleObjectInstance</span>-Membervariable <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">used</span> wird zuvor auf <span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">true</span> gesetzt.</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Die Methode <b style="mso-bidi-font-weight: normal;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Release_ObjectInstance()</span></b> gibt ein momentan verwendetes Arrayobjekt wieder frei, indem die <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">CSimpleObjectInstance</span>-Membervariable <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">used</span> wieder auf <span style="color: blue; font-family: "Courier New"; font-size: 10pt;">false</span> gesetzt wird.</li>
</ul><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">class</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CSimpleObjectInstancePool<br />
{<br />
<span style="color: blue;">public</span>:<br />
<br />
<span style="color: blue;">long</span> NumObjectInstancesMax;<br />
<span style="color: blue;">long</span> NumObjectInstancesUsed;<br />
<br />
CSimpleObjectInstance* ObjectInstance;<br />
<br />
CSimpleObjectInstancePool();<br />
~CSimpleObjectInstancePool();<br />
<br />
<span style="color: blue;">void</span> Init_ObjectInstancePool(<span style="color: blue;">long</span> numObjectInstancesMax);<br />
<br />
CSimpleObjectInstance* Get_Unused_ObjectInstance(<span style="color: blue;">void</span>);<br />
<span style="color: blue;">void</span> Release_ObjectInstance(CSimpleObjectInstance** ppObjectInstance);</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">};</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CSimpleObjectInstancePool::Init_ObjectInstancePool(<br />
<span style="color: blue;">long</span> numObjectInstancesMax)<br />
{<br />
NumObjectInstancesMax = numObjectInstancesMax;<br />
NumObjectInstancesUsed = 0;<br />
<br />
SAFE_DELETE_ARRAY(ObjectInstance)<br />
<br />
ObjectInstance = <span style="color: blue;">new</span> CSimpleObjectInstance[NumObjectInstancesMax];<br />
<br />
<span style="color: blue;">for</span>(<span style="color: blue;">long</span> i = 0; i < NumObjectInstancesMax; i++)<br />
ObjectInstance[i].ID = i;</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Mehr noch als in konventionellen Anwendungen kommt es in Computerspielen darauf an, dass Speicher so schnell wie möglich zugewiesen und wieder freigegeben werden kann. Im konkreten Fall benötigen wir also für unsere <b style="mso-bidi-font-weight: normal;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">Get_Unused_ObjectInstance()</span></b>-Methode ein Verfahren für die schnelle Suche eines momentan unbenutzten Arrayelements.</div><div class="MsoNormal">Beim einfachsten aber auch langsamsten Verfahren würde man das komplette Array nach einem unbenutzten Element durchsuchen und die Suche bei Erfolg abbrechen. Die Suchzeit würde jedoch hierbei linear mit der Anzahl der bereits genutzten Elemente ansteigen.</div><div class="MsoNormal">Im Unterschied dazu erfordert die sogenannte <b style="mso-bidi-font-weight: normal;">Random Memory Allocation</b> weitaus weniger Suchschritte. Hierbei wird nach dem Zufallsprinzip ein Arrayelement ausgesucht. Ist dieses Arrayelement unbenutzt, kann die weitere Suche eingestellt werden. Sind beispielsweise <b style="mso-bidi-font-weight: normal;">50%</b> der Arrayelemente in Benutzung, so sind im Durchschnitt <b style="mso-bidi-font-weight: normal;">lediglich zwei Versuche</b> notwendig (<b style="mso-bidi-font-weight: normal;">Suchtiefe 2</b>), um ein unbenutztes Element zu finden. <span lang="EN-GB">Bei <b style="mso-bidi-font-weight: normal;">75%</b> benutzter Arrayelemente ist mit durchschnittlich <b style="mso-bidi-font-weight: normal;">4 Suchschritten</b> zu rechnen:</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">CSimpleObjectInstance* CSimpleObjectInstancePool::<br />
Get_Unused_ObjectInstance(<span style="color: blue;">void</span>)<br />
{<br />
<span style="color: blue;">if</span>(NumObjectInstancesMax == NumObjectInstancesUsed)<br />
<span style="color: blue;">return</span> NULL;<br />
<br />
<span style="color: blue;">long</span> id;<br />
<span style="color: blue;">bool</span> used = <span style="color: blue;">false</span>;<br />
<span style="color: blue;">long</span> counter = 0;<br />
<br />
<span style="color: green;">// Maximale Anzahl von Suchschritten (Suchtiefe)</span><br />
<span style="color: blue;">long</span> counterMax = 100*NumObjectInstancesMax;<br />
<br />
<span style="color: blue;">do<br />
</span> {<br />
id = RandomNumbers.Next_IntegerNumber(0, NumObjectInstancesMax);<br />
<br />
used = ObjectInstance[id].used;<br />
<br />
<span style="color: blue;">if</span>(used == <span style="color: blue;">false</span>)<br />
<span style="color: blue;">break</span>;<br />
<br />
counter++;<br />
<br />
}<br />
<span style="color: blue;">while</span>(counter < counterMax);<br />
<br />
<span style="color: blue;">if</span>(used == <span style="color: blue;">false</span>)<br />
{<br />
NumObjectInstancesUsed++;<br />
ObjectInstance[id].used = <span style="color: blue;">true</span>;<br />
<span style="color: blue;">return</span> &ObjectInstance[id];<br />
}<br />
<span style="color: blue;">else<br />
</span> <span style="color: blue;">return</span> NULL;<br />
}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="color: blue; font-family: "Courier New"; font-size: 10pt;">void</span><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;"> CSimpleObjectInstancePool::Release_ObjectInstance(<br />
CSimpleObjectInstance** ppObjectInstance)<br />
{<br />
<span style="color: green;">// Release unnötig / Zeiger enthält keine Adresse<br />
</span> <span style="color: blue;">if</span>(*ppObjectInstance == NULL)<br />
<span style="color: blue;">return</span>;<br />
<br />
<span style="color: blue;">if</span>((*ppObjectInstance)->used == <span style="color: blue;">true</span>)<br />
{<br />
NumObjectInstancesUsed--;<br />
(*ppObjectInstance)->used = <span style="color: blue;">false</span>;<br />
*ppObjectInstance = NULL;<br />
}</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span lang="EN-GB" style="font-family: "Courier New"; font-size: 10pt;">}</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-29016256386694990242011-09-26T15:06:00.005+02:002017-03-14T18:48:01.706+01:00OpenCL Tutorial – Masspoint Movement, Collision Hash Grids (Download)<div class="separator" style="clear: both; text-align: center;">
<a href="http://img694.imageshack.us/img694/8013/asteroids1.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://img694.imageshack.us/img694/8013/asteroids1.jpg" height="240" width="320" /></a></div>
Der Schwerpunkt des heutigen Tutorials liegt im Entwurf eines einfachen OpenCL-Frameworks sowie in der Implementierung einer einfachen OpenCL-basierten Bewegungssimulation für ein Asteroidenfeld:<br />
<div class="MsoNormal">
<br /></div>
<ul style="margin-top: 0cm;" type="disc">
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Simulation der Asteroiden-Bewegung (jedem Asteroid ist eine einzelne Punktmasse zugeordnet).</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;">Berechnung der Gitter-Indices und -Positionen in einem Kollisionsgitter (Collision Hash Grid) für eine effiziente Kollisionsprüfung.</li>
</ul>
<div class="MsoNormal">
<br />
<br />
<a name='more'></a><br /></div>
<div class="MsoNormal">
Für die Initialisierung einer OpenCL-Anwendung ist die <span style="color: blue; font-family: "courier new"; font-size: 10pt;">COpenCLDevice</span>-Klasse verantwortlich:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "courier new"; font-size: 10pt;">class</span><span style="font-family: "courier new"; font-size: 10pt;"> COpenCLDevice<br />
{<br />
<span style="color: blue;">public</span>:<br />
<br />
cl_platform_id Platform;<br />
cl_device_id Device;<br />
cl_context DeviceContext;<br />
cl_command_queue DeviceCommandQueue;<br />
<br />
<span style="color: blue;">bool</span> use_GPU_Device;<br />
<br />
COpenCLDevice();<br />
~COpenCLDevice();<br />
<br />
<span style="color: blue;">void</span> Init_Device(<span style="color: blue;">bool</span> useGPU);<br />
<span style="color: blue;">void</span> Wait(<span style="color: blue;">void</span>);<br />
};</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Zuständig für die Handhabung eines einzelnen OpenCL-Programms (Kernel) ist die <span style="color: blue; font-family: "courier new"; font-size: 10pt;">COpenCLProgram</span>-Klasse:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "courier new"; font-size: 10pt;">class</span><span style="font-family: "courier new"; font-size: 10pt;"> COpenCLProgram<br />
{<br />
<span style="color: blue;">public</span>:<br />
<br />
cl_program Program;<br />
cl_kernel Kernel;<br />
<br />
cl_uint WorkGroupDim;<br />
size_t local_ws;<br />
size_t global_ws;<br />
size_t MaxBufferElements;<br />
<br />
COpenCLDevice* pUsedOpenCLDevice;<br />
<br />
COpenCLProgram();<br />
~COpenCLProgram();<br />
<br />
<span style="color: blue;">void</span> Set_OpenCLDevice(COpenCLDevice* pOpenCLDevice);<br />
<br />
</span><span style="color: green; font-family: "courier new"; font-size: 9.5pt;">// Laden und Kompilieren eines OpenCl-Programms</span><span style="font-family: "courier new"; font-size: 10pt;"><br />
<span style="color: blue;">void</span> Build_ProgramFromSourceFile(<span style="color: blue;">char</span> *pKernelName, <span style="color: blue;">char</span> *pFileName,<br />
cl_uint workGroupDim, <span style="color: blue;">bool</span> fastMath, size_t maxBufferElements,<br />
size_t num_WorkItems_Per_WorkGroup = 0);<br />
<br />
</span><span style="color: green; font-family: "courier new"; font-size: 9.5pt;">// Ausführen eines OpenCL-Programms:</span><span style="font-family: "courier new"; font-size: 10pt;"><br />
<span style="color: blue;">void</span> Execute_Program(<span style="color: blue;">void</span>);<br />
<span style="color: blue;">void</span> Execute_Program_With_UserDefined_Num_WorkItems_Per_WorkGroup(<span style="color: blue;">void</span>);<br />
<br />
<span style="color: blue;">void</span> Execute_Program(cl_uint numEventsInWaitList, <span style="color: blue;">const</span> cl_event<br />
*pEventWaitList, cl_event *pEvent);<br />
<span style="color: blue;">void</span> Execute_Program_With_UserDefined_Num_WorkItems_Per_WorkGroup(<br />
cl_uint numEventsInWaitList, <span style="color: blue;">const</span> cl_event *pEventWaitList,<br />
cl_event *pEvent);<br />
<br />
</span><span style="color: green; font-family: "courier new"; font-size: 9.5pt;">// Methoden für die Parameter-Übergabe an ein OpenCL-Programm (Kernel):</span><span style="font-family: "courier new"; font-size: 10pt;"><br />
<span style="color: blue;">void</span> Set_KernelArg(cl_uint pos, cl_mem* pInput);<br />
<span style="color: blue;">void</span> Set_KernelArg(cl_uint pos, <span style="color: blue;">int</span> input);<br />
<span style="color: blue;">void</span> Set_KernelArg(cl_uint pos, <span style="color: blue;">double</span> input);<br />
<span style="color: blue;">void</span> Set_KernelArg(cl_uint pos, <span style="color: blue;">float</span> input);<br />
<span style="color: blue;">void</span> Set_KernelArg(cl_uint pos, size_t input);<br />
};</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Die nachfolgenden Container-Klassen (Arrays von Vektoren und Skalaren) fungieren als Schittstelle zwischen einem OpenCL-Kernel und dem Hauptprogramm:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;">
<span lang="EN-GB" style="color: blue; font-family: "courier new"; font-size: 10pt;">class</span><span lang="EN-GB" style="font-family: "courier new"; font-size: 10pt;"> COpenCL_FloatScalar_Container;<br />
<span style="color: blue;">class</span> COpenCL_2DFloatVector_Container;<br />
<span style="color: blue;">class</span> COpenCL_3DFloatVector_Container;<br />
<span style="color: blue;">class</span> COpenCL_4DFloatVector_Container;<br />
<br />
<span style="color: blue;">class</span> COpenCL_IntegerScalar_Container;<br />
<span style="color: blue;">class</span> COpenCL_2DIntegerVector_Container;<br />
<span style="color: blue;">class</span> COpenCL_3DIntegerVector_Container;<br />
<span style="color: blue;">class</span> COpenCL_4DIntegerVector_Container;<br />
<span style="color: blue;">class</span> COpenCL_NDIntegerVector_Container;</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Die nachfolgenden Klassen ermöglichen den Zugriff auf einzelne Elemente der Container-Klassen aus dem Hauptprogramm heraus:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "courier new"; font-size: 10pt;">class</span><span style="font-family: "courier new"; font-size: 10pt;"> COpenCL_FloatScalar;<br />
<span style="color: blue;">class</span> COpenCL_2DFloatVector;<br />
<span style="color: blue;">class</span> COpenCL_3DFloatVector;<br />
<span style="color: blue;">class</span> COpenCL_4DFloatVector;<br />
<br />
<span style="color: blue;">class</span> COpenCL_IntegerScalar;<br />
<span style="color: blue;">class</span> COpenCL_2D IntegerVector;<br />
<span style="color: blue;">class</span> COpenCL_3D IntegerVector;<br />
<span style="color: blue;">class</span> COpenCL_4D IntegerVector;<br />
<span style="color: blue;">class</span> COpenCL_NDIntegerVector;</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Verantwortlich für die Durchführung der Bewegungssimulation ist der nachfolgende OpenCL-Kernel:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "courier new"; font-size: 10pt;">__kernel <span style="color: blue;">void</span> MasspointMovement_GPU(__global float4* Position,<br />
__global float4* Velocity,<br />
__global int4* GridPosition,<br />
__global int4* GridIndex,<br />
<span style="color: blue;">const</span> <span style="color: blue;">float</span> TimeStep,<br />
<span style="color: blue;">const</span> <span style="color: blue;">float</span> InvGridSize,<br />
<span style="color: blue;">const</span> <span style="color: blue;">float</span> GridOffset,<br />
<span style="color: blue;">const</span> <span style="color: blue;">float</span> GridCenterX,<br />
<span style="color: blue;">const</span> <span style="color: blue;">float</span> GridCenterY,<br />
<span style="color: blue;">const</span> <span style="color: blue;">float</span> GridCenterZ,<br />
<span style="color: blue;">const</span> <span style="color: blue;">int</span> HalfNumCollisionGridElementsXDirPlus1,<br />
<span style="color: blue;">const</span> <span style="color: blue;">int</span> HalfNumCollisionGridElementsYDirPlus1,<br />
<span style="color: blue;">const</span> <span style="color: blue;">int</span> HalfNumCollisionGridElementsZDirPlus1,<br />
<span style="color: blue;">const</span> <span style="color: blue;">int</span> HalfNumCollisionGridElementsXDirMinus1,<br />
<span style="color: blue;">const</span> <span style="color: blue;">int</span> HalfNumCollisionGridElementsYDirMinus1,<br />
<span style="color: blue;">const</span> <span style="color: blue;">int</span> HalfNumCollisionGridElementsZDirMinus1)<br />
{<br />
size_t id = get_global_id(0);<br />
<br />
</span><span style="color: green; font-family: "courier new"; font-size: 9.5pt;">// Bewegungs-Simulation (kräftefrei):</span><span style="font-family: "courier new"; font-size: 10pt;"><br />
Position[id] += Velocity[id]*TimeStep;<br />
<br />
</span><span style="color: green; font-family: "courier new"; font-size: 9.5pt;">// Gitterkoordinaten berechnen:</span><span style="font-family: "courier new"; font-size: 10pt;"><br />
GridPosition[id].x = (<span style="color: blue;">int</span>)(GridOffset+<br />
(Position[id].x-GridCenterX)*InvGridSize);<br />
GridPosition[id].y = (<span style="color: blue;">int</span>)(GridOffset+<br />
(Position[id].y-GridCenterY)*InvGridSize);<br />
GridPosition[id].z = (<span style="color: blue;">int</span>)(GridOffset+<br />
(Position[id].z-GridCenterZ)*InvGridSize);<br />
<br />
</span><span style="color: green; font-family: "courier new"; font-size: 9.5pt;">// Hash-Grid-Index berechnen:</span><span style="font-family: "courier new"; font-size: 10pt;"><br />
GridIndex[id].x =<br />
GridPosition[id].x % HalfNumCollisionGridElementsXDirPlus1 +<br />
HalfNumCollisionGridElementsXDirMinus1;<br />
<br />
GridIndex[id].y =<br />
GridPosition[id].y % HalfNumCollisionGridElementsYDirPlus1 +<br />
HalfNumCollisionGridElementsYDirMinus1;<br />
<br />
GridIndex[id].z =<br />
GridPosition[id].z % HalfNumCollisionGridElementsZDirPlus1 +<br />
HalfNumCollisionGridElementsZDirMinus1;<br />
}</span><span style="color: green; font-family: "courier new"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<b>Hinweis:</b><br />
<div class="MsoNormal">
Für die Ausführung dieses Programmbeispiels muss der Treiber Ihrer Grafikkarte die OpenGL Version 3.3 unterstützen. </div>
<div class="MsoNormal">
<br /></div>
<b>Visual C++ 2010: <a href="https://drive.google.com/uc?export=download&id=0B-5xhdD71xAtYm5hZy03bHdsOEk" target="_blank">DemoWithOpenGL2010_Tut48</a></b><a href="http://dl.dropbox.com/u/6748497/DemoWithOpenGL2010_Tut46.zip" target="_blank"> </a><br />
<div class="MsoNormal">
<br />
<br /></div>
Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-37590535371435309592011-09-16T16:11:00.000+02:002011-09-16T16:11:47.214+02:00Neufassung der Artikelserie zum Thema WegfindungDie Artikel zum Thema Wegfindung wurden komplett neu verfasst und orientieren sich nun direkt an den folgenden Programmbeispielen:<br />
<div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">OpenGL-Programmbeispiel:</b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><a href="http://www.spieleprogrammierung.net/2010/04/opengl-3-wegpunkte-navigation-download.html" target="_blank">http://www.spieleprogrammierung.net/2010/04/opengl-3-wegpunkte-navigation-download.html</a></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">OpenGL-Framework-Programmbeispiel:</b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><a href="http://www.graphics-and-physics-framework.spieleprogrammierung.net/2011/05/tutorial-13-wegfindung-flocking.html" target="_blank">http://www.graphics-and-physics-framework.spieleprogrammierung.net/2011/05/tutorial-13-wegfindung-flocking.html</a></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Artikel 1: <a href="http://www.spieleprogrammierung.net/2010/03/ki-programmierung-teil-7-wegfindung.html" target="_blank">Wegfindung – Einführung</a></b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Artikel 2: <a href="http://www.spieleprogrammierung.net/2010/03/ki-programmierung-teil-9-entwurf-eines.html" target="_blank">Entwurf eines Wegpunkte-Systems</a></b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Artikel 3: <a href="http://www.spieleprogrammierung.net/2010/03/ki-programmierung-teil-10-routinen-fur.html" target="_blank">Routinen für die Wegfindung</a></b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-34673929997954641082011-08-24T10:17:00.000+02:002017-03-14T18:45:22.989+01:00OpenGL Tutorial (Version 3.3) – Skelett-Animation und Geometry Instancing mithilfe von Uniform-Buffer-Objekten (Download)<div class="separator" style="clear: both; text-align: center;">
<a href="http://img638.imageshack.us/img638/8312/instancedskeletalanimat.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://img638.imageshack.us/img638/8312/instancedskeletalanimat.jpg" height="240" width="320" /></a></div>
Im heutigen OpenGL-Tutorial befassen wir uns zum wiederholten Male mit der Skelett-Animation (Vertex Skinning) von 3D-Modellen. Im Unterschied zu den früheren Beispielen kommen bei der Animation nun zwei Uniform-Buffer-Objekte zum Einsatz. Im ersten Buffer werden wie gehabt die Transformationsmatrizen der aktuellen Animationspose gespeichert. Der zweite Buffer wird benötigt, um die Orientierungsmatrizen der einzelnen Instanzen zu verwalten.<br />
<div class="MsoNormal">
<br />
<br />
<br />
<br />
<a name='more'></a><br /></div>
<br />
<b>Hinweis:</b><br />
<div class="MsoNormal">
Für die Ausführung dieses Programmbeispiels muss der Treiber Ihrer Grafikkarte die OpenGL Version 3.3 unterstützen. </div>
<div class="MsoNormal">
<br /></div>
<b>Visual C++ 2010: <a href="https://drive.google.com/uc?export=download&id=0B-5xhdD71xAtTF9ZejNhdUxMbTA" target="_blank">DemoWithOpenGL2010_Tut47</a></b><a href="http://dl.dropbox.com/u/6748497/DemoWithOpenGL2010_Tut46.zip" target="_blank"> </a><br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-582120074093677122011-08-01T11:50:00.002+02:002017-03-14T18:44:51.244+01:00OpenGL Tutorial (Version 3.3) – Gemometry Instancing, Handhabung der Objekt-Instanzen (Download)<div class="separator" style="clear: both; text-align: center;">
<a href="http://abload.de/img/geometryinstancingqea4u.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://abload.de/img/geometryinstancingqea4u.jpg" height="240" width="320" /></a></div>
Im heutigen OpenGL-Tutorial dreht sich wieder einmal alles um das Thema Geometry Instancing. Ziel ist die Darstellung einer beliebig großen Anzahl von 3D-Objekten, die sich zur Laufzeit dynamisch initialisieren bzw. zerstören lassen. Für die Handhabung dieser Objekte ist die <span style="color: blue; font-family: "courier new"; font-size: 10pt;">CSimpleObjectInstanceMemoryManager</span>-Klasse verantwortlich, für die Bereitstellung aller für die Darstellung benötigten Texturen und Mesh-Daten die <span style="color: blue; font-family: "courier new"; font-size: 10pt;">CInstancedObjectTextureAndMeshDesc</span>-Klasse.<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br />
<a name='more'></a><br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Initialisierungsarbeiten:</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "courier new"; font-size: 10pt;">// Texturen und Mesh-Daten laden, die im Rahmen des Geometry Instancings<br />
// benötigt werden:<br />
</span><span style="font-family: "courier new"; font-size: 10pt;">InstancedObjectTextureAndMeshDesc = <span style="color: blue;">new</span> CInstancedObjectTextureAndMeshDesc;<br />
InstancedObjectTextureAndMeshDesc->Init_Data(<span style="color: #a31515;">"../Models/Rocks"</span>, 5);<br />
<br />
<span style="color: green;">// Memory Manager für die Verwaltung aller 3D-Objekt-Instanzen<br />
// initialisieren:<br />
</span>SimpleObjectInstanceMemoryManager = <span style="color: blue;">new</span> CSimpleObjectInstanceMemoryManager;<br />
SimpleObjectInstanceMemoryManager->Init(1000); <span style="color: green;">// 1000 Objekte maximal<br />
<br />
</span>[...]<span style="color: green;"><br />
<br />
</span></span><span lang="EN-GB" style="color: green; font-family: "courier new"; font-size: 10pt;">// eine weitere 3D-Objekt-Instanz initialisieren:<br />
</span><span lang="EN-GB" style="font-family: "courier new"; font-size: 10pt;">SimpleObjectInstanceMemoryManager->New_Object(&WorldSpacePosition,<br />
&Orientation, ScaleFactor,<br />
InstanceDescID);</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span lang="EN-GB">Rendering:</span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;">
<span lang="EN-GB" style="font-family: "courier new"; font-size: 10pt;">pMeshInstanceManager->Reset_All_Instances();<br />
<br />
<span style="color: blue;">for</span>(j = 0, i = 0; i < pMemoryManager->NumObjectsMax; i++)<br />
{<br />
j = pMemoryManager->ReadingOrder[i];<br />
<br />
<span style="color: blue;">if</span>(j != pMemoryManager->NoMore_Object)<br />
{<br />
<span style="color: green;">// Gehört das Objekt zur Gruppe der zu rendernden Instanzen?</span><br />
<span style="color: blue;">if</span>(InstanceGroupID != pTextureAndMeshDesc-><br />
InstancedModelPart[pMemoryManager-><br />
ObjectInstance[j].InstanceDescID].<br />
InstanceGroupID)<br />
<span style="color: blue;">continue</span>;<br />
<br />
<span style="color: green;">// Sichtbarkeitstest durchführen:</span><br />
pMemoryManager->ObjectInstance[j].Check_Visibility(pCameraPosition,<br />
pCameraViewDirection, g_ViewDistance);<br />
<br />
<span style="color: blue;">if</span>(pMemoryManager->ObjectInstance[j].visible == <span style="color: blue;">false</span>)<br />
<span style="color: blue;">continue</span>;<br />
<br />
textureSetID = pTextureAndMeshDesc->InstancedModelPart[pMemoryManager-><br />
ObjectInstance[j].InstanceDescID].IDOfUsedTextureSet;<br />
<br />
pMeshInstanceManager->Set_CameraWorldMatrix(pCameraPosition,<br />
&pMemoryManager->ObjectInstance[j].Orientation,<br />
&pMemoryManager->ObjectInstance[j].WorldSpacePosition,<br />
pMemoryManager->ObjectInstance[j].ScaleFactor,<br />
textureSetID);<br />
<br />
NumInstances++;<br />
<br />
<span style="color: blue;">if</span>(NumInstances == NumInstancesMaxPerDrawCall)<br />
{<br />
pMeshInstanceManager->Update_InstanceTransformUniformBuffer();<br />
<br />
<b style="mso-bidi-font-weight: normal;">InstancedModelPart->pMeshVB_IB->Render_Mesh(pShader, LODStep,<br />
pMeshInstanceManager->UsedInstances);<br />
</b><br />
NumInstances = 0;<br />
pMeshInstanceManager->Reset_All_Instances();<br />
}<br />
}<br />
<span style="color: blue;">else</span> <span style="color: blue;">if</span>(j == pMemoryManager->NoMore_Object)<br />
<span style="color: blue;">break</span>;<br />
}<br />
<br />
<span style="color: blue;">if</span>(NumInstances > 0)<br />
{<br />
pMeshInstanceManager->Update_InstanceTransformUniformBuffer();<br />
<br />
<b style="mso-bidi-font-weight: normal;"> InstancedModelPart->pMeshVB_IB->Render_Mesh(pShader, LODStep,<br />
pMeshInstanceManager->UsedInstances);<br />
</b>}</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
<b>Hinweis:</b><br />
<div class="MsoNormal">
Für die Ausführung dieses Programmbeispiels muss der Treiber Ihrer Grafikkarte die OpenGL Version 3.3 unterstützen. </div>
<div class="MsoNormal">
<br /></div>
<b>Visual C++ 2010: <a href="https://drive.google.com/uc?export=download&id=0B-5xhdD71xAtT2k2MHdvZjVkb1U" target="_blank">DemoWithOpenGL2010_Tut46</a></b><a href="http://dl.dropbox.com/u/6748497/DemoWithOpenGL2010_Tut46.zip" target="_blank"> </a><br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.comtag:blogger.com,1999:blog-5159939380865750407.post-33808692988230449902011-07-05T18:16:00.000+02:002011-07-05T18:16:57.595+02:00OpenAL Audio Framework + Tutorial UpdateUnser unter LGPL-Lizenz stehendes <b><a href="http://www.audio-framework.spieleprogrammierung.net/" target="_blank">OpenAL basiertes Audio Framework</a></b> steht ab sofort in der Version 1.4 zum Download bereit. Die zugehörigen Tutorials wurden ebenfalls überarbeitet und verwenden nun unser ebenfalls unter LGPL-Lizenz stehendes <b><a href="http://www.graphics-and-physics-framework.spieleprogrammierung.net/" target="_blank">OpenGL basiertes Grafik und Physik Framework</a></b>.<br />
<br />
<br />
<span style="font-size: large;"><b>OpenAl Audio Framework Demoprogramme: </b></span><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://img706.imageshack.us/img706/8967/audioframework1.jpg" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="240" src="http://img706.imageshack.us/img706/8967/audioframework1.jpg" width="320" /></a></div><b><a href="http://www.audio-framework.spieleprogrammierung.net/2011/07/soundeffekte-und-hintergrundmusik.html" target="_blank">3D-Sound + Streaming Music</a></b><br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://img7.imageshack.us/img7/5636/audioframework2.jpg" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="240" src="http://img7.imageshack.us/img7/5636/audioframework2.jpg" width="320" /></a></div><b><a href="http://www.audio-framework.spieleprogrammierung.net/2011/07/sprachausgabe.html" target="_blank">Streaming Voice Samples</a></b>Alexhttp://www.blogger.com/profile/12911562805026944414noreply@blogger.com