material.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. bool material()
  60. {
  61. bool result = true;
  62. TestWithAllDrivers(polygonOffset);
  63. return result;
  64. }