Fix segfaults in case the image is not created. Add test which simply checks which formats are supported for screenshots.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3752 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
8d6dd90997
commit
cae05e6a69
|
@ -4285,7 +4285,7 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE
|
|||
break;
|
||||
case ECF_R8G8B8:
|
||||
fmt = GL_BGR;
|
||||
type = GL_RGB;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case ECF_A8R8G8B8:
|
||||
fmt = GL_BGRA;
|
||||
|
@ -4365,7 +4365,9 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE
|
|||
}
|
||||
IImage* newImage = createImage(format, ScreenSize);
|
||||
|
||||
u8* pixels = static_cast<u8*>(newImage->lock());
|
||||
u8* pixels = 0;
|
||||
if (newImage)
|
||||
pixels = static_cast<u8*>(newImage->lock());
|
||||
if (pixels)
|
||||
{
|
||||
GLenum tgt=GL_FRONT;
|
||||
|
@ -4418,14 +4420,15 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE
|
|||
delete [] tmpBuffer;
|
||||
}
|
||||
|
||||
newImage->unlock();
|
||||
|
||||
if (testGLError() || !pixels)
|
||||
if (newImage)
|
||||
{
|
||||
newImage->drop();
|
||||
return 0;
|
||||
newImage->unlock();
|
||||
if (testGLError() || !pixels)
|
||||
{
|
||||
newImage->drop();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ int main(int argumentCount, char * arguments[])
|
|||
TEST(ioScene);
|
||||
// all driver checks
|
||||
TEST(videoDriver);
|
||||
TEST(screenshot);
|
||||
TEST(drawPixel);
|
||||
TEST(drawRectOutline);
|
||||
TEST(guiDisabledMenu);
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright (C) 2008-2011 Colin MacDonald
|
||||
// No rights reserved: this software is in the public domain.
|
||||
|
||||
#include "testUtils.h"
|
||||
|
||||
using namespace irr;
|
||||
|
||||
// Tests screenshots.
|
||||
/** At the moment, this just verifies that the last frame of the animation produces the expected bitmap. */
|
||||
bool testShots(video::E_DRIVER_TYPE type)
|
||||
{
|
||||
IrrlichtDevice *device = createDevice(type, core::dimension2d<u32>(160, 120), 32);
|
||||
if (!device)
|
||||
return true;
|
||||
|
||||
video::IVideoDriver* driver = device->getVideoDriver();
|
||||
scene::ISceneManager * smgr = device->getSceneManager();
|
||||
|
||||
scene::IAnimatedMesh* mesh = smgr->getMesh("../media/sydney.md2");
|
||||
scene::IAnimatedMeshSceneNode* node;
|
||||
|
||||
if (!mesh)
|
||||
return false;
|
||||
node = smgr->addAnimatedMeshSceneNode(mesh);
|
||||
if (!node)
|
||||
return false;
|
||||
node->setPosition(core::vector3df(20, 0, 30));
|
||||
node->setMaterialFlag(video::EMF_LIGHTING, false);
|
||||
node->setMaterialTexture(0, driver->getTexture("../media/sydney.bmp"));
|
||||
node->setLoopMode(false);
|
||||
|
||||
(void)smgr->addCameraSceneNode();
|
||||
|
||||
// Just jump to the last frame since that's all we're interested in.
|
||||
node->setMD2Animation(scene::EMAT_DEATH_FALLBACK);
|
||||
node->setCurrentFrame((f32)(node->getEndFrame()));
|
||||
node->setAnimationSpeed(0);
|
||||
|
||||
device->run();
|
||||
driver->beginScene(true, true, video::SColor(255, 255, 255, 0));
|
||||
smgr->drawAll();
|
||||
driver->endScene();
|
||||
|
||||
for (u32 i=0; i<video::ECF_UNKNOWN; ++i)
|
||||
{
|
||||
video::IImage* img = driver->createScreenShot((video::ECOLOR_FORMAT)i);
|
||||
logTestString("Color Format %d %ssupported\n", i, (img && img->getColorFormat() == i)?"":"un");
|
||||
if (img)
|
||||
img->drop();
|
||||
}
|
||||
device->closeDevice();
|
||||
device->run();
|
||||
device->drop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool screenshot()
|
||||
{
|
||||
testShots(video::EDT_OPENGL);
|
||||
testShots(video::EDT_DIRECT3D9);
|
||||
return true;
|
||||
}
|
|
@ -161,7 +161,7 @@ static bool doTests()
|
|||
tmp.getAngle(), ref.getAngle());
|
||||
return false;
|
||||
}
|
||||
tmp = core::vector2d<T>(-1.53080559e-16, 2.49999523);
|
||||
tmp = core::vector2d<T>(static_cast<T>(-1.53080559e-16), static_cast<T>(2.49999523));
|
||||
ref = core::vector2d<f64>(-1.53080559e-16, 2.49999523);
|
||||
if (!equals(tmp.getAngle(),ref.getAngle()))
|
||||
{
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
<Unit filename="renderTargetTexture.cpp" />
|
||||
<Unit filename="sceneCollisionManager.cpp" />
|
||||
<Unit filename="sceneNodeAnimator.cpp" />
|
||||
<Unit filename="screenshot.cpp" />
|
||||
<Unit filename="serializeAttributes.cpp" />
|
||||
<Unit filename="skinnedMesh.cpp" />
|
||||
<Unit filename="softwareDevice.cpp" />
|
||||
|
|
|
@ -125,6 +125,7 @@
|
|||
<ClCompile Include="renderTargetTexture.cpp" />
|
||||
<ClCompile Include="sceneCollisionManager.cpp" />
|
||||
<ClCompile Include="sceneNodeAnimator.cpp" />
|
||||
<ClCompile Include="screenshot.cpp" />
|
||||
<ClCompile Include="serializeAttributes.cpp" />
|
||||
<ClCompile Include="skinnedMesh.cpp" />
|
||||
<ClCompile Include="softwareDevice.cpp" />
|
||||
|
|
|
@ -348,6 +348,10 @@
|
|||
RelativePath=".\sceneNodeAnimator.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\screenshot.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\serializeAttributes.cpp"
|
||||
>
|
||||
|
|
|
@ -347,6 +347,10 @@
|
|||
RelativePath=".\sceneNodeAnimator.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\screenshot.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\serializeAttributes.cpp"
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue