material.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "testUtils.h"
  2. using namespace irr;
  3. static bool polygonOffset(video::E_DRIVER_TYPE type)
  4. {
  5. IrrlichtDevice* device = createDevice(type, core::dimension2d<u32>(160, 120));
  6. if (device == 0)
  7. return true;
  8. video::IVideoDriver* driver = device->getVideoDriver();
  9. if (!driver->queryFeature(video::EVDF_POLYGON_OFFSET))
  10. {
  11. device->closeDevice();
  12. device->run();
  13. device->drop();
  14. return true;
  15. }
  16. stabilizeScreenBackground(driver);
  17. scene::ISceneManager* smgr = device->getSceneManager();
  18. // create first plane
  19. scene::ISceneNode* plane = smgr->addMeshSceneNode(smgr->addHillPlaneMesh(
  20. "plane", core::dimension2df(10,10), core::dimension2du(2,2)), 0, -1,
  21. core::vector3df(0,0,20), core::vector3df(270,0,0));
  22. if (plane)
  23. {
  24. plane->setMaterialTexture(0, driver->getTexture("../media/t351sml.jpg"));
  25. plane->setMaterialFlag(video::EMF_LIGHTING, false);
  26. plane->setMaterialFlag(video::EMF_BACK_FACE_CULLING, true);
  27. }
  28. // create second plane exactly on top of the first one
  29. scene::ISceneNode* plane2 = smgr->addMeshSceneNode(smgr->addHillPlaneMesh(
  30. "plane2", core::dimension2df(5,5), core::dimension2du(2,2)), 0, -1,
  31. core::vector3df(0,0,20), core::vector3df(270,0,0));
  32. plane2->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
  33. smgr->addCameraSceneNode();
  34. // test back plane to back
  35. plane->getMaterial(0).PolygonOffsetSlopeScale = 1.f;
  36. plane->getMaterial(0).PolygonOffsetDepthBias = 1.f;
  37. if ( type == video::EDT_DIRECT3D9 )
  38. plane->getMaterial(0).PolygonOffsetDepthBias *= 2.f*4.8e-7f;
  39. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,113,113,133));
  40. smgr->drawAll();
  41. driver->endScene();
  42. bool result = takeScreenshotAndCompareAgainstReference(driver, "-polygonBack.png");
  43. //reset back plane
  44. plane->getMaterial(0).PolygonOffsetDepthBias=0;
  45. // test front plane to front
  46. plane2->getMaterial(0).PolygonOffsetSlopeScale=-1.f;
  47. plane2->getMaterial(0).PolygonOffsetDepthBias=-1.f;
  48. if ( type == video::EDT_DIRECT3D9 )
  49. plane2->getMaterial(0).PolygonOffsetDepthBias *= 2.f*4.8e-7f;
  50. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,113,113,133));
  51. smgr->drawAll();
  52. driver->endScene();
  53. result &= takeScreenshotAndCompareAgainstReference(driver, "-polygonFront.png");
  54. device->closeDevice();
  55. device->run();
  56. device->drop();
  57. return result;
  58. }
  59. static bool testSMaterial()
  60. {
  61. irr::video::SMaterial a;
  62. irr::video::SMaterial b;
  63. // Same by default?
  64. if ( !(a == b) )
  65. return false;
  66. if ( a != b )
  67. return false;
  68. // getting (creating) one texture matrix shouldn't change things
  69. b.TextureLayer[0].getTextureMatrix();
  70. if ( a != b )
  71. return false;
  72. // no longer same now
  73. b.TextureLayer[0].getTextureMatrix().setTextureScale(5.f, 0.5f);
  74. if ( a == b )
  75. return false;
  76. return true;
  77. }
  78. bool material()
  79. {
  80. bool result = true;
  81. TestWithAllDrivers(polygonOffset);
  82. if ( !testSMaterial() )
  83. {
  84. logTestString("testSMaterial failed\n\n");
  85. result = false;
  86. }
  87. return result;
  88. }