irr: Add stencil patch

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@13003 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
curaga 2013-06-28 12:09:21 +00:00
parent f2cca4e5e8
commit 56177bdc93
8 changed files with 29 additions and 13 deletions

View File

@ -1,3 +1,4 @@
The following changes have been made: The following changes have been made:
- config changes in IrrCompileConfig.h - config changes in IrrCompileConfig.h
- primary sort by material type - primary sort by material type
- stencil RTT support

View File

@ -435,11 +435,13 @@ namespace video
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.
\param format The color format of the render target. Floating point formats are supported. \param format The color format of the render target. Floating point formats are supported.
\param useStencil Whether to enable stencil for this RTT. Default false.
\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. This pointer should not be dropped. See could not be created. This pointer should not be dropped. See
IReferenceCounted::drop() for more information. */ IReferenceCounted::drop() for more information. */
virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size, virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
const io::path& name = "rt", const ECOLOR_FORMAT format = ECF_UNKNOWN) =0; const io::path& name = "rt", const ECOLOR_FORMAT format = ECF_UNKNOWN,
const bool useStencil = false) =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!

View File

@ -2315,7 +2315,8 @@ s32 CNullDriver::addShaderMaterialFromFiles(const io::path& vertexShaderProgramF
//! Creates a render target texture. //! Creates a render target texture.
ITexture* CNullDriver::addRenderTargetTexture(const core::dimension2d<u32>& size, ITexture* CNullDriver::addRenderTargetTexture(const core::dimension2d<u32>& size,
const io::path&name, const ECOLOR_FORMAT format) const io::path&name, const ECOLOR_FORMAT format,
const bool useStencil)
{ {
return 0; return 0;
} }

View File

@ -315,7 +315,8 @@ namespace video
//! Creates a render target texture. //! Creates a render target texture.
virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size, virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN); const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN,
const bool useStencil = false);
//! 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, bool zeroTexels) const; virtual void makeColorKeyTexture(video::ITexture* texture, video::SColor color, bool zeroTexels) const;

View File

