123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- #include "testUtils.h"
- using namespace irr;
- namespace
- {
- bool testWithRenderTarget(video::E_DRIVER_TYPE driverType)
- {
- // create device
- IrrlichtDevice *device = createDevice(driverType, core::dimension2d<u32>(160,120));
- if (device == 0)
- return true; // could not create selected driver.
- video::IVideoDriver* driver = device->getVideoDriver();
- if (!driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
- {
- device->closeDevice();
- device->run();
- device->drop();
- return true;
- }
- stabilizeScreenBackground(driver);
- logTestString("Testing driver %ls\n", driver->getName());
- video::ITexture* renderTargetTex = driver->addRenderTargetTexture(core::dimension2d<u32>(64, 64), "BASEMAP");
- video::ITexture* renderTargetDepth = driver->addRenderTargetTexture(core::dimension2d<u32>(64, 64), "rtd", video::ECF_D16);
- video::IRenderTarget* renderTarget = driver->addRenderTarget();
- renderTarget->setTexture(renderTargetTex, renderTargetDepth);
- video::ITexture* tex=driver->getTexture("../media/water.jpg");
- driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,255,0,255));//Backbuffer background is pink
- //draw the 256x256 water image on the rendertarget:
- driver->setRenderTargetEx(renderTarget,video::ECBF_COLOR|video::ECBF_DEPTH,video::SColor(255,0,0,255));//Rendertarget background is blue
- driver->draw2DImage(tex, core::position2d<s32>(0,0), core::recti(0,0,32,32));
- driver->setRenderTargetEx(0, 0);
- //draw the rendertarget on screen:
- //this should normally draw a 64x64 image containing a 32x32 image in the top left corner
- driver->draw2DImage(renderTargetTex, core::position2d<s32>(0,0));
- driver->endScene();
- bool result = takeScreenshotAndCompareAgainstReference(driver, "-draw2DImageRTT.png");
- device->closeDevice();
- device->run();
- device->drop();
- return result;
- }
- // Test various special destination rectangles
- bool testRectangles(video::E_DRIVER_TYPE driverType)
- {
- // create device
- IrrlichtDevice *device = createDevice(driverType, core::dimension2d<u32>(160,120));
- if (device == 0)
- return true; // could not create selected driver.
- video::IVideoDriver* driver = device->getVideoDriver();
- stabilizeScreenBackground(driver);
- logTestString("Testing driver %ls\n", driver->getName());
- video::ITexture *tex=driver->getTexture("../media/fireball.bmp");
- driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,255,0,255));//Backbuffer background is pink
- // draw normal, will be overdrwan in error case
- driver->draw2DImage(tex, core::recti(68,32,132,96), core::recti(0,0,64,64));
- //draw the image larger
- driver->draw2DImage(tex, core::recti(0,0,64,64), core::recti(0,0,32,32));
- //draw the image flipped horizontally
- driver->draw2DImage(tex, core::recti(132,0,68,64), core::recti(0,0,64,64));
- //draw the image smaller
- driver->draw2DImage(tex, core::recti(0,64,32,96), core::recti(0,0,64,64));
- //draw the image much smaller
- driver->draw2DImage(tex, core::recti(36,64,44,72), core::recti(0,0,64,64));
- //draw the image flipped horizontally
- driver->draw2DImage(tex, core::recti(68,64,132,0), core::recti(0,0,64,64));
- driver->endScene();
- bool result = takeScreenshotAndCompareAgainstReference(driver, "-draw2DImageRect.png");
- device->closeDevice();
- device->run();
- device->drop();
- return result;
- }
- // draws a complex (interlaced, paletted, alpha) png image
- bool testWithPNG(video::E_DRIVER_TYPE driverType)
- {
- // create device
- IrrlichtDevice *device = createDevice(driverType, core::dimension2d<u32>(160,120));
- if (device == 0)
- return true; // could not create selected driver.
- video::IVideoDriver* driver = device->getVideoDriver();
- stabilizeScreenBackground(driver);
- logTestString("Testing driver %ls\n", driver->getName());
- video::ITexture *tex=driver->getTexture("media/RedbrushAlpha-0.25.png");
- driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,40,40,255));//Backbuffer background is blue
- driver->draw2DImage(tex, core::recti(0,0,160,120), core::recti(0,0,256,256), 0, 0, true);
- driver->endScene();
- bool result = takeScreenshotAndCompareAgainstReference(driver, "-draw2DImagePNG.png", 98.f);
- device->closeDevice();
- device->run();
- device->drop();
- return result;
- }
- // draws an image and checks if the written example equals the original image
- bool testExactPlacement(video::E_DRIVER_TYPE driverType)
- {
- // create device
- IrrlichtDevice *device = createDevice(driverType, core::dimension2d<u32>(160,120), 32);
- if (device == 0)
- return true; // could not create selected driver.
- video::IVideoDriver* driver = device->getVideoDriver();
- if (driver->getColorFormat() != video::ECF_A8R8G8B8 || !driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
- {
- device->closeDevice();
- device->run();
- device->drop();
- return true;
- }
- stabilizeScreenBackground(driver);
- logTestString("Testing driver %ls\n", driver->getName());
- video::ITexture* renderTargetTex = driver->addRenderTargetTexture(core::dimension2d<u32>(32, 32), "rt1");
- video::ITexture* renderTargetDepth = driver->addRenderTargetTexture(core::dimension2d<u32>(32, 32), "rtd", video::ECF_D16);
- video::IRenderTarget* renderTarget = driver->addRenderTarget();
- renderTarget->setTexture(renderTargetTex, renderTargetDepth);
- video::ITexture* tex=driver->getTexture("../media/fireball.bmp");
- driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,40,40,255));//Backbuffer background is blue
- driver->setRenderTargetEx(renderTarget, 0, video::ECBF_COLOR | video::ECBF_DEPTH);
- driver->draw2DImage(tex, core::recti(0,0,32,32), core::recti(0,0,64,64));
- driver->setRenderTargetEx(0, 0, 0);
- driver->endScene();
- video::IImage* img = driver->createImage(renderTargetTex, core::vector2di(), renderTargetTex->getSize());
- driver->writeImageToFile(img, "results/fireball.png");
- img->drop();
- bool result = fuzzyCompareImages(driver,
- driverType == video::EDT_BURNINGSVIDEO ? "media/Burning's Video-fireball.png":"media/fireball.png", "results/fireball.png")>98.25f;
- device->closeDevice();
- device->run();
- device->drop();
- return result;
- }
- }
- bool draw2DImage()
- {
- bool result = true;
- TestWithAllDrivers(testWithRenderTarget);
- TestWithAllHWDrivers(testWithPNG);
- // TODO D3D driver moves image 1 pixel top-left in case of down scaling
- TestWithAllDrivers(testExactPlacement);
- TestWithAllDrivers(testRectangles);
- return result;
- }
|