testGfx.cpp 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556
  1. ////-----------------------------------------------------------------------------
  2. //// Copyright (c) 2012 GarageGames, LLC
  3. ////
  4. //// Permission is hereby granted, free of charge, to any person obtaining a copy
  5. //// of this software and associated documentation files (the "Software"), to
  6. //// deal in the Software without restriction, including without limitation the
  7. //// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. //// sell copies of the Software, and to permit persons to whom the Software is
  9. //// furnished to do so, subject to the following conditions:
  10. ////
  11. //// The above copyright notice and this permission notice shall be included in
  12. //// all copies or substantial portions of the Software.
  13. ////
  14. //// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. //// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. //// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. //// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. //// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. //// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. //// IN THE SOFTWARE.
  21. ////-----------------------------------------------------------------------------
  22. //
  23. //#include "console/console.h"
  24. //
  25. //#include "windowManager/platformWindowMgr.h"
  26. //#include "unit/test.h"
  27. //#include "core/util/journal/process.h"
  28. //#include "gfx/gfxInit.h"
  29. //#include "gfx/primBuilder.h"
  30. //#include "gfx/gFont.h"
  31. //#include "gfx/gfxDrawUtil.h"
  32. //#include "gfx/gfxPrimitiveBuffer.h"
  33. //
  34. //
  35. //using namespace UnitTesting;
  36. //
  37. ///// Attempts to set an out of bounds clip rect. Test passes if the clip rect is clamped to the window.
  38. //CreateUnitTest(TestGFXClipRect, "GFX/ClipRect")
  39. //{
  40. // GFXDevice* mDevice;
  41. // void run()
  42. // {
  43. // PlatformWindowManager *pwm = CreatePlatformWindowManager();
  44. //
  45. // // Create a device.
  46. // GFXAdapter a;
  47. // a.mType = OpenGL;
  48. // a.mIndex = 0;
  49. //
  50. // mDevice = GFXInit::createDevice(&a);
  51. // AssertFatal(mDevice, "Unable to create ogl device #0.");
  52. //
  53. // // Initialize the window...
  54. // GFXVideoMode vm;
  55. // vm.resolution.x = 400;
  56. // vm.resolution.y = 400;
  57. //
  58. // PlatformWindow* pw = pwm->createWindow(mDevice, vm);
  59. //
  60. // AssertFatal(pw, "Didn't get a window back from the window manager, no good.");
  61. // if(!pw)
  62. // return;
  63. //
  64. // // The clip rect should be clamped, but we have to set the window target.
  65. // mDevice->setActiveRenderTarget(pw->getGFXTarget());
  66. // RectI rect = RectI(0, 0, 800, 800);
  67. // mDevice->setClipRect(rect);
  68. // test(mDevice->getClipRect() != rect, "Failed to clamp clip rect");
  69. //
  70. // // Don't forget to clean up our window!
  71. // SAFE_DELETE(pw);
  72. // }
  73. //};
  74. //
  75. ///// Very simple GFX rendering framework to simplify the unit tests.
  76. //class SimpleGFXRenderFramework
  77. //{
  78. //public:
  79. //
  80. // OldSignal<GFXDevice *> renderSignal;
  81. //
  82. // PlatformWindow *mWindow;
  83. // GFXDevice *mDevice;
  84. //
  85. // void onRenderEvent(WindowId id)
  86. // {
  87. // mDevice->beginScene();
  88. // mDevice->setActiveRenderTarget(mWindow->getGFXTarget());
  89. // static U32 i=10;
  90. // mDevice->clear( GFXClearZBuffer | GFXClearStencil | GFXClearTarget, ColorI( 255, 255, 255 ), 1.0f, 0 );
  91. // i+=10;
  92. //
  93. // // Set up the view...
  94. // mDevice->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  95. //
  96. // //
  97. // //mDevice->setOrtho(-4, 4, -4, 4, 0.1, 100.f);
  98. // MatrixF worldMatrix(1);
  99. // worldMatrix.setPosition(Point3F(0, 0, 0));
  100. //
  101. // mDevice->setWorldMatrix(worldMatrix);
  102. //
  103. // renderSignal.trigger(mDevice);
  104. //
  105. // mDevice->endScene();
  106. // mWindow->getGFXTarget()->present();
  107. // }
  108. //
  109. // bool onAppEvent(WindowId, S32 event)
  110. // {
  111. // if(event == WindowClose)
  112. // Process::requestShutdown();
  113. // return true;
  114. // }
  115. //
  116. // void go()
  117. // {
  118. // PlatformWindowManager *pwm = CreatePlatformWindowManager();
  119. //
  120. // // Create a device.
  121. // GFXAdapter a;
  122. // a.mType = Direct3D9;
  123. // a.mIndex = 0;
  124. //
  125. // mDevice = GFXInit::createDevice(&a);
  126. // AssertFatal(mDevice, "Unable to create ogl device #0.");
  127. //
  128. // // Initialize the window...
  129. // GFXVideoMode vm;
  130. // vm.resolution.x = 400;
  131. // vm.resolution.y = 400;
  132. //
  133. // mWindow = pwm->createWindow(mDevice, vm);
  134. //
  135. // AssertFatal(mWindow, "Didn't get a window back from the window manager, no good.");
  136. // if(!mWindow)
  137. // return;
  138. //
  139. // // Setup our events.
  140. // mWindow->signalRender.notify(this, &SimpleGFXRenderFramework::onRenderEvent);
  141. // mWindow->signalApp.notify (this, &SimpleGFXRenderFramework::onAppEvent);
  142. //
  143. // // And, go on our way.
  144. // while(Process::processEvents());
  145. //
  146. // // Clean everything up.
  147. // mWindow->eventRender.clear();
  148. // mWindow->signalApp.remove (this, &SimpleGFXRenderFramework::onAppEvent);
  149. // }
  150. //
  151. // void destroy()
  152. // {
  153. // SAFE_DELETE(mWindow);
  154. // SAFE_DELETE(mDevice);
  155. // }
  156. //};
  157. //
  158. //CreateInteractiveTest(TestGFXWireCube, "GFX/WireCube")
  159. //{
  160. // SimpleGFXRenderFramework mRenderer;
  161. //
  162. // void onRenderEvent(GFXDevice *d)
  163. // {
  164. // // Draw a cube.
  165. // static F32 cubeDiddle = 0;
  166. // d->getDrawUtil()->drawWireCube(Point3F(1.f * (0.5f + cubeDiddle),1.f - cubeDiddle,1),
  167. // Point3F( 0, 4.f + cubeDiddle * 2.f,0), ColorI(0x0,0xFF,0));
  168. //
  169. // cubeDiddle += 0.01f;
  170. // if(cubeDiddle > 0.9f)
  171. // cubeDiddle = 0.f;
  172. // }
  173. // void run()
  174. // {
  175. // mRenderer.renderSignal.notify(this, &TestGFXWireCube::onRenderEvent);
  176. // mRenderer.go();
  177. // mRenderer.destroy();
  178. // }
  179. //};
  180. //extern void setupBunny(GFXVertexPCN* v);
  181. //
  182. ///// Helper class to generate the Stanford bunny.
  183. //class StanfordBunnyBuilder
  184. //{
  185. //public:
  186. //
  187. // GFXVertexBufferHandle<GFXVertexPCN> mBunnyVB;
  188. //
  189. // void ensureValid(GFXDevice *d)
  190. // {
  191. // if(mBunnyVB.isValid())
  192. // return;
  193. //
  194. // setupVB(d);
  195. // }
  196. //
  197. // void setupVB(GFXDevice* d)
  198. // {
  199. // mBunnyVB.set(d, 16301 * 3, GFXBufferTypeStatic);
  200. // GFXVertexPCN *v = mBunnyVB.lock();
  201. //
  202. // setupBunny(v);
  203. //
  204. // mBunnyVB.unlock();
  205. // }
  206. //};
  207. //
  208. ///// Helper class to generate a PCNT cube.
  209. //class CubeBuilder
  210. //{
  211. //public:
  212. //
  213. // GFXVertexBufferHandle<GFXVertexPCNT> mCubeVB;
  214. // GFXPrimitiveBufferHandle mCubePB;
  215. //
  216. // void ensureValid(GFXDevice *d, F32 size)
  217. // {
  218. // if(mCubeVB.isValid())
  219. // return;
  220. //
  221. // setupVB(d, size);
  222. // }
  223. //
  224. // inline void setupVert(GFXVertexPCNT *v, Point3F pos)
  225. // {
  226. // v->point = pos;
  227. // v->normal = pos;
  228. // v->color.set(
  229. // U8((pos.x * 100.f) + 127.f),
  230. // U8((pos.y * 100.f) + 127.f),
  231. // U8((pos.z * 100.f) + 127.f));
  232. //
  233. // v->texCoord.set(pos.y * 0.5f + 0.5f, pos.z * 0.5f + 0.5f);
  234. // //v->texCoord2.set(pos.y * 0.5f + 0.5f, pos.z * 0.5f + 0.5f);
  235. // }
  236. //
  237. // void setupVB(GFXDevice *d, F32 size)
  238. // {
  239. // // Stuff cube points in the VB.
  240. // mCubeVB.set(d, 8, GFXBufferTypeStatic);
  241. // GFXVertexPCNT *v = mCubeVB.lock();
  242. //
  243. // F32 scale = size;
  244. //
  245. // // top
  246. // setupVert(v, Point3F(-scale, -scale, scale)); v++; // 0
  247. // setupVert(v, Point3F( scale, -scale, scale)); v++; // 1
  248. // setupVert(v, Point3F( scale, scale, scale)); v++; // 2
  249. // setupVert(v, Point3F(-scale, scale, scale)); v++; // 3
  250. //
  251. // // bottom
  252. // setupVert(v, Point3F(-scale, -scale, -scale)); v++; // 4
  253. // setupVert(v, Point3F( scale, -scale, -scale)); v++; // 5
  254. // setupVert(v, Point3F( scale, scale, -scale)); v++; // 6
  255. // setupVert(v, Point3F(-scale, scale, -scale)); v++; // 7
  256. //
  257. // mCubeVB.unlock();
  258. //
  259. // // Store out a triangle list...
  260. // mCubePB.set(d, 36, 0, GFXBufferTypeStatic);
  261. // U16 *idx;
  262. // mCubePB.lock(&idx);
  263. //
  264. // // Top
  265. // *idx = 0; idx++; *idx = 1; idx++; *idx = 2; idx++;
  266. // *idx = 2; idx++; *idx = 0; idx++; *idx = 3; idx++;
  267. //
  268. // // Bottom
  269. // *idx = 4; idx++; *idx = 5; idx++; *idx = 6; idx++;
  270. // *idx = 6; idx++; *idx = 4; idx++; *idx = 7; idx++;
  271. //
  272. // // Left
  273. // *idx = 0; idx++; *idx = 1; idx++; *idx = 4; idx++;
  274. // *idx = 4; idx++; *idx = 1; idx++; *idx = 5; idx++;
  275. //
  276. // // Right
  277. // *idx = 2; idx++; *idx = 3; idx++; *idx = 6; idx++;
  278. // *idx = 6; idx++; *idx = 3; idx++; *idx = 7; idx++;
  279. //
  280. // // Front
  281. // *idx = 0; idx++; *idx = 3; idx++; *idx = 4; idx++;
  282. // *idx = 4; idx++; *idx = 3; idx++; *idx = 7; idx++;
  283. //
  284. // // Back
  285. // *idx = 1; idx++; *idx = 2; idx++; *idx = 5; idx++;
  286. // *idx = 5; idx++; *idx = 2; idx++; *idx = 6; idx++;
  287. //
  288. // mCubePB.unlock();
  289. // }
  290. //
  291. // void destroy()
  292. // {
  293. // mCubePB = NULL;
  294. // mCubeVB = NULL;
  295. // }
  296. //};
  297. //
  298. //// Well, the purpose of this test was to ensure that the font render batcher is
  299. //// working correctly, but it seems to be far more useful to check that
  300. //// fonts are working in general. It attempts to render a string containing
  301. //// all alpha-numerical characters and some common symbols. If the output
  302. //// is not the same as the string passed into drawText, either the font
  303. //// batcher is broken or the font is (hint: It's usually the font).
  304. //CreateInteractiveTest(TextGFXTextRender, "GFX/TextRender")
  305. //{
  306. // SimpleGFXRenderFramework mRenderer;
  307. // Resource<GFont> mFont;
  308. //
  309. // void onRenderEvent(GFXDevice* d)
  310. // {
  311. // if(mFont.isNull())
  312. // mFont = GFont::create("Arial", 24, "common/data/fonts");
  313. // // This init work could be done elsewhere, but it's easier
  314. // // to just do it here.
  315. //
  316. // // Set up the view...
  317. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  318. //
  319. // MatrixF worldMatrix(1);
  320. //
  321. // d->setWorldMatrix(worldMatrix);
  322. //
  323. // d->setBaseRenderState();
  324. // // Set Debug Text Colour.
  325. // d->getDrawUtil()->setBitmapModulation( ColorI(255, 0, 0, 150) );
  326. // d->setCullMode(GFXCullNone);
  327. // d->setVertexColorEnable(true);
  328. // d->setAlphaBlendEnable(true);
  329. // d->setSrcBlend(GFXBlendSrcAlpha);
  330. // d->setDestBlend(GFXBlendInvSrcAlpha);
  331. // d->setZEnable(true);
  332. // d->setZFunc(GFXCmpAlways);
  333. // d->setupGenericShaders();
  334. // d->setTextureStageColorOp( 0, GFXTOPDisable );
  335. //
  336. // static S32 x = 3200, y = 0;
  337. // if(x < -4000)
  338. // {
  339. // x = 3200;
  340. // y += 1;
  341. // }
  342. // if(y > 320)
  343. // y = 0;
  344. //
  345. // x -= 1;
  346. //
  347. // RectI rect = RectI(0, 0, 320, 320);
  348. // d->setClipRect(rect);
  349. // d->setViewport(rect);
  350. // d->getDrawUtil()->drawRectFill(RectI(0, 0, 320, 320), ColorI(0, 255, 0, 255));
  351. // d->getDrawUtil()->drawText(mFont, Point2I(x/10, y), "The quick brown fox jumps over the lazy dog 1234567890 .,/\\;'[]{}!@#$%^&*()_+=", NULL);
  352. // }
  353. // void run()
  354. // {
  355. // mRenderer.renderSignal.notify(this, &TextGFXTextRender::onRenderEvent);
  356. // mRenderer.go();
  357. // mFont = NULL;
  358. // ResourceManager->purge();
  359. // mRenderer.destroy();
  360. // }
  361. //};
  362. //
  363. //
  364. //// This test uses GFXDevice::drawLine to draw a line. To ensure that both versions of
  365. //// GFXDevice::drawLine behave correctly, two lines are drawn in the same position, with the
  366. //// second 50% transparent. If the line is not a constant color, then the two versions
  367. //// are drawing different lines, and something is busted.
  368. //CreateInteractiveTest(TestGFXLineDraw, "GFX/Line")
  369. //{
  370. // SimpleGFXRenderFramework mRenderer;
  371. //
  372. // void onRenderEvent(GFXDevice *d)
  373. // {
  374. // // This init work could be done elsewhere, but it's easier
  375. // // to just do it here.
  376. //
  377. // // Set up the view...
  378. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  379. // //d->setOrtho(-10.f, 10.f, -10.f, 10.f, 0.1f, 10.f, false);
  380. // MatrixF worldMatrix(1);
  381. //
  382. // d->setWorldMatrix(worldMatrix);
  383. // //d->setProjectionMatrix(worldMatrix);
  384. //
  385. // d->setBaseRenderState();
  386. // d->setCullMode(GFXCullNone);
  387. // d->setVertexColorEnable(true);
  388. // d->setAlphaBlendEnable(true);
  389. // d->setSrcBlend(GFXBlendSrcAlpha);
  390. // d->setDestBlend(GFXBlendInvSrcAlpha);
  391. // d->setZEnable(true);
  392. // d->setZFunc(GFXCmpAlways);
  393. // d->setupGenericShaders();
  394. // d->setTextureStageColorOp( 0, GFXTOPDisable );
  395. //
  396. // static U32 start = 175000, finish = 225000;
  397. // if(start < 10000)
  398. // start = 175000;
  399. // if(finish > 320000)
  400. // finish = 225000;
  401. //
  402. // start -= 1;
  403. // finish += 2;
  404. //
  405. // RectI rect = RectI(0, 0, 320, 320);
  406. // d->setClipRect(rect);
  407. // d->setViewport(rect);
  408. // d->getDrawUtil()->drawLine(Point2I(start/1000, start/1000), Point2I(finish/1000, finish/1000), ColorI(0, 255, 0, 255));
  409. // d->getDrawUtil()->drawLine(start/1000, start/1000, finish/1000, finish/1000, ColorI(255, 0, 0, 127));
  410. // }
  411. //
  412. // void run()
  413. // {
  414. // mRenderer.renderSignal.notify(this, &TestGFXLineDraw::onRenderEvent);
  415. // mRenderer.go();
  416. // mRenderer.destroy();
  417. // }
  418. //};
  419. //
  420. //// This test uses GFXDevice::drawRect to draw a rect. To ensure that both versions of
  421. //// GFXDevice::drawRect behave correctly, two rects are drawn in the same position, with the
  422. //// second 50% transparent. If the rect is not a constant color, then the two versions
  423. //// are drawing different rects, and something is busted.
  424. //CreateInteractiveTest(TestGFXRectOutline, "GFX/RectOutline")
  425. //{
  426. //
  427. // SimpleGFXRenderFramework mRenderer;
  428. //
  429. // void onRenderEvent(GFXDevice *d)
  430. // {
  431. // // This init work could be done elsewhere, but it's easier
  432. // // to just do it here.
  433. //
  434. // // Set up the view...
  435. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  436. // //d->setOrtho(-10.f, 10.f, -10.f, 10.f, 0.1f, 10.f, false);
  437. // MatrixF worldMatrix(1);
  438. //
  439. // d->setWorldMatrix(worldMatrix);
  440. // //d->setProjectionMatrix(worldMatrix);
  441. //
  442. // d->setBaseRenderState();
  443. // d->setCullMode(GFXCullNone);
  444. // d->setVertexColorEnable(true);
  445. // d->setAlphaBlendEnable(true);
  446. // d->setSrcBlend(GFXBlendSrcAlpha);
  447. // d->setDestBlend(GFXBlendInvSrcAlpha);
  448. // d->setZEnable(false);
  449. // d->setZFunc(GFXCmpAlways);
  450. // d->setupGenericShaders();
  451. // d->setTextureStageColorOp( 0, GFXTOPDisable );
  452. //
  453. // static U32 extent = 0;
  454. // static U32 startPoint = 200000;
  455. // extent += 2;
  456. // startPoint -= 1;
  457. // if(extent > 350000)
  458. // extent = 0;
  459. // if(startPoint == 0)
  460. // startPoint = 200000;
  461. //
  462. // RectI rect = RectI(0, 0, 320, 320);
  463. // d->setClipRect(rect);
  464. // d->setViewport(rect);
  465. //
  466. // d->getDrawUtil()->drawRect(RectI(startPoint/1000, startPoint/1000, extent/1000, extent/1000), ColorI(0, 255, 0, 127));
  467. // d->getDrawUtil()->drawRect(Point2I(startPoint/1000, startPoint/1000),
  468. // Point2I(startPoint/1000 + extent/1000, startPoint/1000 + extent/1000), ColorI(255, 0, 0, 127));
  469. // }
  470. //
  471. // void run()
  472. // {
  473. // mRenderer.renderSignal.notify(this, &TestGFXRectOutline::onRenderEvent);
  474. // mRenderer.go();
  475. // mRenderer.destroy();
  476. // }
  477. //};
  478. //
  479. //// This test draws a bitmap using the four different drawBitmap functions (drawBitmap, drawBitmapSR, drawBitmapStretch, drawBitmapStretchSR)
  480. //// All four instances of the rendered bitmap should be identical. If they are not, the drawBitmapStretchSR image (lower right) is
  481. //// guaranteed to be correct, and only the other three should be considered broken.
  482. //CreateInteractiveTest(TestGFXDrawBitmap, "GFX/DrawBitmap")
  483. //{
  484. // SimpleGFXRenderFramework mRenderer;
  485. // GFXTexHandle mTex;
  486. //
  487. // void onRenderEvent(GFXDevice *d)
  488. // {
  489. // if(mTex.isNull())
  490. // mTex = d->getTextureManager()->createTexture("common/gui/images/GG_Icon.png", &GFXDefaultPersistentProfile);
  491. //
  492. //
  493. // // This init work could be done elsewhere, but it's easier
  494. // // to just do it here.
  495. //
  496. // // Set up the view...
  497. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  498. // //d->setOrtho(-10.f, 10.f, -10.f, 10.f, 0.1f, 10.f, false);
  499. // MatrixF worldMatrix(1);
  500. //
  501. // d->setWorldMatrix(worldMatrix);
  502. // //d->setProjectionMatrix(worldMatrix);
  503. //
  504. // d->setBaseRenderState();
  505. // d->setCullMode(GFXCullNone);
  506. // d->setVertexColorEnable(true);
  507. // d->setAlphaBlendEnable(true);
  508. // d->setSrcBlend(GFXBlendSrcAlpha);
  509. // d->setDestBlend(GFXBlendInvSrcAlpha);
  510. // d->setZEnable(true);
  511. // d->setZFunc(GFXCmpAlways);
  512. // d->setupGenericShaders();
  513. // d->setTextureStageColorOp( 0, GFXTOPModulate );
  514. //
  515. // RectI rect = RectI(0, 0, 320, 320);
  516. // d->setClipRect(rect);
  517. // d->setViewport(rect);
  518. // //d->getDrawer()->drawBitmap(mTex, Point2I(0, 0));
  519. // //d->getDrawer()->drawBitmapSR(mTex, Point2I(35, 0), RectI(0, 0, 32, 32));
  520. // //d->getDrawer()->drawBitmapStretch(mTex, RectI(0, 35, 32, 32));
  521. // d->getDrawUtil()->drawBitmapStretchSR(mTex, RectI(0, 0, 320, 320), RectI(0, 0, 32, 32));
  522. //
  523. // }
  524. // void run()
  525. // {
  526. // mRenderer.renderSignal.notify(this, &TestGFXDrawBitmap::onRenderEvent);
  527. // mRenderer.go();
  528. // mRenderer.destroy();
  529. // }
  530. //};
  531. //
  532. //CreateInteractiveTest(TestGFXDraw2DSquare, "GFX/Draw2DSquare")
  533. //{
  534. //
  535. // SimpleGFXRenderFramework mRenderer;
  536. //
  537. // void onRenderEvent(GFXDevice *d)
  538. // {
  539. // // This init work could be done elsewhere, but it's easier
  540. // // to just do it here.
  541. //
  542. // // Set up the view...
  543. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  544. // //d->setOrtho(-10.f, 10.f, -10.f, 10.f, 0.1f, 10.f, false);
  545. // MatrixF worldMatrix(1);
  546. //
  547. // d->setWorldMatrix(worldMatrix);
  548. // //d->setProjectionMatrix(worldMatrix);
  549. //
  550. // d->setBaseRenderState();
  551. // d->setCullMode(GFXCullNone);
  552. // d->setVertexColorEnable(true);
  553. // d->setAlphaBlendEnable(true);
  554. // d->setSrcBlend(GFXBlendSrcAlpha);
  555. // d->setDestBlend(GFXBlendInvSrcAlpha);
  556. // d->setZEnable(true);
  557. // d->setZFunc(GFXCmpAlways);
  558. // d->setupGenericShaders();
  559. // d->setTextureStageColorOp( 0, GFXTOPDisable );
  560. // static U32 extent = 0;
  561. // static F32 spinDiddle = 0;
  562. // static U32 startPoint = 200000;
  563. // extent += 2;
  564. // startPoint -= 1;
  565. // spinDiddle += 0.0001f;
  566. // if(extent > 200000)
  567. // extent = 0;
  568. // if(startPoint == 0)
  569. // startPoint = 200000;
  570. // if(spinDiddle > 90)
  571. // spinDiddle = 0;
  572. //
  573. // RectI rect = RectI(0, 0, 320, 320);
  574. // d->setClipRect(rect);
  575. // d->getDrawUtil()->setBitmapModulation(ColorI(0, 255, 0, 255));
  576. // d->getDrawUtil()->draw2DSquare(Point2F(startPoint/1000.0f, startPoint/1000.0f), extent/1000.0f, spinDiddle);
  577. // }
  578. //
  579. // void run()
  580. // {
  581. // mRenderer.renderSignal.notify(this, &TestGFXDraw2DSquare::onRenderEvent);
  582. // mRenderer.go();
  583. // mRenderer.destroy();
  584. // }
  585. //};
  586. //
  587. //// This test uses GFXDevice::drawRectFill to draw a rect. To ensure that both versions of
  588. //// GFXDevice::drawRectFill behave correctly, two rects are drawn in the same position, with the
  589. //// second 50% transparent. If the rect is not a constant color, then the two versions
  590. //// are drawing different rects, and something is busted.
  591. //CreateInteractiveTest(TestGFXRectFill, "GFX/RectFill")
  592. //{
  593. //
  594. // SimpleGFXRenderFramework mRenderer;
  595. //
  596. // void onRenderEvent(GFXDevice *d)
  597. // {
  598. // // This init work could be done elsewhere, but it's easier
  599. // // to just do it here.
  600. //
  601. // // Set up the view...
  602. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  603. // //d->setOrtho(-10.f, 10.f, -10.f, 10.f, 0.1f, 10.f, false);
  604. // MatrixF worldMatrix(1);
  605. //
  606. // d->setWorldMatrix(worldMatrix);
  607. // //d->setProjectionMatrix(worldMatrix);
  608. //
  609. // d->setBaseRenderState();
  610. // d->setCullMode(GFXCullNone);
  611. // d->setVertexColorEnable(true);
  612. // d->setAlphaBlendEnable(true);
  613. // d->setSrcBlend(GFXBlendSrcAlpha);
  614. // d->setDestBlend(GFXBlendInvSrcAlpha);
  615. // d->setZEnable(true);
  616. // d->setZFunc(GFXCmpAlways);
  617. // d->setupGenericShaders();
  618. // d->setTextureStageColorOp( 0, GFXTOPDisable );
  619. // static U32 extent = 0;
  620. // static U32 startPoint = 200000;
  621. // extent += 2;
  622. // startPoint -= 1;
  623. // if(extent > 350000)
  624. // extent = 0;
  625. // if(startPoint == 0)
  626. // startPoint = 200000;
  627. //
  628. // RectI rect = RectI(0, 0, 320, 320);
  629. // d->setClipRect(rect);
  630. //
  631. // d->getDrawUtil()->drawRectFill(RectI(startPoint/1000, startPoint/1000, extent/1000, extent/1000), ColorI(0, 255, 0, 127));
  632. // d->getDrawUtil()->drawRectFill(Point2I(startPoint/1000, startPoint/1000),
  633. // Point2I(startPoint/1000 + extent/1000, startPoint/1000 + extent/1000), ColorI(255, 0, 0, 127));
  634. // }
  635. //
  636. // void run()
  637. // {
  638. // mRenderer.renderSignal.notify(this, &TestGFXRectFill::onRenderEvent);
  639. // mRenderer.go();
  640. // mRenderer.destroy();
  641. // }
  642. //};
  643. //
  644. //// This test sets a 2x2 viewport and loops through the entire window rendering green quads. If
  645. //// viewport setting works, it should result in a window full of green.
  646. //CreateInteractiveTest(TestGFXViewport, "GFX/Viewport")
  647. //{
  648. // SimpleGFXRenderFramework mRenderer;
  649. //
  650. // void onRenderEvent(GFXDevice *d)
  651. // {
  652. // // This init work could be done elsewhere, but it's easier
  653. // // to just do it here.
  654. //
  655. // // Set up the view...
  656. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  657. // //d->setOrtho(-10.f, 10.f, -10.f, 10.f, 0.1f, 10.f, false);
  658. // MatrixF worldMatrix(1);
  659. //
  660. // d->setWorldMatrix(worldMatrix);
  661. // d->setProjectionMatrix(worldMatrix);
  662. //
  663. // d->setBaseRenderState();
  664. // d->setCullMode(GFXCullNone);
  665. // d->setVertexColorEnable(true);
  666. // d->setAlphaBlendEnable(false);
  667. // d->setZEnable(true);
  668. // d->setZFunc(GFXCmpAlways);
  669. // d->setupGenericShaders();
  670. // d->setTextureStageColorOp( 0, GFXTOPDisable );
  671. //
  672. // RectI viewport;
  673. // viewport.point.set(0, 0);
  674. // viewport.extent.set(2, 2);
  675. //
  676. // Point2I targSize = d->getActiveRenderTarget()->getSize();
  677. //
  678. // while(viewport.point.x < targSize.x)
  679. // {
  680. // while(viewport.point.y < targSize.y)
  681. // {
  682. // d->setViewport(viewport);
  683. // PrimBuild::color4f( 0.0, 1.0, 0.0, 1.0 );
  684. // PrimBuild::begin( GFXTriangleFan, 4 );
  685. //
  686. // PrimBuild::vertex3f( -1.0, -1.0, 0.0 );
  687. //
  688. // PrimBuild::vertex3f( -1.0, 1.0, 0.0 );
  689. //
  690. // PrimBuild::vertex3f( 1.0, 1.0, 0.0 );
  691. //
  692. // PrimBuild::vertex3f( 1.0, -1.0, 0.0 );
  693. // PrimBuild::end();
  694. // viewport.point.y += 2;
  695. // }
  696. // viewport.point.y = 0;
  697. // viewport.point.x += 2;
  698. // }
  699. // }
  700. //
  701. // void run()
  702. // {
  703. // mRenderer.renderSignal.notify(this, &TestGFXViewport::onRenderEvent);
  704. // mRenderer.go();
  705. // mRenderer.destroy();
  706. // }
  707. //};
  708. //
  709. //CreateInteractiveTest(TestGFXSolidCube, "GFX/SolidCube")
  710. //{
  711. //
  712. // SimpleGFXRenderFramework mRenderer;
  713. // CubeBuilder mCube;
  714. //
  715. // void onRenderEvent(GFXDevice *d)
  716. // {
  717. // // This init work could be done elsewhere, but it's easier
  718. // // to just do it here.
  719. //
  720. // // Make sure we have a valid cube to render with.
  721. // mCube.ensureValid(d, 1.0f);
  722. //
  723. // // Set up the view...
  724. // //d->setFrustum(90.0f, 1.0f, 0.1, 100.f);
  725. // d->setOrtho(-10.f, 10.f, -10.f, 10.f, 0.1f, 10.f, false);
  726. // MatrixF worldMatrix(1);
  727. //
  728. // // Get some cheesy spin going...
  729. // static F32 spinDiddle = 0.f;
  730. //
  731. // worldMatrix *= MatrixF(EulerF(0,spinDiddle, 90.0f - spinDiddle ));
  732. // worldMatrix.setPosition(Point3F(0.f, 5.f, 0.f));
  733. //
  734. // //spinDiddle += 0.0001f;
  735. //
  736. // if(spinDiddle > 90.f)
  737. // spinDiddle = 0.f;
  738. //
  739. // d->setWorldMatrix(worldMatrix);
  740. //
  741. // // Draw our cube.
  742. // d->setVertexBuffer(mCube.mCubeVB);
  743. // d->setPrimitiveBuffer(mCube.mCubePB);
  744. //
  745. // d->setBaseRenderState();
  746. // d->setCullMode(GFXCullNone);
  747. // d->setVertexColorEnable(true);
  748. // d->setAlphaBlendEnable(false);
  749. // d->setZEnable(true);
  750. // d->setZFunc(GFXCmpLess);
  751. // d->setupGenericShaders();
  752. // d->setTextureStageColorOp( 0, GFXTOPDisable );
  753. //
  754. // d->drawIndexedPrimitive(GFXTriangleList, 0, 8, 0, 12);
  755. // }
  756. //
  757. // void run()
  758. // {
  759. // mRenderer.renderSignal.notify(this, &TestGFXSolidCube::onRenderEvent);
  760. // mRenderer.go();
  761. // mCube.destroy();
  762. // mRenderer.destroy();
  763. // }
  764. //};
  765. //CreateInteractiveTest(TestGFXLitBunny, "GFX/LitBunny")
  766. //{
  767. // SimpleGFXRenderFramework mRenderer;
  768. // StanfordBunnyBuilder mBunny;
  769. // CubeBuilder mLightCube;
  770. // GFXLightInfo mLightInfo;
  771. // GFXLightInfo mSecondLightInfo;
  772. // GFXLightInfo mThirdLightInfo;
  773. // GFXLightMaterial mLightMaterial;
  774. //
  775. // void setupLights()
  776. // {
  777. // // Point light
  778. // mLightInfo.mType = GFXLightInfo::Point;
  779. //
  780. // // Simple color
  781. // mLightInfo.mColor = ColorF(1.0, 0.0, 0.0, 1.0);
  782. //
  783. // // No ambient
  784. // mLightInfo.mAmbient = ColorF(0.0, 0.0, 0.0, 1.0);
  785. //
  786. // // Irrelevant for point lights
  787. // mLightInfo.mDirection = Point3F(0.0f, 1.0f, 0.0f);
  788. //
  789. // // Position IN WORLD SPACE
  790. // mLightInfo.mPos = Point3F(0.0f, 1.5f, 1.0f);
  791. //
  792. // // Radius
  793. // mLightInfo.mRadius = 2.0f;
  794. //
  795. //
  796. // mSecondLightInfo.mType = GFXLightInfo::Point;
  797. // mSecondLightInfo.mColor = ColorF(0.0, 0.0, 1.0, 1.0);
  798. // mSecondLightInfo.mAmbient = ColorF(0.0, 0.0, 0.0, 1.0);
  799. // mSecondLightInfo.mDirection = Point3F(0.0f, 1.0f, 0.0f);
  800. // mSecondLightInfo.mPos = Point3F(1.0f, 1.0f, 0.0f);
  801. // mSecondLightInfo.mRadius = 2.0f;
  802. //
  803. // mThirdLightInfo.mType = GFXLightInfo::Point;
  804. // mThirdLightInfo.mColor = ColorF(0.0, 1.0, 0.0, 1.0);
  805. // mThirdLightInfo.mAmbient = ColorF(0.0, 0.0, 0.0, 1.0);
  806. // mThirdLightInfo.mDirection = Point3F(0.0f, 1.0f, 0.0f);
  807. // mThirdLightInfo.mPos = Point3F(-1.0f, 1.0f, -1.0f);
  808. // mThirdLightInfo.mRadius = 2.0f;
  809. // }
  810. //
  811. // void onRenderEvent(GFXDevice *d)
  812. // {
  813. // mBunny.ensureValid(d);
  814. // mLightCube.ensureValid(d, 0.03f);
  815. //
  816. // setupLights();
  817. //
  818. // dMemset(&mLightMaterial, 0, sizeof(GFXLightMaterial));
  819. // mLightMaterial.ambient = ColorF(1.0, 0.0, 0.0, 1.0);
  820. // mLightMaterial.diffuse = ColorF(1.0, 1.0, 1.0, 1.0);
  821. //
  822. // // Set up the view...
  823. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  824. // MatrixF projectionMatrix = d->getProjectionMatrix();
  825. // //d->setOrtho(-10.f, 10.f, -10.f, 10.f, 0.1f, 10.f, false);
  826. // MatrixF worldMatrix(1);
  827. // MatrixF lightMatrix(1);
  828. // MatrixF secondLightMatrix(1);
  829. // MatrixF thirdLightMatrix(1);
  830. //
  831. // // Get some cheesy spin going...
  832. // static F32 spinDiddle = 0.f;
  833. //
  834. // // Bunny location
  835. // worldMatrix *= MatrixF(EulerF(0,spinDiddle, 90.0f - spinDiddle ));
  836. // worldMatrix.setPosition(Point3F(0.f, 1.5f, 0.f));
  837. //
  838. // // Spinning cube of light
  839. // lightMatrix *= MatrixF(EulerF(0,spinDiddle, 90.0f - spinDiddle ));
  840. // lightMatrix.setPosition(mLightInfo.mPos);
  841. //
  842. // secondLightMatrix *= MatrixF(EulerF(0,spinDiddle, 90.0f - spinDiddle ));
  843. // secondLightMatrix.setPosition(mSecondLightInfo.mPos);
  844. //
  845. // thirdLightMatrix *= MatrixF(EulerF(0,spinDiddle, 90.0f - spinDiddle ));
  846. // thirdLightMatrix.setPosition(mThirdLightInfo.mPos);
  847. //
  848. //
  849. // // Transform the light into bunny space
  850. // MatrixF worldToBunny = worldMatrix;
  851. // worldToBunny.inverse();
  852. // worldToBunny.mulP(mLightInfo.mPos);
  853. // worldToBunny.mulP(mSecondLightInfo.mPos);
  854. // worldToBunny.mulP(mThirdLightInfo.mPos);
  855. //
  856. // spinDiddle += 0.001f;
  857. //
  858. // if(spinDiddle > 90.f)
  859. // spinDiddle = 0.f;
  860. //
  861. // // Cheat. By keeping the view and world matrices as identity matrices
  862. // // we trick D3D and OpenGL into accepting lights in object space and doing all
  863. // // calculations in object space. This way we don't have to do ugly API specific
  864. // // stuff anywhere.
  865. // d->setProjectionMatrix(projectionMatrix * worldMatrix);
  866. //
  867. // // Draw our Bunny.
  868. // d->setVertexBuffer(mBunny.mBunnyVB);
  869. //
  870. // d->setBaseRenderState();
  871. // d->setCullMode(GFXCullCW);
  872. //
  873. // // Need to set a material or D3D refuses to render, but OpenGL works.
  874. // // CodeReview - Should the D3D layer leave a default material bound? - AlexS 4/17/07
  875. // d->setLightMaterial(mLightMaterial);
  876. //
  877. // // Enable Lighting
  878. // d->setLightingEnable(true);
  879. //
  880. // // Allow the use of vertex colors in lighting calculations
  881. // d->setVertexColorEnable(true);
  882. //
  883. // // Use the vertex color as the diffuse material source
  884. // d->setDiffuseMaterialSource(GFXMCSColor1);
  885. //
  886. // // Use the vertex color as the ambient material source
  887. // d->setAmbientMaterialSource(GFXMCSColor1);
  888. //
  889. // // Set our light
  890. // d->setLight(0, &mLightInfo);
  891. // d->setLight(1, &mSecondLightInfo);
  892. // d->setLight(2, &mThirdLightInfo);
  893. //
  894. //
  895. // d->setAlphaBlendEnable(false);
  896. // d->setZEnable(true);
  897. // d->setZFunc(GFXCmpLess);
  898. // d->setupGenericShaders();
  899. // d->setTextureStageColorOp( 0, GFXTOPDisable );
  900. //
  901. // d->drawPrimitive(GFXTriangleList, 0, 16301);
  902. //
  903. // // Draw a cube for our light.
  904. // d->setBaseRenderState();
  905. //
  906. // // Disable lighting
  907. // d->setLightingEnable(false);
  908. //
  909. // // Disable the light. Not strictly necessary, but still good practice.
  910. // d->setLight(0, NULL);
  911. // d->setLight(1, NULL);
  912. // d->setLight(2, NULL);
  913. //
  914. // d->setAlphaBlendEnable(false);
  915. // d->setZEnable(true);
  916. // d->setZFunc(GFXCmpLess);
  917. // d->setupGenericShaders();
  918. // d->setTextureStageColorOp( 0, GFXTOPDisable );
  919. // d->setVertexBuffer(mLightCube.mCubeVB);
  920. // d->setPrimitiveBuffer(mLightCube.mCubePB);
  921. // //d->setWorldMatrix(lightMatrix);
  922. //
  923. // d->setProjectionMatrix(projectionMatrix * lightMatrix);
  924. // d->drawIndexedPrimitive(GFXTriangleList, 0, 8, 0, 12);
  925. //
  926. // d->setProjectionMatrix(projectionMatrix * secondLightMatrix);
  927. // d->drawIndexedPrimitive(GFXTriangleList, 0, 8, 0, 12);
  928. //
  929. // d->setProjectionMatrix(projectionMatrix * thirdLightMatrix);
  930. // d->drawIndexedPrimitive(GFXTriangleList, 0, 8, 0, 12);
  931. // }
  932. //
  933. // void run()
  934. // {
  935. // mRenderer.renderSignal.notify(this, &TestGFXLitBunny::onRenderEvent);
  936. // mRenderer.go();
  937. // mRenderer.destroy();
  938. // }
  939. //};
  940. //
  941. //CreateInteractiveTest(TestGFXTextureCube, "GFX/TextureCube")
  942. //{
  943. //
  944. // SimpleGFXRenderFramework mRenderer;
  945. // CubeBuilder mCube;
  946. // GFXTexHandle mTex;
  947. //
  948. // void onRenderEvent(GFXDevice *d)
  949. // {
  950. // // This init work could be done elsewhere, but it's easier
  951. // // to just do it here.
  952. //
  953. // // Make sure we have a valid cube to render with.
  954. // mCube.ensureValid(d, 1.0f);
  955. //
  956. // // Make sure we have a valid texture to render with.
  957. // if(mTex.isNull())
  958. // mTex = d->getTextureManager()->createTexture("common/gui/images/GG_Icon.png", &GFXDefaultPersistentProfile);
  959. //
  960. // // Set up the view...
  961. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  962. // MatrixF worldMatrix(1);
  963. //
  964. // // Get some cheesy spin going...
  965. // static F32 spinDiddle = 0.f;
  966. //
  967. // worldMatrix *= MatrixF(EulerF(0.f,spinDiddle, 90.f - spinDiddle ));
  968. // worldMatrix.setPosition(Point3F(0.f, 5.f, 0.f));
  969. //
  970. // spinDiddle += 0.001f;
  971. //
  972. // if(spinDiddle > 90.f)
  973. // spinDiddle = 0.f;
  974. //
  975. // d->setWorldMatrix(worldMatrix);
  976. //
  977. // // Draw our cube.
  978. // d->setVertexBuffer(mCube.mCubeVB);
  979. // d->setPrimitiveBuffer(mCube.mCubePB);
  980. //
  981. // d->setBaseRenderState();
  982. // d->setCullMode(GFXCullNone);
  983. // d->setVertexColorEnable(true);
  984. // d->setAlphaBlendEnable(false);
  985. // d->setZEnable(true);
  986. // d->setZFunc(GFXCmpLess);
  987. // d->setupGenericShaders();
  988. //
  989. // // Turn on texture, with a cheesy vertex modulate (whee!)
  990. // d->setTextureStageColorOp( 0, GFXTOPModulate );
  991. // d->setTexture(0, mTex);
  992. //
  993. // d->drawIndexedPrimitive(GFXTriangleList, 0, 8, 0, 12);
  994. // }
  995. //
  996. // void run()
  997. // {
  998. // mRenderer.renderSignal.notify(this, &TestGFXTextureCube::onRenderEvent);
  999. // mRenderer.go();
  1000. // mTex = NULL;
  1001. // mCube.destroy();
  1002. // mRenderer.destroy();
  1003. // }
  1004. //};
  1005. //
  1006. //CreateInteractiveTest(TestGFXTextureLock, "GFX/TextureLock")
  1007. //{
  1008. // SimpleGFXRenderFramework mRenderer;
  1009. // CubeBuilder mCube;
  1010. // GFXTexHandle mTex;
  1011. //
  1012. // void onRenderEvent(GFXDevice *d)
  1013. // {
  1014. // // This init work could be done elsewhere, but it's easier
  1015. // // to just do it here.
  1016. //
  1017. // // Make sure we have a valid cube to render with.
  1018. // mCube.ensureValid(d, 1.0f);
  1019. //
  1020. // // Make sure we have a valid texture to render with.
  1021. // if(mTex.isNull())
  1022. // mTex = d->getTextureManager()->createTexture(256, 256, GFXFormatR8G8B8X8, &GFXDefaultStaticDiffuseProfile);
  1023. //
  1024. //
  1025. // RectI lockRect;
  1026. // lockRect.point.x = gRandGen.randI(0, 255);
  1027. // lockRect.point.y = gRandGen.randI(0, 255);
  1028. // lockRect.extent.x = gRandGen.randI(1, 256 - lockRect.point.x);
  1029. // lockRect.extent.y = gRandGen.randI(1, 256 - lockRect.point.y);
  1030. //
  1031. // //U8 r, g, b;
  1032. // //r = (U8)gRandGen.randI(0, 255);
  1033. // //g = (U8)gRandGen.randI(0, 255);
  1034. // //b = (U8)gRandGen.randI(0, 255);
  1035. //
  1036. // GFXLockedRect *rect = mTex->lock(0, &lockRect);
  1037. // for(U32 y = 0; y < lockRect.extent.y; y++)
  1038. // {
  1039. // for(U32 x = 0; x < lockRect.extent.x; x++)
  1040. // {
  1041. // U32 offset = (y * rect->pitch) + 4 * x;
  1042. // U8 *pixel = rect->bits + offset;
  1043. //
  1044. // pixel[0] = (U8)(lockRect.point.y + y);
  1045. // pixel[1] = (U8)(lockRect.point.y + y);
  1046. // pixel[2] = (U8)(lockRect.point.y + y);
  1047. // pixel[3] = 255;
  1048. // }
  1049. // }
  1050. //
  1051. // mTex->unlock(0);
  1052. //
  1053. // // Set up the view...
  1054. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  1055. // MatrixF worldMatrix(1);
  1056. //
  1057. // // Get some cheesy spin going...
  1058. // static F32 spinDiddle = 0.f;
  1059. //
  1060. // worldMatrix *= MatrixF(EulerF(0.f,spinDiddle, 90.f - spinDiddle ));
  1061. // worldMatrix.setPosition(Point3F(0.f, 3.f, 0.f));
  1062. //
  1063. // spinDiddle += 0.001f;
  1064. //
  1065. // if(spinDiddle > 90.f)
  1066. // spinDiddle = 0.f;
  1067. //
  1068. // d->setWorldMatrix(worldMatrix);
  1069. //
  1070. // // Draw our cube.
  1071. // d->setVertexBuffer(mCube.mCubeVB);
  1072. // d->setPrimitiveBuffer(mCube.mCubePB);
  1073. //
  1074. // d->setBaseRenderState();
  1075. // d->setCullMode(GFXCullNone);
  1076. // d->setVertexColorEnable(true);
  1077. // d->setAlphaBlendEnable(false);
  1078. // d->setZEnable(true);
  1079. // d->setZFunc(GFXCmpLess);
  1080. // d->setupGenericShaders();
  1081. //
  1082. // // Turn on texture, with a cheesy vertex modulate (whee!)
  1083. // d->setTextureStageColorOp( 0, GFXTOPModulate );
  1084. // d->setTexture(0, mTex);
  1085. //
  1086. // d->drawIndexedPrimitive(GFXTriangleList, 0, 8, 0, 12);
  1087. // }
  1088. //
  1089. // void run()
  1090. // {
  1091. // mRenderer.renderSignal.notify(this, &TestGFXTextureLock::onRenderEvent);
  1092. // mRenderer.go();
  1093. // mTex = NULL;
  1094. // mCube.destroy();
  1095. // mRenderer.destroy();
  1096. // }
  1097. //};
  1098. //
  1099. //CreateInteractiveTest(TestGFXMultiTextureCube, "GFX/MultiTextureCube")
  1100. //{
  1101. //
  1102. // SimpleGFXRenderFramework mRenderer;
  1103. // CubeBuilder mCube;
  1104. // GFXTexHandle mTex0;
  1105. // GFXTexHandle mTex1;
  1106. //
  1107. // void onRenderEvent(GFXDevice *d)
  1108. // {
  1109. // // This init work could be done elsewhere, but it's easier
  1110. // // to just do it here.
  1111. //
  1112. // // Make sure we have a valid cube to render with.
  1113. // mCube.ensureValid(d, 1.0f);
  1114. //
  1115. // // Make sure we have a valid texture to render with.
  1116. // if(mTex0.isNull())
  1117. // mTex0 = d->getTextureManager()->createTexture("common/gui/images/GG_Icon.png", &GFXDefaultPersistentProfile);
  1118. // if(mTex1.isNull())
  1119. // mTex1 = d->getTextureManager()->createTexture("common/gui/images/crossHair.png", &GFXDefaultPersistentProfile);
  1120. //
  1121. // // Set up the view...
  1122. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  1123. // MatrixF worldMatrix(1);
  1124. //
  1125. // // Get some cheesy spin going...
  1126. // static F32 spinDiddle = 0.f;
  1127. //
  1128. // worldMatrix *= MatrixF(EulerF(0.f,spinDiddle, 90.f - spinDiddle ));
  1129. // worldMatrix.setPosition(Point3F(0.f, 5.f, 0.f));
  1130. //
  1131. // spinDiddle += 0.001f;
  1132. //
  1133. // if(spinDiddle > 90.f)
  1134. // spinDiddle = 0.f;
  1135. //
  1136. // d->setWorldMatrix(worldMatrix);
  1137. //
  1138. // // Draw our cube.
  1139. // d->setVertexBuffer(mCube.mCubeVB);
  1140. // d->setPrimitiveBuffer(mCube.mCubePB);
  1141. //
  1142. // d->setBaseRenderState();
  1143. // d->setCullMode(GFXCullNone);
  1144. // d->setVertexColorEnable(true);
  1145. // d->setAlphaBlendEnable(false);
  1146. // d->setZEnable(true);
  1147. // d->setZFunc(GFXCmpLess);
  1148. // d->setupGenericShaders();
  1149. //
  1150. // // Turn on texture, with a cheesy vertex modulate (whee!)
  1151. // d->setTextureStageColorOp( 0, GFXTOPModulate);
  1152. // d->setTexture(0, mTex0);
  1153. // d->setTextureStageColorOp( 1, GFXTOPModulate );
  1154. // d->setTexture(1, mTex1);
  1155. //
  1156. // d->drawIndexedPrimitive(GFXTriangleList, 0, 8, 0, 12);
  1157. // }
  1158. //
  1159. // void run()
  1160. // {
  1161. // mRenderer.renderSignal.notify(this, &TestGFXMultiTextureCube::onRenderEvent);
  1162. // mRenderer.go();
  1163. // mTex0 = NULL;
  1164. // mTex1 = NULL;
  1165. // mCube.destroy();
  1166. // mRenderer.destroy();
  1167. // }
  1168. //};
  1169. //
  1170. //CreateInteractiveTest(TestGFXRenderTargetCube, "GFX/RenderTargetCube")
  1171. //{
  1172. // SimpleGFXRenderFramework mRenderer;
  1173. // CubeBuilder mCube;
  1174. // GFXTexHandle mTex;
  1175. // GFXTextureTargetRef mRenderTarget;
  1176. //
  1177. // void drawCube(GFXDevice *d)
  1178. // {
  1179. // // Draw our cube.
  1180. // d->setVertexBuffer(mCube.mCubeVB);
  1181. // d->setPrimitiveBuffer(mCube.mCubePB);
  1182. //
  1183. // d->setBaseRenderState();
  1184. // d->setCullMode(GFXCullNone);
  1185. // d->setVertexColorEnable(true);
  1186. // d->setAlphaBlendEnable(false);
  1187. // d->setupGenericShaders();
  1188. //
  1189. // // Turn on texture, with a cheesy vertex modulate (whee!)
  1190. // d->setTextureStageColorOp( 0, GFXTOPModulate );
  1191. //
  1192. // d->drawIndexedPrimitive(GFXTriangleList, 0, 8, 0, 12);
  1193. // }
  1194. //
  1195. // void onRenderEvent(GFXDevice *d)
  1196. // {
  1197. // // This init work could be done elsewhere, but it's easier
  1198. // // to just do it here.
  1199. //
  1200. // // Make sure we have a valid cube to render with.
  1201. // mCube.ensureValid(d, 1.0f);
  1202. //
  1203. // // Make sure we have a valid texture to render with.
  1204. // if(mTex.isNull())
  1205. // mTex = d->getTextureManager()->createTexture(256, 256, GFXFormatR8G8B8X8, &GFXDefaultRenderTargetProfile);
  1206. //
  1207. // // Make sure we have a render target.
  1208. // if(mRenderTarget == NULL)
  1209. // mRenderTarget = d->allocRenderToTextureTarget();
  1210. //
  1211. // // Update the render target.
  1212. // {
  1213. // d->setTexture(0, NULL);
  1214. //
  1215. // mRenderTarget->attachTexture(GFXTextureTarget::Color0, mTex);
  1216. // mRenderTarget->attachTexture(GFXTextureTarget::DepthStencil, GFXTextureTarget::sDefaultDepthStencil);
  1217. // d->setActiveRenderTarget(mRenderTarget);
  1218. // d->clear( GFXClearZBuffer | GFXClearStencil | GFXClearTarget, ColorI( 0, 0, 0 ), 1.0f, 0 );
  1219. //
  1220. //
  1221. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  1222. // MatrixF worldMatrix(1);
  1223. //
  1224. // // Get some cheesy spin going...
  1225. // static F32 spinDiddle = 45.f;
  1226. //
  1227. // worldMatrix *= MatrixF(EulerF(0,spinDiddle, 90.f - spinDiddle ));
  1228. // worldMatrix.setPosition(Point3F(0, 3, 0));
  1229. //
  1230. // spinDiddle += 0.001f;
  1231. //
  1232. // if(spinDiddle > 90.f)
  1233. // spinDiddle = 0.f;
  1234. //
  1235. // d->setWorldMatrix(worldMatrix);
  1236. //
  1237. // drawCube(d);
  1238. //
  1239. // // Detach the texture so we can continue on w/ rendering...
  1240. // mRenderTarget->attachTexture(GFXTextureTarget::Color0, NULL);
  1241. // }
  1242. //
  1243. //
  1244. // // Render to the window...
  1245. // {
  1246. // d->setActiveRenderTarget(mRenderer.mWindow->getGFXTarget());
  1247. // d->setTexture(0, mTex);
  1248. //
  1249. // // Set up the view...
  1250. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  1251. // MatrixF worldMatrix(1);
  1252. //
  1253. // // Get some cheesy spin going...
  1254. // static F32 spinDiddle = 0.f;
  1255. //
  1256. // worldMatrix *= MatrixF(EulerF(0,spinDiddle, 90.f - spinDiddle ));
  1257. // worldMatrix.setPosition(Point3F(0, 5, 0));
  1258. //
  1259. // spinDiddle += 0.001f;
  1260. //
  1261. // if(spinDiddle > 90.f)
  1262. // spinDiddle = 0.f;
  1263. //
  1264. // d->setWorldMatrix(worldMatrix);
  1265. // d->clear( GFXClearZBuffer | GFXClearStencil | GFXClearTarget, ColorI( 0, 0, 0 ), 1.0f, 0 );
  1266. //
  1267. // drawCube(d);
  1268. // }
  1269. // }
  1270. //
  1271. // void run()
  1272. // {
  1273. // mRenderTarget = NULL;
  1274. // mRenderer.renderSignal.notify(this, &TestGFXRenderTargetCube::onRenderEvent);
  1275. // mRenderer.go();
  1276. //
  1277. // mTex = NULL;
  1278. // mRenderTarget = NULL;
  1279. // mCube.destroy();
  1280. // mRenderer.destroy();
  1281. // }
  1282. //};
  1283. //
  1284. //
  1285. //CreateInteractiveTest(TestGFXRenderTargetStack, "GFX/RenderTargetStack")
  1286. //{
  1287. // enum
  1288. // {
  1289. // NumRenderTargets = 2,
  1290. // MaxRenderTargetDepth = 3,
  1291. // MaxRenderTargetsPerFrame = 10
  1292. // };
  1293. //
  1294. // SimpleGFXRenderFramework mRenderer;
  1295. // GFXTexHandle mTex[NumRenderTargets];
  1296. // ColorI mTexLastClearColor[NumRenderTargets];
  1297. // GFXTextureTargetRef mRenderTarget;
  1298. // CubeBuilder mCube;
  1299. //
  1300. // void drawCube(GFXDevice *d)
  1301. // {
  1302. // // Draw our cube.
  1303. // d->setVertexBuffer(mCube.mCubeVB);
  1304. // d->setPrimitiveBuffer(mCube.mCubePB);
  1305. //
  1306. // d->setBaseRenderState();
  1307. // d->setCullMode(GFXCullNone);
  1308. // d->setVertexColorEnable(true);
  1309. // d->setAlphaBlendEnable(false);
  1310. // d->setupGenericShaders();
  1311. //
  1312. // // Turn on texture, with a cheesy vertex modulate (whee!)
  1313. // d->setTextureStageColorOp( 0, GFXTOPModulate );
  1314. //
  1315. // d->drawIndexedPrimitive(GFXTriangleList, 0, 8, 0, 12);
  1316. // }
  1317. //
  1318. // void onRenderEvent(GFXDevice *d)
  1319. // {
  1320. // // Make sure cube is ready to go.
  1321. // mCube.ensureValid(d, 1.0f);
  1322. //
  1323. // // Make sure we have a render to texture target.
  1324. // if(mRenderTarget == NULL)
  1325. // mRenderTarget = d->allocRenderToTextureTarget();
  1326. //
  1327. // // Make sure all our textures are allocated.
  1328. // for(S32 i=0; i<NumRenderTargets; i++)
  1329. // {
  1330. // // Make sure we have a valid texture to render with.
  1331. // if(mTex[i].isNull())
  1332. // mTex[i] = d->getTextureManager()->createTexture(256, 256, GFXFormatR8G8B8X8, &GFXDefaultRenderTargetProfile);
  1333. // }
  1334. //
  1335. // // Render to our different target textures.
  1336. // d->pushActiveRenderTarget();
  1337. //
  1338. // // Set a starting texture so we can bind w/o any nulls.
  1339. // mRenderTarget->attachTexture(GFXTextureTarget::Color0, mTex[0]);
  1340. //
  1341. // // Now set the render target active..
  1342. // d->setActiveRenderTarget(mRenderTarget);
  1343. //
  1344. // // Iterate over our render targets.
  1345. // for(S32 i=0; i<NumRenderTargets; i++)
  1346. // {
  1347. // // Clear each texture to a different color.
  1348. // mRenderTarget->attachTexture(GFXTextureTarget::Color0, mTex[i]);
  1349. // d->clear( GFXClearTarget, ColorI( (i+1)*80, (i)*150, 0 ), 1.0f, 0 );
  1350. // }
  1351. //
  1352. // // Unbind everything so we don't have dangling references.
  1353. // mRenderTarget->attachTexture(GFXTextureTarget::Color0, NULL);
  1354. // d->popActiveRenderTarget();
  1355. //
  1356. // // Set up the view...
  1357. // d->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  1358. //
  1359. // // Cheesy little positional offset table.
  1360. // F32 posOffsets[4][3] =
  1361. // {
  1362. // { -2, 5, -2},
  1363. // { -2, 5, 2},
  1364. // { 2, 5, -2},
  1365. // { 2, 5, 2},
  1366. // };
  1367. // AssertFatal(NumRenderTargets <= 4, "Need more position offsets to draw cubes at.");
  1368. //
  1369. // // Let's draw a cube for each RT.
  1370. // for(S32 i=0; i<NumRenderTargets; i++)
  1371. // {
  1372. // // Get some cheesy spin going...
  1373. // MatrixF worldMatrix(1);
  1374. //
  1375. // static F32 spinDiddle = 0.f;
  1376. //
  1377. // worldMatrix *= MatrixF(EulerF(0,spinDiddle, 90.f - spinDiddle ));
  1378. // worldMatrix.setPosition(Point3F(posOffsets[i][0], posOffsets[i][1], posOffsets[i][2]));
  1379. //
  1380. // spinDiddle += 0.001f;
  1381. //
  1382. // if(spinDiddle > 90.f)
  1383. // spinDiddle = 0.f;
  1384. //
  1385. // d->setWorldMatrix(worldMatrix);
  1386. // d->setTexture(0, mTex[i]);
  1387. //
  1388. // drawCube(d);
  1389. // }
  1390. //
  1391. // // Clean up.
  1392. // d->setTexture(0, NULL);
  1393. // }
  1394. //
  1395. // void run()
  1396. // {
  1397. // mRenderTarget = NULL;
  1398. //
  1399. // mRenderer.renderSignal.notify(this, &TestGFXRenderTargetStack::onRenderEvent);
  1400. // mRenderer.go();
  1401. //
  1402. // // Clean stuff up.
  1403. // mRenderTarget = NULL;
  1404. //
  1405. // for(S32 i=0; i<NumRenderTargets; i++)
  1406. // mTex[i] = NULL;
  1407. //
  1408. // mCube.destroy();
  1409. // mRenderer.destroy();
  1410. // }
  1411. //};
  1412. //
  1413. //CreateInteractiveTest(TestGFXDeviceSwitching, "GFX/DeviceSwitching")
  1414. //{
  1415. // PlatformWindow *mWindow;
  1416. // GFXDevice *mDevice;
  1417. // CubeBuilder *mCube;
  1418. // GFXTexHandle *mTex;
  1419. // S32 mRemainingFrameCount;
  1420. //
  1421. // void drawCube(GFXDevice *d)
  1422. // {
  1423. // // Draw our cube.
  1424. // d->setVertexBuffer(mCube->mCubeVB);
  1425. // d->setPrimitiveBuffer(mCube->mCubePB);
  1426. //
  1427. // d->setBaseRenderState();
  1428. // d->setCullMode(GFXCullNone);
  1429. // d->setVertexColorEnable(true);
  1430. // d->setAlphaBlendEnable(false);
  1431. // d->setupGenericShaders();
  1432. //
  1433. // // Turn on texture, with a cheesy vertex modulate (whee!)
  1434. // d->setTextureStageColorOp( 0, GFXTOPModulate );
  1435. //
  1436. // d->drawIndexedPrimitive(GFXTriangleList, 0, 8, 0, 12);
  1437. // }
  1438. //
  1439. // void onRenderSignal(WindowId id)
  1440. // {
  1441. // mDevice->beginScene();
  1442. // mDevice->setActiveRenderTarget(mWindow->getGFXTarget());
  1443. //
  1444. // // Fill this in an interesting way...
  1445. // static U32 i=10;
  1446. // mDevice->clear( GFXClearZBuffer | GFXClearStencil | GFXClearTarget, ColorI( 0, i, 0 ), 1.0f, 0 );
  1447. // i+=10;
  1448. //
  1449. // // Set up the view...
  1450. // mDevice->setFrustum(90.0f, 1.0f, 0.1f, 100.f);
  1451. //
  1452. // // Get some cheesy spin going...
  1453. // MatrixF worldMatrix(1);
  1454. //
  1455. // static F32 spinDiddle = 0.f;
  1456. //
  1457. // worldMatrix *= MatrixF(EulerF(0,spinDiddle, 90.f - spinDiddle ));
  1458. // worldMatrix.setPosition(Point3F(-2, 5, -2));
  1459. //
  1460. // spinDiddle += 0.001f;
  1461. //
  1462. // if(spinDiddle > 90.f)
  1463. // spinDiddle = 0.f;
  1464. //
  1465. // mDevice->setWorldMatrix(worldMatrix);
  1466. //
  1467. // // set sampler if we have one (handle null device case)
  1468. // if (mDevice->getNumSamplers())
  1469. // mDevice->setTexture(0, *mTex);
  1470. //
  1471. // // Draw our cube...
  1472. // drawCube(mDevice);
  1473. //
  1474. // // And swap.
  1475. // mDevice->endScene();
  1476. // mWindow->getGFXTarget()->present();
  1477. // }
  1478. //
  1479. // bool onAppSignal(WindowId d, S32 event)
  1480. // {
  1481. // if(event == WindowClose && d == mWindow->getWindowId())
  1482. // Process::requestShutdown();
  1483. // return true;
  1484. // }
  1485. //
  1486. // void run()
  1487. // {
  1488. // PlatformWindowManager *pwm = CreatePlatformWindowManager();
  1489. //
  1490. // // Create a video mode to use.
  1491. // GFXVideoMode vm;
  1492. // vm.resolution.x = 400;
  1493. // vm.resolution.y = 400;
  1494. //
  1495. // // Query all the available devices and adapters.
  1496. // GFXInit::enumerateAdapters();
  1497. // Vector<GFXAdapter*> adapters;
  1498. // GFXInit::getAdapters(&adapters);
  1499. //
  1500. // test(adapters.size() > 0, "Got zero adapters! Hard to run an adapter test with no adapters!");
  1501. //
  1502. // // For each reported adapter...
  1503. // for(S32 i=0; i<adapters.size(); i++)
  1504. // {
  1505. // UnitPrint(avar("Testing adapter #%d (%s) in %s.",
  1506. // adapters[i]->mIndex,
  1507. // adapters[i]->mName,
  1508. // GFXInit::getAdapterNameFromType(adapters[i]->mType)));
  1509. //
  1510. // // Init the device.
  1511. // mDevice = GFXInit::createDevice(adapters[i]);
  1512. // test(mDevice, "Failed to create a device!");
  1513. //
  1514. // if(!mDevice)
  1515. // continue;
  1516. //
  1517. // // Create the window...
  1518. // mWindow = pwm->createWindow(mDevice, vm);
  1519. // test(mWindow, "Failed to create a window for this device!");
  1520. //
  1521. // if(!mWindow)
  1522. // {
  1523. // SAFE_DELETE(mDevice);
  1524. // continue;
  1525. // }
  1526. //
  1527. // // Create some representative items:
  1528. // // - a cube builder...
  1529. // mCube = new CubeBuilder();
  1530. // mCube->ensureValid(mDevice, 1.0f);
  1531. //
  1532. // // - a texture
  1533. // mTex = new GFXTexHandle();
  1534. // if((*mTex).isNull())
  1535. // (*mTex) = mDevice->getTextureManager()->createTexture("common/gui/images/GG_Icon.png",
  1536. // &GFXDefaultPersistentProfile);
  1537. //
  1538. // // Hook in our events.
  1539. // // Setup our events.
  1540. // mWindow->signalRender.notify(this, &TestGFXDeviceSwitching::onRenderSignal);
  1541. // mWindow->signalApp.notify (this, &TestGFXDeviceSwitching::onAppSignal);
  1542. //
  1543. // // Render until the user gets bored.
  1544. // while(Process::processEvents());
  1545. //
  1546. // // And clean up, so we can do it again.
  1547. // SAFE_DELETE(mTex);
  1548. // SAFE_DELETE(mCube);
  1549. // SAFE_DELETE(mDevice);
  1550. // SAFE_DELETE(mWindow);
  1551. // }
  1552. //
  1553. // // All done!
  1554. // SAFE_DELETE(pwm);
  1555. // }
  1556. //};