Commit 0cc1b698 authored by hybrid's avatar hybrid

Fix software renderer inconsistency with rest of drivers in case of invalid...

Fix software renderer inconsistency with rest of drivers in case of invalid destination rect for draw2DImage. Now no driver will render an image in these cases.
Added a test case to check behavior of all drivers for this situation.
Fixed comparison of similar test case to support fuzzy comparison and relaxed threshold.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4143 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 095ae506
...@@ -773,7 +773,8 @@ void CNullDriver::draw2DImage(const video::ITexture* texture, const core::rect<s ...@@ -773,7 +773,8 @@ void CNullDriver::draw2DImage(const video::ITexture* texture, const core::rect<s
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect, const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
const video::SColor* const colors, bool useAlphaChannelOfTexture) const video::SColor* const colors, bool useAlphaChannelOfTexture)
{ {
draw2DImage(texture, core::position2d<s32>(destRect.UpperLeftCorner), if (destRect.isValid())
draw2DImage(texture, core::position2d<s32>(destRect.UpperLeftCorner),
sourceRect, clipRect, colors?colors[0]:video::SColor(0xffffffff), sourceRect, clipRect, colors?colors[0]:video::SColor(0xffffffff),
useAlphaChannelOfTexture); useAlphaChannelOfTexture);
} }
......
...@@ -50,6 +50,46 @@ bool testWithRenderTarget(video::E_DRIVER_TYPE driverType) ...@@ -50,6 +50,46 @@ bool testWithRenderTarget(video::E_DRIVER_TYPE driverType)
return result; 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();
logTestString("Testing driver %ls\n", driver->getName());
video::ITexture *tex=driver->getTexture("../media/fireball.bmp");
driver->beginScene(true, true, 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 // draws a complex (interlaced, paletted, alpha) png image
bool testWithPNG(video::E_DRIVER_TYPE driverType) bool testWithPNG(video::E_DRIVER_TYPE driverType)
{ {
...@@ -112,7 +152,7 @@ bool testExactPlacement(video::E_DRIVER_TYPE driverType) ...@@ -112,7 +152,7 @@ bool testExactPlacement(video::E_DRIVER_TYPE driverType)
video::IImage* img = driver->createImage(rt, core::vector2di(), rt->getSize()); video::IImage* img = driver->createImage(rt, core::vector2di(), rt->getSize());
driver->writeImageToFile(img, "results/fireball.png"); driver->writeImageToFile(img, "results/fireball.png");
img->drop(); img->drop();
bool result = binaryCompareFiles("media/fireball.png", "results/fireball.png"); bool result = fuzzyCompareImages(driver, "media/fireball.png", "results/fireball.png")>98.25f;
device->closeDevice(); device->closeDevice();
device->run(); device->run();
...@@ -127,7 +167,9 @@ bool draw2DImage() ...@@ -127,7 +167,9 @@ bool draw2DImage()
{ {
bool result = true; bool result = true;
TestWithAllDrivers(testWithRenderTarget); TestWithAllDrivers(testWithRenderTarget);
TestWithAllDrivers(testExactPlacement);
TestWithAllHWDrivers(testWithPNG); TestWithAllHWDrivers(testWithPNG);
// TODO D3D driver moves image 1 pixel top-left in case of down scaling
TestWithAllDrivers(testExactPlacement);
TestWithAllDrivers(testRectangles);
return result; return result;
} }
...@@ -267,9 +267,9 @@ static float fuzzyCompareImages(irr::video::IImage * image1, ...@@ -267,9 +267,9 @@ static float fuzzyCompareImages(irr::video::IImage * image1,
} }
video::ECOLOR_FORMAT format1 = image1->getColorFormat(); video::ECOLOR_FORMAT format1 = image1->getColorFormat();
if(video::ECF_R8G8B8 != format1) if(video::ECF_A8R8G8B8 != format1 && video::ECF_R8G8B8 != format1)
{ {
logTestString("fuzzyCompareImages: image 1 must be ECF_R8G8B8\n"); logTestString("fuzzyCompareImages: image 1 must be ECF_AR8G8B8 or ECF_R8G8B8\n");
return 0.f; return 0.f;
} }
...@@ -287,6 +287,9 @@ static float fuzzyCompareImages(irr::video::IImage * image1, ...@@ -287,6 +287,9 @@ static float fuzzyCompareImages(irr::video::IImage * image1,
u32 mismatchedColours = 0; u32 mismatchedColours = 0;
for(u32 pixel = 0; pixel < pixels; ++pixel) for(u32 pixel = 0; pixel < pixels; ++pixel)
{ {
if(video::ECF_A8R8G8B8 == format1)
image1Data++;
const u8 r1 = *(image1Data++); const u8 r1 = *(image1Data++);
const u8 g1 = *(image1Data++); const u8 g1 = *(image1Data++);
const u8 b1 = *(image1Data++); const u8 b1 = *(image1Data++);
...@@ -309,6 +312,27 @@ static float fuzzyCompareImages(irr::video::IImage * image1, ...@@ -309,6 +312,27 @@ static float fuzzyCompareImages(irr::video::IImage * image1,
} }
//! Compare two images, returning the degree to which they match.
/** \param image1 The first image to compare.
\param image2 The second image to compare.
\return The match, from 0.f to 100.f */
float fuzzyCompareImages(irr::video::IVideoDriver * driver,
const char * fileName1, const char * fileName2)
{
assert(fileName1);
assert(fileName2);
irr::video::IImage * img1 = driver->createImageFromFile(fileName1);
if (!img1)
return 0;
irr::video::IImage * img2 = driver->createImageFromFile(fileName2);
const float result = fuzzyCompareImages(img1, img2);
logTestString("Image match: %f%%\n", result);
img1->drop();
if (img2)
img2->drop();
return result;
}
bool takeScreenshotAndCompareAgainstReference(irr::video::IVideoDriver * driver, bool takeScreenshotAndCompareAgainstReference(irr::video::IVideoDriver * driver,
const char * fileName, const char * fileName,
irr::f32 requiredMatch) irr::f32 requiredMatch)
...@@ -361,10 +385,10 @@ bool takeScreenshotAndCompareAgainstReference(irr::video::IVideoDriver * driver, ...@@ -361,10 +385,10 @@ bool takeScreenshotAndCompareAgainstReference(irr::video::IVideoDriver * driver,
return false; return false;
} }
float match = fuzzyCompareImages(screenshot, reference); const float match = fuzzyCompareImages(screenshot, reference);
logTestString("Image match: %f%%\n", match); logTestString("Image match: %f%%\n", match);
if(match < requiredMatch) if (match < requiredMatch)
{ {
irr::core::stringc mismatchFilename = "results/"; irr::core::stringc mismatchFilename = "results/";
mismatchFilename += driverName; mismatchFilename += driverName;
......
...@@ -36,6 +36,14 @@ extern bool binaryCompareFiles(const char * fileName1, const char * fileName2); ...@@ -36,6 +36,14 @@ extern bool binaryCompareFiles(const char * fileName1, const char * fileName2);
\return true if the files are identical, false on any error or difference. */ \return true if the files are identical, false on any error or difference. */
extern bool xmlCompareFiles(irr::io::IFileSystem * fs, const char * fileName1, const char * fileName2); extern bool xmlCompareFiles(irr::io::IFileSystem * fs, const char * fileName1, const char * fileName2);
//! Compare two images, returning the degree to which they match.
/** \param driver The Irrlicht video driver.
\param fileName1 The first image to compare.
\param fileName2 The second image to compare.
\return The match, from 0.f to 100.f */
extern float fuzzyCompareImages(irr::video::IVideoDriver * driver,
const char * fileName1, const char * fileName2);
//! Take a screenshot and compare it against a reference screenshot in the tests/media subdirectory //! Take a screenshot and compare it against a reference screenshot in the tests/media subdirectory
/** \param driver The Irrlicht video driver. /** \param driver The Irrlicht video driver.
\param fileName The unique filename suffix that will be appended to the name of the video driver. \param fileName The unique filename suffix that will be appended to the name of the video driver.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment