Commit a0e403fc authored by cutealien's avatar cutealien

Add setRenderTarget interface taking an ITexture back in as wrapper.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5073 dfc29bdd-3216-0410-991c-e03cc46cb475
parent ed12a085
...@@ -556,6 +556,42 @@ namespace video ...@@ -556,6 +556,42 @@ namespace video
return setRenderTarget(target, idArray, clearBackBuffer, clearDepthBuffer, clearStencilBuffer, clearColor); return setRenderTarget(target, idArray, clearBackBuffer, clearDepthBuffer, clearStencilBuffer, clearColor);
} }
//! Sets a new render target.
/** This will only work if the driver supports the
EVDF_RENDER_TO_TARGET feature, which can be queried with
queryFeature(). Usually, rendering to textures is done in this
way:
\code
// create render target
ITexture* target = driver->addRenderTargetTexture(core::dimension2d<u32>(128,128), "rtt1");
// ...
driver->setRenderTarget(target); // set render target
// .. draw stuff here
driver->setRenderTarget(0); // set previous render target
\endcode
Please note that you cannot render 3D or 2D geometry with a
render target as texture on it when you are rendering the scene
into this render target at the same time. It is usually only
possible to render into a texture between the
IVideoDriver::beginScene() and endScene() method calls.
\param texture New render target. Must be a texture created with
IVideoDriver::addRenderTargetTexture(). If set to 0, it sets
the previous render target which was set before the last
setRenderTarget() call.
\param clearBackBuffer Clears the backbuffer of the render
target with the color parameter
\param clearZBuffer Clears the zBuffer of the rendertarget.
Note that because the frame buffer may share the zbuffer with
the rendertarget, its zbuffer might be partially cleared too
by this.
\param color The background color for the render target.
\return True if sucessful and false if not. */
virtual bool setRenderTarget(video::ITexture* texture,
bool clearBackBuffer = true, bool clearZBuffer = true,
SColor color = video::SColor(0, 0, 0, 0)) = 0;
//! Sets a new viewport. //! Sets a new viewport.
/** Every rendering operation is done into this new area. /** Every rendering operation is done into this new area.
\param area: Rectangle defining the new area of rendering \param area: Rectangle defining the new area of rendering
......
...@@ -2133,7 +2133,7 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria ...@@ -2133,7 +2133,7 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria
// if (resetAllRenderstates || (lastmaterial.ZWriteEnable != material.ZWriteEnable)) // if (resetAllRenderstates || (lastmaterial.ZWriteEnable != material.ZWriteEnable))
{ {
if (material.ZWriteEnable && (AllowZWriteOnTransparent || (!material.isTransparent() && if (material.ZWriteEnable && (AllowZWriteOnTransparent || (!material.isTransparent() &&
!MaterialRenderers[material.MaterialType].Renderer->isTransparent()))) !MaterialRenderers[material.MaterialType].Renderer->isTransparent())))
{ {
pID3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE); pID3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE);
} }
......
...@@ -83,7 +83,7 @@ IImageWriter* createImageWriterPPM(); ...@@ -83,7 +83,7 @@ IImageWriter* createImageWriterPPM();
//! constructor //! constructor
CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& screenSize) CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& screenSize)
: CurrentRenderTarget(0), CurrentRenderTargetSize(0, 0), FileSystem(io), MeshManipulator(0), : TextureRenderTarget(0), CurrentRenderTarget(0), CurrentRenderTargetSize(0, 0), FileSystem(io), MeshManipulator(0),
ViewPort(0, 0, 0, 0), ScreenSize(screenSize), PrimitivesDrawn(0), MinVertexCountForVBO(500), ViewPort(0, 0, 0, 0), ScreenSize(screenSize), PrimitivesDrawn(0), MinVertexCountForVBO(500),
TextureCreationFlags(0), OverrideMaterial2DEnabled(false), AllowZWriteOnTransparent(false) TextureCreationFlags(0), OverrideMaterial2DEnabled(false), AllowZWriteOnTransparent(false)
{ {
...@@ -213,6 +213,9 @@ CNullDriver::~CNullDriver() ...@@ -213,6 +213,9 @@ CNullDriver::~CNullDriver()
if (MeshManipulator) if (MeshManipulator)
MeshManipulator->drop(); MeshManipulator->drop();
if (TextureRenderTarget)
TextureRenderTarget->drop();
removeAllRenderTargets(); removeAllRenderTargets();
deleteAllTextures(); deleteAllTextures();
...@@ -624,6 +627,25 @@ bool CNullDriver::setRenderTarget(IRenderTarget* target, core::array<u32> active ...@@ -624,6 +627,25 @@ bool CNullDriver::setRenderTarget(IRenderTarget* target, core::array<u32> active
return false; return false;
} }
bool CNullDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuffer, bool clearZBuffer, SColor color)
{
if (texture)
{
if (!TextureRenderTarget)
{
// (there's no createRenderTarget)
TextureRenderTarget = addRenderTarget();
TextureRenderTarget->grab();
removeRenderTarget(TextureRenderTarget);
}
return setRenderTarget(TextureRenderTarget, 0, clearBackBuffer, clearZBuffer, clearZBuffer, color);
}
else
{
return setRenderTarget(NULL, 0, clearBackBuffer, clearZBuffer, clearZBuffer, color);
}
}
//! sets a viewport //! sets a viewport
void CNullDriver::setViewPort(const core::rect<s32>& area) void CNullDriver::setViewPort(const core::rect<s32>& area)
......
...@@ -104,6 +104,11 @@ namespace video ...@@ -104,6 +104,11 @@ namespace video
virtual bool setRenderTarget(IRenderTarget* target, core::array<u32> activeTextureID, bool clearBackBuffer, virtual bool setRenderTarget(IRenderTarget* target, core::array<u32> activeTextureID, bool clearBackBuffer,
bool clearDepthBuffer, bool clearStencilBuffer, SColor clearColor) _IRR_OVERRIDE_; bool clearDepthBuffer, bool clearStencilBuffer, SColor clearColor) _IRR_OVERRIDE_;
//! set a render target
virtual bool setRenderTarget(video::ITexture* texture,
bool clearBackBuffer = true, bool clearZBuffer = true,
SColor color = video::SColor(0, 0, 0, 0)) _IRR_OVERRIDE_;
//! sets a viewport //! sets a viewport
virtual void setViewPort(const core::rect<s32>& area) _IRR_OVERRIDE_; virtual void setViewPort(const core::rect<s32>& area) _IRR_OVERRIDE_;
...@@ -804,6 +809,7 @@ namespace video ...@@ -804,6 +809,7 @@ namespace video
core::array<SOccQuery> OcclusionQueries; core::array<SOccQuery> OcclusionQueries;
core::array<IRenderTarget*> RenderTargets; core::array<IRenderTarget*> RenderTargets;
IRenderTarget* TextureRenderTarget; // A default rendertarget for rendering to single textures.
IRenderTarget* CurrentRenderTarget; IRenderTarget* CurrentRenderTarget;
core::dimension2d<u32> CurrentRenderTargetSize; core::dimension2d<u32> CurrentRenderTargetSize;
......
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