@ -8,7 +8,6 @@
#ifdef _IRR_COMPILE_WITH_OPENGL_ #ifdef _IRR_COMPILE_WITH_OPENGL_
#include "COpenGLTexture.h"
#include "COpenGLMaterialRenderer.h" #include "COpenGLMaterialRenderer.h"
#include "COpenGLShaderMaterialRenderer.h" #include "COpenGLShaderMaterialRenderer.h"
#include "COpenGLSLMaterialRenderer.h" #include "COpenGLSLMaterialRenderer.h"
@ -3994,7 +3993,8 @@ IVideoDriver* COpenGLDriver::getVideoDriver()
ITexture* COpenGLDriver::addRenderTargetTexture(const core::dimension2d<u32>& size, ITexture* COpenGLDriver::addRenderTargetTexture(const core::dimension2d<u32>& size,
const io::path& name, const io::path& name,
const ECOLOR_FORMAT format) const ECOLOR_FORMAT format,
const bool useStencil)
{ {
//disable mip-mapping //disable mip-mapping
bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
@ -4010,7 +4010,7 @@ ITexture* COpenGLDriver::addRenderTargetTexture(const core::dimension2d<u32>& si
{ {
bool success = false; bool success = false;
addTexture(rtt); addTexture(rtt);
ITexture* tex = createDepthTexture(rtt); ITexture* tex = createDepthTexture(rtt, useStencil);
if (tex) if (tex)
{ {
success = static_cast<video::COpenGLFBODepthTexture*>(tex)->attach(rtt); success = static_cast<video::COpenGLFBODepthTexture*>(tex)->attach(rtt);
@ -4566,7 +4566,7 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE
//! get depth texture for the given render target texture //! get depth texture for the given render target texture
ITexture* COpenGLDriver::createDepthTexture(ITexture* texture, bool shared) ITexture* COpenGLDriver::createDepthTexture(ITexture* texture, const bool useStencil, const bool shared)
{ {
if ((texture->getDriverType() != EDT_OPENGL) || (!texture->isRenderTarget())) if ((texture->getDriverType() != EDT_OPENGL) || (!texture->isRenderTarget()))
return 0; return 0;
@ -4579,16 +4579,17 @@ ITexture* COpenGLDriver::createDepthTexture(ITexture* texture, bool shared)
{ {
for (u32 i=0; i<DepthTextures.size(); ++i) for (u32 i=0; i<DepthTextures.size(); ++i)
{ {
if (DepthTextures[i]->getSize()==texture->getSize()) if (DepthTextures[i]->getSize()==texture->getSize() &&
useStencil == DepthTextures[i]->hasStencil())
{ {
DepthTextures[i]->grab(); DepthTextures[i]->grab();
return DepthTextures[i]; return DepthTextures[i];
} }
} }
DepthTextures.push_back(new COpenGLFBODepthTexture(texture->getSize(), "depth1", this)); DepthTextures.push_back(new COpenGLFBODepthTexture(texture->getSize(), "depth1", this, useStencil));
return DepthTextures.getLast(); return DepthTextures.getLast();
} }
return (new COpenGLFBODepthTexture(texture->getSize(), "depth1", this)); return (new COpenGLFBODepthTexture(texture->getSize(), "depth1", this, useStencil));
} }

View File

@ -23,6 +23,7 @@ namespace irr
#include "IMaterialRendererServices.h" #include "IMaterialRendererServices.h"
// also includes the OpenGL stuff // also includes the OpenGL stuff
#include "COpenGLExtensionHandler.h" #include "COpenGLExtensionHandler.h"
#include "COpenGLTexture.h"
#ifdef _IRR_COMPILE_WITH_CG_ #ifdef _IRR_COMPILE_WITH_CG_
#include "Cg/cg.h" #include "Cg/cg.h"
@ -344,7 +345,8 @@ namespace video
virtual u32 getMaximalPrimitiveCount() const; virtual u32 getMaximalPrimitiveCount() const;
virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size, virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN); const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN,
const bool useStencil = false);
//! set or reset render target //! set or reset render target
virtual bool setRenderTarget(video::E_RENDER_TARGET target, bool clearTarget, virtual bool setRenderTarget(video::E_RENDER_TARGET target, bool clearTarget,
@ -390,7 +392,8 @@ namespace video
//! Returns the maximum texture size supported. //! Returns the maximum texture size supported.
virtual core::dimension2du getMaxTextureSize() const; virtual core::dimension2du getMaxTextureSize() const;
ITexture* createDepthTexture(ITexture* texture, bool shared=true); ITexture* createDepthTexture(ITexture* texture, const bool useStencil = false,
const bool shared = true);
void removeDepthTexture(ITexture* texture); void removeDepthTexture(ITexture* texture);
//! Removes a texture from the texture cache and deletes it, freeing lot of memory. //! Removes a texture from the texture cache and deletes it, freeing lot of memory.
@ -543,7 +546,7 @@ namespace video
} }
}; };
STextureStageCache CurrentTexture; STextureStageCache CurrentTexture;
core::array<ITexture*> DepthTextures; core::array<COpenGLFBODepthTexture*> DepthTextures;
struct SUserClipPlane struct SUserClipPlane
{ {
SUserClipPlane() : Enabled(false) {} SUserClipPlane() : Enabled(false) {}

View File

@ -893,6 +893,11 @@ void COpenGLFBODepthTexture::unbindRTT()
{ {
} }
bool COpenGLFBODepthTexture::hasStencil()
{
return UseStencil;
}
bool checkFBOStatus(COpenGLDriver* Driver) bool checkFBOStatus(COpenGLDriver* Driver)
{ {

View File

@ -190,6 +190,8 @@ public:
bool attach(ITexture*); bool attach(ITexture*);
bool hasStencil();
protected: protected:
GLuint DepthRenderBuffer; GLuint DepthRenderBuffer;
GLuint StencilRenderBuffer; GLuint StencilRenderBuffer;