Commit b44c2bda authored by hybrid's avatar hybrid

Added RTTs to texture cache.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1622 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 324acd72
Changes in version 1.5 (... 2008) Changes in version 1.5 (... 2008)
- Major API change: RTTs are now created via addRenderTargetTexture instead of createRenderTargetTexture, which allows to retrieve them from the texture cache, but also changes the way of removing the RTTs, and especially one must not drop the pointer anymore.
- WindowsCE-Bugfix - WindowsCE-Bugfix
- isBetweenPoints return true now even for the begin and end points, i.e. line segments are now including their start and end. - isBetweenPoints return true now even for the begin and end points, i.e. line segments are now including their start and end.
......
...@@ -120,14 +120,14 @@ int main() ...@@ -120,14 +120,14 @@ int main()
/* /*
To test out the render to texture feature, we need a render target To test out the render to texture feature, we need a render target
texture. These are not like standard textures, but need to be created texture. These are not like standard textures, but need to be created
first. To create one, we call IVideoDriver::createRenderTargetTexture() first. To create one, we call IVideoDriver::addRenderTargetTexture()
and specify the size of the texture. Please don't use sizes bigger than and specify the size of the texture. Please don't use sizes bigger than
the frame buffer for this, because the render target shares the zbuffer the frame buffer for this, because the render target shares the zbuffer
with the frame buffer. And because we want to render the scene not from with the frame buffer.
the user camera into the texture, we add another fixed camera to the Because we want to render the scene not from the user camera into the
scene. But before we do all this, we check if the current running texture, we add another fixed camera to the scene. But before we do all
driver is able to render to textures. If it is not, we simply display a this, we check if the current running driver is able to render to
warning text. textures. If it is not, we simply display a warning text.
*/ */
// create render target // create render target
...@@ -137,7 +137,7 @@ int main() ...@@ -137,7 +137,7 @@ int main()
if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET)) if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
{ {
rt = driver->createRenderTargetTexture(core::dimension2d<s32>(256,256)); rt = driver->addRenderTargetTexture(core::dimension2d<s32>(256,256), "RTT1");
test->setMaterialTexture(0, rt); // set material of cube to render target test->setMaterialTexture(0, rt); // set material of cube to render target
// add fixed camera // add fixed camera
...@@ -218,9 +218,6 @@ int main() ...@@ -218,9 +218,6 @@ int main()
} }
} }
if (rt)
rt->drop(); // drop render target because we created if with a create() method
device->drop(); // drop device device->drop(); // drop device
return 0; return 0;
} }
......
...@@ -214,17 +214,22 @@ namespace video ...@@ -214,17 +214,22 @@ namespace video
information. */ information. */
virtual ITexture* addTexture(const c8* name, IImage* image) = 0; virtual ITexture* addTexture(const c8* name, IImage* image) = 0;
//! Creates a render target texture. //! Adds a new render target texture to the texture cache.
/** \param size Size of the texture, in pixels. Width and /** \param size Size of the texture, in pixels. Width and
height should be a power of two (e.g. 64, 128, 256, 512, ...) height should be a power of two (e.g. 64, 128, 256, 512, ...)
and it should not be bigger than the backbuffer, because it and it should not be bigger than the backbuffer, because it
shares the zbuffer with the screen buffer. shares the zbuffer with the screen buffer.
\param name An optional name for the RTT. \param name An optional name for the RTT.
\return Pointer to the created texture or 0 if the texture \return Pointer to the created texture or 0 if the texture
could not be created. If you no longer need the image, you could not be created. This pointer should not be dropped. See
should call ITexture::drop(). See IReferenceCounted::drop() IReferenceCounted::drop() for more information. */
for more information. */ virtual ITexture* addRenderTargetTexture(const core::dimension2d<s32>& size,
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name = 0) = 0; const c8* name=0) =0;
//! Adds a new render target texture
/** \deprecated use addRenderTargetTexture instead. */
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size,
const c8* name=0) =0;
//! Removes a texture from the texture cache and deletes it. //! Removes a texture from the texture cache and deletes it.
/** This method can free a lot of memory! /** This method can free a lot of memory!
...@@ -293,7 +298,7 @@ namespace video ...@@ -293,7 +298,7 @@ namespace video
way: way:
\code \code
// create render target // create render target
ITexture* target = driver->createRenderTargetTexture(core::dimension2d<s32>(128,128)); ITexture* target = driver->addRenderTargetTexture(core::dimension2d<s32>(128,128), "rtt1");
// ... // ...
...@@ -311,7 +316,7 @@ namespace video ...@@ -311,7 +316,7 @@ namespace video
simple workaround for this is to flip the texture coordinates simple workaround for this is to flip the texture coordinates
of the geometry where the render target texture is displayed on. of the geometry where the render target texture is displayed on.
\param texture New render target. Must be a texture created with \param texture New render target. Must be a texture created with
IVideoDriver::createRenderTargetTexture(). If set to 0, it sets IVideoDriver::addRenderTargetTexture(). If set to 0, it sets
the previous render target which was set before the last the previous render target which was set before the last
setRenderTarget() call. setRenderTarget() call.
\param clearBackBuffer Clears the backbuffer of the render \param clearBackBuffer Clears the backbuffer of the render
......
...@@ -752,10 +752,15 @@ bool CD3D8Driver::setRenderTarget(video::ITexture* texture, ...@@ -752,10 +752,15 @@ bool CD3D8Driver::setRenderTarget(video::ITexture* texture,
//! Creates a render target texture. //! Creates a render target texture.
ITexture* CD3D8Driver::createRenderTargetTexture( ITexture* CD3D8Driver::addRenderTargetTexture(
const core::dimension2d<s32>& size, const c8* name) const core::dimension2d<s32>& size, const c8* name)
{ {
return new CD3D8Texture(this, size, name); if (!name)
name="rt";
ITexture* tex = new CD3D8Texture(this, size, name);
addTexture(tex);
tex->drop();
return tex;
} }
......
...@@ -180,7 +180,8 @@ namespace video ...@@ -180,7 +180,8 @@ namespace video
virtual IVideoDriver* getVideoDriver(); virtual IVideoDriver* getVideoDriver();
//! Creates a render target texture. //! Creates a render target texture.
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name); virtual ITexture* addRenderTargetTexture(const core::dimension2d<s32>& size,
const c8* name);
//! Clears the ZBuffer. //! Clears the ZBuffer.
virtual void clearZBuffer(); virtual void clearZBuffer();
......
...@@ -2434,9 +2434,15 @@ IVideoDriver* CD3D9Driver::getVideoDriver() ...@@ -2434,9 +2434,15 @@ IVideoDriver* CD3D9Driver::getVideoDriver()
//! Creates a render target texture. //! Creates a render target texture.
ITexture* CD3D9Driver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name) ITexture* CD3D9Driver::addRenderTargetTexture(const core::dimension2d<s32>& size,
{ const c8* name)
return new CD3D9Texture(this, size, name); {
if (!name)
name="rt";
ITexture* tex = new CD3D9Texture(this, size, name);
addTexture(tex);
tex->drop();
return tex;
} }
......
...@@ -200,7 +200,8 @@ namespace video ...@@ -200,7 +200,8 @@ namespace video
virtual IVideoDriver* getVideoDriver(); virtual IVideoDriver* getVideoDriver();
//! Creates a render target texture. //! Creates a render target texture.
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name); virtual ITexture* addRenderTargetTexture(const core::dimension2d<s32>& size,
const c8* name);
//! Clears the ZBuffer. //! Clears the ZBuffer.
virtual void clearZBuffer(); virtual void clearZBuffer();
......
...@@ -1808,12 +1808,15 @@ s32 CNullDriver::addShaderMaterialFromFiles(const c8* vertexShaderProgramFileNam ...@@ -1808,12 +1808,15 @@ s32 CNullDriver::addShaderMaterialFromFiles(const c8* vertexShaderProgramFileNam
return result; return result;
} }
//! Creates a render target texture. //! Creates a render target texture.
ITexture* CNullDriver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name) ITexture* CNullDriver::addRenderTargetTexture(const core::dimension2d<s32>& size,
const c8* name)
{ {
return 0; return 0;
} }
//! Clears the ZBuffer. //! Clears the ZBuffer.
void CNullDriver::clearZBuffer() void CNullDriver::clearZBuffer()
{ {
...@@ -1833,6 +1836,7 @@ IImage* CNullDriver::createScreenShot() ...@@ -1833,6 +1836,7 @@ IImage* CNullDriver::createScreenShot()
return 0; return 0;
} }
// prints renderer version // prints renderer version
void CNullDriver::printVersion() void CNullDriver::printVersion()
{ {
...@@ -1879,6 +1883,15 @@ void CNullDriver::enableClipPlane(u32 index, bool enable) ...@@ -1879,6 +1883,15 @@ void CNullDriver::enableClipPlane(u32 index, bool enable)
} }
ITexture* CNullDriver::createRenderTargetTexture(const core::dimension2d<s32>& size,
const c8* name)
{
os::Printer::log("createRenderTargetTexture is deprecated, use addRenderTargetTexture istead");
ITexture* tex = addRenderTargetTexture(size, name);
tex->grab();
return tex;
}
} // end namespace } // end namespace
} // end namespace } // end namespace
......
...@@ -267,7 +267,8 @@ namespace video ...@@ -267,7 +267,8 @@ namespace video
virtual void removeAllTextures(); virtual void removeAllTextures();
//! Creates a render target texture. //! Creates a render target texture.
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name); virtual ITexture* addRenderTargetTexture(const core::dimension2d<s32>& size,
const c8* name);
//! Creates an 1bit alpha channel of the texture based of an color key. //! Creates an 1bit alpha channel of the texture based of an color key.
virtual void makeColorKeyTexture(video::ITexture* texture, video::SColor color) const; virtual void makeColorKeyTexture(video::ITexture* texture, video::SColor color) const;
...@@ -507,6 +508,10 @@ namespace video ...@@ -507,6 +508,10 @@ namespace video
virtual void setAllowZWriteOnTransparent(bool flag) virtual void setAllowZWriteOnTransparent(bool flag)
{ AllowZWriteOnTransparent=flag; } { AllowZWriteOnTransparent=flag; }
//! deprecated method
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size,
const c8* name=0);
protected: protected:
//! deletes all textures //! deletes all textures
......
...@@ -2548,7 +2548,7 @@ IGPUProgrammingServices* COpenGLDriver::getGPUProgrammingServices() ...@@ -2548,7 +2548,7 @@ IGPUProgrammingServices* COpenGLDriver::getGPUProgrammingServices()
} }
ITexture* COpenGLDriver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name) ITexture* COpenGLDriver::addRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name)
{ {
//disable mip-mapping //disable mip-mapping
bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
...@@ -2560,7 +2560,11 @@ ITexture* COpenGLDriver::createRenderTargetTexture(const core::dimension2d<s32>& ...@@ -2560,7 +2560,11 @@ ITexture* COpenGLDriver::createRenderTargetTexture(const core::dimension2d<s32>&
#if defined(GL_EXT_framebuffer_object) #if defined(GL_EXT_framebuffer_object)
// if driver supports FrameBufferObjects, use them // if driver supports FrameBufferObjects, use them
if (queryFeature(EVDF_FRAMEBUFFER_OBJECT)) if (queryFeature(EVDF_FRAMEBUFFER_OBJECT))
{
rtt = new COpenGLTexture(size, name, this); rtt = new COpenGLTexture(size, name, this);
addTexture(rtt);
rtt->drop();
}
else else
#endif #endif
{ {
......
...@@ -306,7 +306,8 @@ namespace video ...@@ -306,7 +306,8 @@ namespace video
//! call. //! call.
virtual u32 getMaximalPrimitiveCount() const; virtual u32 getMaximalPrimitiveCount() const;
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name); virtual ITexture* addRenderTargetTexture(const core::dimension2d<s32>& size,
const c8* name);
virtual bool setRenderTarget(video::ITexture* texture, bool clearBackBuffer, virtual bool setRenderTarget(video::ITexture* texture, bool clearBackBuffer,
bool clearZBuffer, SColor color); bool clearZBuffer, SColor color);
......
...@@ -880,12 +880,17 @@ const core::matrix4& CSoftwareDriver::getTransform(E_TRANSFORMATION_STATE state) ...@@ -880,12 +880,17 @@ const core::matrix4& CSoftwareDriver::getTransform(E_TRANSFORMATION_STATE state)
return TransformationMatrix[state]; return TransformationMatrix[state];
} }
//! Creates a render target texture. //! Creates a render target texture.
ITexture* CSoftwareDriver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name) ITexture* CSoftwareDriver::addRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name)
{ {
CImage* img = new CImage(video::ECF_A1R5G5B5, size); CImage* img = new CImage(video::ECF_A1R5G5B5, size);
if (!name)
name="rt";
ITexture* tex = new CSoftwareTexture(img, name, true); ITexture* tex = new CSoftwareTexture(img, name, true);
img->drop(); img->drop();
addTexture(tex);
tex->drop();
return tex; return tex;
} }
......
...@@ -97,7 +97,8 @@ namespace video ...@@ -97,7 +97,8 @@ namespace video
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const; virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
//! Creates a render target texture. //! Creates a render target texture.
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name); virtual ITexture* addRenderTargetTexture(const core::dimension2d<s32>& size,
const c8* name);
//! Clears the ZBuffer. //! Clears the ZBuffer.
virtual void clearZBuffer(); virtual void clearZBuffer();
......
...@@ -1845,12 +1845,16 @@ const core::matrix4& CBurningVideoDriver::getTransform(E_TRANSFORMATION_STATE st ...@@ -1845,12 +1845,16 @@ const core::matrix4& CBurningVideoDriver::getTransform(E_TRANSFORMATION_STATE st
//! Creates a render target texture. //! Creates a render target texture.
ITexture* CBurningVideoDriver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name) ITexture* CBurningVideoDriver::addRenderTargetTexture(const core::dimension2d<s32>& size,
const c8* name)
{ {
CImage* img = new CImage(BURNINGSHADER_COLOR_FORMAT, size); CImage* img = new CImage(BURNINGSHADER_COLOR_FORMAT, size);
if (!name)
name="rt";
ITexture* tex = new CSoftwareTexture2(img, name, false, true); ITexture* tex = new CSoftwareTexture2(img, name, false, true);
img->drop(); img->drop();
addTexture(tex);
tex->drop();
return tex; return tex;
} }
......
...@@ -113,7 +113,7 @@ namespace video ...@@ -113,7 +113,7 @@ namespace video
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const; virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
//! Creates a render target texture. //! Creates a render target texture.
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name); virtual ITexture* addRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name);
//! Clears the DepthBuffer. //! Clears the DepthBuffer.
virtual void clearZBuffer(); virtual void clearZBuffer();
......
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