drawVertexPrimitive.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "testUtils.h"
  2. using namespace irr;
  3. namespace
  4. {
  5. // this test renders random point clouds using different primitives on top
  6. // tests the primitives type support in general and can hint to differences
  7. // between the drivers
  8. bool testWithDriver(video::E_DRIVER_TYPE driverType)
  9. {
  10. IrrlichtDevice *device =
  11. createDevice(driverType, core::dimension2du(160, 120));
  12. if (!device)
  13. return true;
  14. scene::ISceneManager* smgr = device->getSceneManager();
  15. video::IVideoDriver* driver = device->getVideoDriver();
  16. stabilizeScreenBackground(driver);
  17. logTestString("Testing driver %ls\n", driver->getName());
  18. smgr->addCameraSceneNode(0, core::vector3df(128,128,-100), core::vector3df(128,128,128));
  19. scene::SMeshBuffer Buffer;
  20. Buffer.Material.Wireframe = false;
  21. Buffer.Material.Lighting = false;
  22. Buffer.Material.FogEnable = false;
  23. Buffer.Material.BackfaceCulling = false;
  24. Buffer.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
  25. device->getRandomizer()->reset();
  26. const u32 points=256;
  27. Buffer.Vertices.reallocate(points);
  28. for (u32 i=0; i<points; ++i)
  29. {
  30. f32 x = (f32)(1+device->getRandomizer()->rand()%points);
  31. f32 y = (f32)(1+device->getRandomizer()->rand()%points);
  32. f32 z = (f32)(1+device->getRandomizer()->rand()%points);
  33. video::SColor color(255, device->getRandomizer()->rand()%255, device->getRandomizer()->rand()%255, device->getRandomizer()->rand()%255);
  34. Buffer.Vertices.push_back( video::S3DVertex(x,y,z,0,1,0,color,0,0) );
  35. }
  36. Buffer.recalculateBoundingBox();
  37. for (u32 i=0; i<Buffer.Vertices.size(); ++i)
  38. {
  39. Buffer.Indices.push_back(i);
  40. }
  41. bool result = true;
  42. for (u32 Type=scene::EPT_POINTS; Type <= scene::EPT_POINT_SPRITES; ++Type)
  43. {
  44. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,100,101,140));
  45. smgr->drawAll();
  46. u32 primCount = 0;
  47. switch (Type)
  48. {
  49. case scene::EPT_POINTS: primCount = Buffer.Indices.size(); break;
  50. case scene::EPT_LINE_STRIP: primCount = Buffer.Indices.size()-1; break;
  51. case scene::EPT_LINE_LOOP: primCount = Buffer.Indices.size()-1; break;
  52. case scene::EPT_LINES: primCount = Buffer.Indices.size()/2; break;
  53. case scene::EPT_TRIANGLE_STRIP: primCount = Buffer.Indices.size()-2; break;
  54. case scene::EPT_TRIANGLE_FAN: primCount = Buffer.Indices.size()-2; break;
  55. case scene::EPT_TRIANGLES: primCount = Buffer.Indices.size()/3; break;
  56. case scene::EPT_QUAD_STRIP: primCount = (Buffer.Indices.size()-2)/4; break;
  57. case scene::EPT_QUADS: primCount = Buffer.Indices.size()/4; break;
  58. case scene::EPT_POLYGON: primCount = Buffer.Indices.size()-1; break;
  59. case scene::EPT_POINT_SPRITES: primCount = Buffer.Indices.size(); break;
  60. default: break;
  61. }
  62. // TODO: mode is buggy, but required for skybox. So driver supports it, but would core dump here.
  63. //burning v0.53 works
  64. #if 0
  65. if (driverType==video::EDT_BURNINGSVIDEO && Type==scene::EPT_TRIANGLE_FAN)
  66. continue;
  67. #endif
  68. driver->setMaterial(Buffer.Material);
  69. driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
  70. driver->drawVertexPrimitiveList(Buffer.getVertices(),
  71. Buffer.getVertexCount(), Buffer.getIndices(), primCount,
  72. video::EVT_STANDARD, (scene::E_PRIMITIVE_TYPE)Type,
  73. video::EIT_16BIT);
  74. driver->endScene();
  75. core::stringc name = "-drawVPL_";
  76. // we use character enumeration as we have more than 9 types
  77. name.append(Type-scene::EPT_POINTS+'a');
  78. name.append(".png");
  79. result &= takeScreenshotAndCompareAgainstReference(driver, name.c_str(), 99.5f);
  80. }
  81. device->closeDevice();
  82. device->run();
  83. device->drop();
  84. return result ;
  85. }
  86. }
  87. bool drawVertexPrimitive(void)
  88. {
  89. bool result = true;
  90. TestWithAllDrivers(testWithDriver);
  91. return result;
  92. }