Commit adb9effb authored by hybrid's avatar hybrid

Add the often requested Texture->Image conversion method

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2498 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 4f0bf8b9
......@@ -1016,7 +1016,7 @@ namespace video
//! Creates a software image from a part of another image.
/**
\param imageToCopy Image to copy the the new image in part.
\param imageToCopy Image to copy to the new image in part.
\param pos Position of rectangle to copy.
\param size Extents of rectangle to copy.
\return The created image.
......@@ -1026,6 +1026,18 @@ namespace video
const core::position2d<s32>& pos,
const core::dimension2d<u32>& size) =0;
//! Creates a software image from a part of a texture.
/**
\param texture Texture to copy to the new image in part.
\param pos Position of rectangle to copy.
\param size Extents of rectangle to copy.
\return The created image.
If you no longer need the image, you should call IImage::drop().
See IReferenceCounted::drop() for more information. */
virtual IImage* createImage(ITexture* texture,
const core::position2d<s32>& pos,
const core::dimension2d<u32>& size) =0;
//! Event handler for resize events. Only used by the engine internally.
/** Used to notify the driver that the window was resized.
Usually, there is no need to call this method. */
......
......@@ -12,6 +12,7 @@
#include "IImageWriter.h"
#include "IMaterialRenderer.h"
#include "CMeshManipulator.h"
#include "CColorConverter.h"
namespace irr
......@@ -1370,6 +1371,38 @@ IImage* CNullDriver::createImage(IImage* imageToCopy, const core::position2d<s32
}
//! Creates a software image from part of a texture.
IImage* CNullDriver::createImage(ITexture* texture, const core::position2d<s32>& pos, const core::dimension2d<u32>& size)
{
if (pos==core::position2di(0,0) && size == texture->getSize())
{
IImage* image = new CImage(texture->getColorFormat(), size, texture->lock(true), false);
texture->unlock();
return image;
}
else
{
// make sure to avoid buffer overruns
const core::rect<u32> clamped(core::vector2d<u32>(core::clamp(static_cast<u32>(pos.X), 0u, texture->getSize().Width),
core::clamp(static_cast<u32>(pos.Y), 0u, texture->getSize().Height)),
core::dimension2du(core::clamp(static_cast<u32>(size.Width), 0u, texture->getSize().Width),
core::clamp(static_cast<u32>(size.Height), 0u, texture->getSize().Height)));
if (!clamped.isValid())
return 0;
IImage* image = new CImage(texture->getColorFormat(), clamped.getSize());
void* src = texture->lock(true);
void* dst = image->lock();
for (u32 i=clamped.UpperLeftCorner.X; i<clamped.getHeight(); ++i)
{
video::CColorConverter::convert_viaFormat(src, texture->getColorFormat(), clamped.getWidth(), dst, image->getColorFormat());
}
image->unlock();
texture->unlock();
return image;
}
}
//! Sets the fog mode.
void CNullDriver::setFog(SColor color, E_FOG_TYPE fogType, f32 start, f32 end,
f32 density, bool pixelFog, bool rangeFog)
......
......@@ -343,6 +343,11 @@ namespace video
const core::position2d<s32>& pos,
const core::dimension2d<u32>& size);
//! Creates a software image from part of a texture.
virtual IImage* createImage(ITexture* texture,
const core::position2d<s32>& pos,
const core::dimension2d<u32>& size);
//! Draws a mesh buffer
virtual void drawMeshBuffer(const scene::IMeshBuffer* mb);
......
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