mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-09 09:13:49 +01:00
9ce63bc7d3
SMaterialLayers are now identical when both have identity matrices. Before it didn't consider them identical when one layer had set the identity matrix explicitly and the other didn't. Generally didn't matter, just caused very rarely some extra state switches in the drivers. And just as rarely had a cheaper comparison. Just seems more correct this way. operator= no longer releases texture memory which was allocated at one point. Unless explicitly requested such memory is now always released later in the destructor. This can avoid quite a few memory allocations/released in the driver. Usually not a noticeable performance difference on most platforms. But it can help avoid memory fragmentation. We instead use an extra bool now to tell if the texture memory is used. So slight increase in SMaterialLayer and SMaterial size. But I did a quick performance test and this had no negative influence here, while it did improve speed in the case where it switched between material layers using/not using texture matrices a bit. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6488 dfc29bdd-3216-0410-991c-e03cc46cb475
112 lines
3.0 KiB
C++
112 lines
3.0 KiB
C++
#include "testUtils.h"
|
|
|
|
using namespace irr;
|
|
|
|
static bool polygonOffset(video::E_DRIVER_TYPE type)
|
|
{
|
|
IrrlichtDevice* device = createDevice(type, core::dimension2d<u32>(160, 120));
|
|
|
|
if (device == 0)
|
|
return true;
|
|
|
|
video::IVideoDriver* driver = device->getVideoDriver();
|
|
if (!driver->queryFeature(video::EVDF_POLYGON_OFFSET))
|
|
{
|
|
device->closeDevice();
|
|
device->run();
|
|
device->drop();
|
|
return true;
|
|
}
|
|
|
|
stabilizeScreenBackground(driver);
|
|
|
|
scene::ISceneManager* smgr = device->getSceneManager();
|
|
|
|
// create first plane
|
|
scene::ISceneNode* plane = smgr->addMeshSceneNode(smgr->addHillPlaneMesh(
|
|
"plane", core::dimension2df(10,10), core::dimension2du(2,2)), 0, -1,
|
|
core::vector3df(0,0,20), core::vector3df(270,0,0));
|
|
|
|
if (plane)
|
|
{
|
|
plane->setMaterialTexture(0, driver->getTexture("../media/t351sml.jpg"));
|
|
plane->setMaterialFlag(video::EMF_LIGHTING, false);
|
|
plane->setMaterialFlag(video::EMF_BACK_FACE_CULLING, true);
|
|
}
|
|
|
|
// create second plane exactly on top of the first one
|
|
scene::ISceneNode* plane2 = smgr->addMeshSceneNode(smgr->addHillPlaneMesh(
|
|
"plane2", core::dimension2df(5,5), core::dimension2du(2,2)), 0, -1,
|
|
core::vector3df(0,0,20), core::vector3df(270,0,0));
|
|
plane2->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
|
|
|
|
smgr->addCameraSceneNode();
|
|
|
|
// test back plane to back
|
|
plane->getMaterial(0).PolygonOffsetSlopeScale = 1.f;
|
|
plane->getMaterial(0).PolygonOffsetDepthBias = 1.f;
|
|
if ( type == video::EDT_DIRECT3D9 )
|
|
plane->getMaterial(0).PolygonOffsetDepthBias *= 2.f*4.8e-7f;
|
|
|
|
driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,113,113,133));
|
|
smgr->drawAll();
|
|
driver->endScene();
|
|
bool result = takeScreenshotAndCompareAgainstReference(driver, "-polygonBack.png");
|
|
|
|
//reset back plane
|
|
plane->getMaterial(0).PolygonOffsetDepthBias=0;
|
|
// test front plane to front
|
|
plane2->getMaterial(0).PolygonOffsetSlopeScale=-1.f;
|
|
plane2->getMaterial(0).PolygonOffsetDepthBias=-1.f;
|
|
if ( type == video::EDT_DIRECT3D9 )
|
|
plane2->getMaterial(0).PolygonOffsetDepthBias *= 2.f*4.8e-7f;
|
|
driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,113,113,133));
|
|
smgr->drawAll();
|
|
driver->endScene();
|
|
result &= takeScreenshotAndCompareAgainstReference(driver, "-polygonFront.png");
|
|
|
|
device->closeDevice();
|
|
device->run();
|
|
device->drop();
|
|
return result;
|
|
}
|
|
|
|
static bool testSMaterial()
|
|
{
|
|
irr::video::SMaterial a;
|
|
irr::video::SMaterial b;
|
|
|
|
// Same by default?
|
|
if ( !(a == b) )
|
|
return false;
|
|
if ( a != b )
|
|
return false;
|
|
|
|
// getting (creating) one texture matrix shouldn't change things
|
|
b.TextureLayer[0].getTextureMatrix();
|
|
if ( a != b )
|
|
return false;
|
|
|
|
// no longer same now
|
|
b.TextureLayer[0].getTextureMatrix().setTextureScale(5.f, 0.5f);
|
|
if ( a == b )
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool material()
|
|
{
|
|
bool result = true;
|
|
|
|
TestWithAllDrivers(polygonOffset);
|
|
|
|
if ( !testSMaterial() )
|
|
{
|
|
logTestString("testSMaterial failed\n\n");
|
|
result = false;
|
|
}
|
|
|
|
return result;
|
|
}
|