Added ITexture::isRenderTarget and moved OGL render texture flip to the texture matrix.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@982 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
7566dbad65
commit
240c64cd4f
|
@ -1,5 +1,7 @@
|
|||
Changes in version 1.4 (... 2007)
|
||||
|
||||
- Added ITexture::isRenderTarget()
|
||||
|
||||
- Major API rewriting for proper const usage. Now, most getter methods are const and so are the larger parameters and return values. Moreover, mayn methods taking only unsigned numbers now use u32 instead of s32 to get his limitation from the method's signature.
|
||||
|
||||
- Added IMeshManipulator::createMeshWelded which creates a copy of the mesh with similar vertices welded together.
|
||||
|
|
|
@ -160,6 +160,10 @@ public:
|
|||
/** Useful after locking and modifying the texture */
|
||||
virtual void regenerateMipMapLevels() = 0;
|
||||
|
||||
//! Returns whether the texture is a render target
|
||||
/** \return Returns true if this is a render target, otherwise false. */
|
||||
virtual bool isRenderTarget() const { return false; }
|
||||
|
||||
//! Returns name of texture (in most cases this is the filename)
|
||||
const core::stringc& getName() const { return Name; }
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
virtual void regenerateMipMapLevels();
|
||||
|
||||
//! returns if it is a render target
|
||||
bool isRenderTarget() const;
|
||||
virtual bool isRenderTarget() const;
|
||||
|
||||
//! Returns pointer to the render target surface
|
||||
IDirect3DSurface8* getRenderTargetSurface();
|
||||
|
|
|
@ -912,7 +912,7 @@ void CD3D9Driver::draw2DImage(const video::ITexture* texture, const core::rect<s
|
|||
|
||||
setRenderStates2DMode(useColor[0].getAlpha()<255 || useColor[1].getAlpha()<255 || useColor[2].getAlpha()<255 || useColor[3].getAlpha()<255, true, useAlphaChannelOfTexture);
|
||||
|
||||
setTexture(0, texture);
|
||||
setTexture(0, const_cast<video::ITexture*>(texture));
|
||||
|
||||
setVertexShader(EVT_STANDARD);
|
||||
|
||||
|
@ -937,7 +937,7 @@ void CD3D9Driver::draw2DImage(const video::ITexture* texture,
|
|||
if (!sourceRect.isValid())
|
||||
return;
|
||||
|
||||
if (!setTexture(0, texture))
|
||||
if (!setTexture(0, const_cast<video::ITexture*>(texture)))
|
||||
return;
|
||||
|
||||
core::position2d<s32> targetPos = pos;
|
||||
|
|
|
@ -67,7 +67,7 @@ public:
|
|||
virtual void regenerateMipMapLevels();
|
||||
|
||||
//! returns if it is a render target
|
||||
bool isRenderTarget() const;
|
||||
virtual bool isRenderTarget() const;
|
||||
|
||||
//! Returns pointer to the render target surface
|
||||
IDirect3DSurface9* getRenderTargetSurface();
|
||||
|
|
|
@ -34,7 +34,7 @@ COpenGLDriver::COpenGLDriver(const core::dimension2d<s32>& screenSize, HWND wind
|
|||
: CNullDriver(io, screenSize), COpenGLExtensionHandler(),
|
||||
CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true),
|
||||
AntiAlias(antiAlias), RenderTargetTexture(0), LastSetLight(-1),
|
||||
CurrentRendertargetSize(0,0), ClockwiseWinding(true),
|
||||
CurrentRendertargetSize(0,0),
|
||||
HDc(0), Window(window), HRc(0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
|
@ -157,7 +157,7 @@ COpenGLDriver::COpenGLDriver(const core::dimension2d<s32>& screenSize, bool full
|
|||
: CNullDriver(io, screenSize), COpenGLExtensionHandler(),
|
||||
CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true),
|
||||
AntiAlias(antiAlias), RenderTargetTexture(0), LastSetLight(-1),
|
||||
CurrentRendertargetSize(0,0), ClockwiseWinding(true), _device(device)
|
||||
CurrentRendertargetSize(0,0), _device(device)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("COpenGLDriver");
|
||||
|
@ -176,8 +176,7 @@ COpenGLDriver::COpenGLDriver(const core::dimension2d<s32>& screenSize, bool full
|
|||
: CNullDriver(io, screenSize), COpenGLExtensionHandler(),
|
||||
CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
|
||||
Transformation3DChanged(true), AntiAlias(antiAlias),
|
||||
RenderTargetTexture(0), LastSetLight(-1), CurrentRendertargetSize(0,0),
|
||||
ClockwiseWinding(true)
|
||||
RenderTargetTexture(0), LastSetLight(-1), CurrentRendertargetSize(0,0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("COpenGLDriver");
|
||||
|
@ -212,8 +211,7 @@ COpenGLDriver::COpenGLDriver(const core::dimension2d<s32>& screenSize, bool full
|
|||
: CNullDriver(io, screenSize), COpenGLExtensionHandler(),
|
||||
CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
|
||||
Transformation3DChanged(true), AntiAlias(antiAlias),
|
||||
RenderTargetTexture(0), LastSetLight(-1), CurrentRendertargetSize(0,0),
|
||||
ClockwiseWinding(true)
|
||||
RenderTargetTexture(0), LastSetLight(-1), CurrentRendertargetSize(0,0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("COpenGLDriver");
|
||||
|
@ -464,25 +462,6 @@ void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matri
|
|||
createGLMatrix(glmat, mat);
|
||||
// flip z to compensate OpenGLs right-hand coordinate system
|
||||
glmat[12] *= -1.0f;
|
||||
// in render targets, flip the screen
|
||||
if ( CurrentRendertargetSize.Width != 0 )
|
||||
{
|
||||
glmat[5] *= -1.0f;
|
||||
// because we flipped the screen, triangles are the wrong way around
|
||||
if (ClockwiseWinding)
|
||||
{
|
||||
glFrontFace(GL_CCW);
|
||||
ClockwiseWinding = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ClockwiseWinding)
|
||||
{
|
||||
glFrontFace(GL_CW);
|
||||
ClockwiseWinding = true;
|
||||
}
|
||||
}
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(glmat);
|
||||
break;
|
||||
|
@ -490,18 +469,25 @@ void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matri
|
|||
case ETS_TEXTURE_1:
|
||||
case ETS_TEXTURE_2:
|
||||
case ETS_TEXTURE_3:
|
||||
{
|
||||
const u32 i = state - ETS_TEXTURE_0;
|
||||
const bool isRTT = (Material.Textures[i] && Material.Textures[i]->isRenderTarget());
|
||||
|
||||
if (MultiTextureExtension)
|
||||
extGlActiveTexture(GL_TEXTURE0_ARB + ( state - ETS_TEXTURE_0 ));
|
||||
extGlActiveTexture(GL_TEXTURE0_ARB + i);
|
||||
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
if (mat.isIdentity())
|
||||
if (mat.isIdentity() && !isRTT)
|
||||
glLoadIdentity();
|
||||
else
|
||||
{
|
||||
createGLTextureMatrix(glmat, mat );
|
||||
if (isRTT)
|
||||
glmat[5] *= -1;
|
||||
glLoadMatrixf(glmat);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1205,27 +1191,6 @@ void COpenGLDriver::setRenderStates3DMode()
|
|||
|
||||
createGLMatrix(glmat, Matrices[ETS_PROJECTION]);
|
||||
glmat[12] *= -1.0f;
|
||||
|
||||
// in render targets, flip the screen
|
||||
if ( CurrentRendertargetSize.Width > 0 )
|
||||
{
|
||||
glmat[5] *= -1.0f;
|
||||
// because we flipped the screen, triangles are the wrong way around
|
||||
if (ClockwiseWinding)
|
||||
{
|
||||
glFrontFace(GL_CCW);
|
||||
ClockwiseWinding = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ClockwiseWinding)
|
||||
{
|
||||
glFrontFace(GL_CW);
|
||||
ClockwiseWinding = true;
|
||||
}
|
||||
}
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(glmat);
|
||||
|
||||
|
@ -1532,27 +1497,6 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
|
|||
m.setTranslation(translation);
|
||||
|
||||
createGLMatrix(glmat, m);
|
||||
|
||||
// in render targets, flip the screen
|
||||
if ( CurrentRendertargetSize.Width != 0 )
|
||||
{
|
||||
glmat[5] *= -1.0f;
|
||||
// triangles are the wrong way around because we flipped the screen
|
||||
if (ClockwiseWinding)
|
||||
{
|
||||
glFrontFace(GL_CCW);
|
||||
ClockwiseWinding = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ClockwiseWinding)
|
||||
{
|
||||
glFrontFace(GL_CW);
|
||||
ClockwiseWinding = true;
|
||||
}
|
||||
}
|
||||
|
||||
glLoadMatrixf(glmat);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
@ -2165,9 +2109,12 @@ ITexture* COpenGLDriver::createRenderTargetTexture(const core::dimension2d<s32>&
|
|||
else
|
||||
#endif
|
||||
{
|
||||
rtt = addTexture(size, name);
|
||||
rtt = addTexture(size, name);
|
||||
if (rtt)
|
||||
{
|
||||
rtt->grab();
|
||||
static_cast<video::COpenGLTexture*>(rtt)->setRenderTarget(true);
|
||||
}
|
||||
}
|
||||
|
||||
//restore mip-mapping
|
||||
|
|
|
@ -347,9 +347,6 @@ namespace video
|
|||
core::array<bool> UserClipPlaneEnabled;
|
||||
|
||||
core::dimension2d<s32> CurrentRendertargetSize;
|
||||
//! bool to see if we are using clockwise or counter-clockwise winding,
|
||||
//! render targets use opposite winding as their projection matrix is flipped.
|
||||
bool ClockwiseWinding;
|
||||
|
||||
#ifdef _IRR_WINDOWS_API_
|
||||
HDC HDc; // Private GDI Device Context
|
||||
|
|
|
@ -27,7 +27,7 @@ static bool checkFBOStatus(COpenGLDriver* Driver);
|
|||
COpenGLTexture::COpenGLTexture(IImage* image, const char* name, COpenGLDriver* driver)
|
||||
: ITexture(name), Driver(driver), Image(0),
|
||||
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT),
|
||||
PixelType(GL_UNSIGNED_BYTE), HasMipMaps(true),
|
||||
PixelType(GL_UNSIGNED_BYTE), HasMipMaps(true), IsRenderTarget(false),
|
||||
ColorFrameBuffer(0), DepthRenderBuffer(0), StencilRenderBuffer(0), Locks(0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
|
@ -51,7 +51,7 @@ COpenGLTexture::COpenGLTexture(const core::dimension2d<s32>& size,
|
|||
COpenGLDriver* driver)
|
||||
: ITexture(name), ImageSize(size), Driver(driver), Image(0),
|
||||
TextureName(0), InternalFormat(GL_RGB8), PixelFormat(GL_RGBA),
|
||||
PixelType(GL_UNSIGNED_BYTE), HasMipMaps(false),
|
||||
PixelType(GL_UNSIGNED_BYTE), HasMipMaps(false), IsRenderTarget(true),
|
||||
ColorFrameBuffer(0), DepthRenderBuffer(0), StencilRenderBuffer(0), Locks(0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
|
@ -465,6 +465,16 @@ bool COpenGLTexture::isFrameBufferObject() const
|
|||
return ColorFrameBuffer != 0;
|
||||
}
|
||||
|
||||
bool COpenGLTexture::isRenderTarget() const
|
||||
{
|
||||
return IsRenderTarget;
|
||||
}
|
||||
|
||||
void COpenGLTexture::setRenderTarget(bool isTarget)
|
||||
{
|
||||
IsRenderTarget = isTarget;
|
||||
}
|
||||
|
||||
|
||||
//! Bind ColorFrameBuffer (valid only if isFrameBufferObject() returns true).
|
||||
void COpenGLTexture::bindFrameBufferObject()
|
||||
|
|
|
@ -86,6 +86,9 @@ public:
|
|||
//! locking and modifying the texture
|
||||
virtual void regenerateMipMapLevels();
|
||||
|
||||
//! Is it a render target?
|
||||
virtual bool isRenderTarget() const;
|
||||
|
||||
//! Is it a FrameBufferObject?
|
||||
bool isFrameBufferObject() const;
|
||||
|
||||
|
@ -95,6 +98,9 @@ public:
|
|||
//! Unbind FrameBufferObject (valid only if isFrameBufferObject() returns true).
|
||||
void unbindFrameBufferObject();
|
||||
|
||||
//! sets whether this texture is intended to be used as a render target.
|
||||
void setRenderTarget(bool isTarget);
|
||||
|
||||
private:
|
||||
|
||||
//! get the desired color format based on texture creation flags and the input format.
|
||||
|
@ -119,6 +125,7 @@ private:
|
|||
GLenum PixelFormat;
|
||||
GLenum PixelType;
|
||||
bool HasMipMaps;
|
||||
bool IsRenderTarget;
|
||||
bool AutomaticMipmapUpdate;
|
||||
|
||||
GLuint ColorFrameBuffer; // for FBO path
|
||||
|
|
|
@ -863,7 +863,7 @@ const core::matrix4& CSoftwareDriver::getTransform(E_TRANSFORMATION_STATE state)
|
|||
ITexture* CSoftwareDriver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name)
|
||||
{
|
||||
CImage* img = new CImage(video::ECF_A1R5G5B5, size);
|
||||
ITexture* tex = new CSoftwareTexture(img, name);
|
||||
ITexture* tex = new CSoftwareTexture(img, name, true);
|
||||
img->drop();
|
||||
return tex;
|
||||
}
|
||||
|
|
|
@ -1856,7 +1856,7 @@ ITexture* CSoftwareDriver2::createRenderTargetTexture(const core::dimension2d<s3
|
|||
{
|
||||
CImage* img = new CImage(ECF_SOFTWARE2, size);
|
||||
|
||||
ITexture* tex = new CSoftwareTexture2(img, name, false);
|
||||
ITexture* tex = new CSoftwareTexture2(img, name, false, true);
|
||||
img->drop();
|
||||
return tex;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ namespace video
|
|||
{
|
||||
|
||||
//! constructor
|
||||
CSoftwareTexture::CSoftwareTexture(IImage* image, const char* name)
|
||||
: ITexture(name), Texture(0)
|
||||
CSoftwareTexture::CSoftwareTexture(IImage* image, const char* name, bool renderTarget)
|
||||
: ITexture(name), Texture(0), IsRenderTarget(renderTarget)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CSoftwareTexture");
|
||||
|
@ -151,6 +151,11 @@ void CSoftwareTexture::regenerateMipMapLevels()
|
|||
// our software textures don't have mip maps
|
||||
}
|
||||
|
||||
bool CSoftwareTexture::isRenderTarget() const
|
||||
{
|
||||
return IsRenderTarget;
|
||||
}
|
||||
|
||||
|
||||
} // end namespace video
|
||||
} // end namespace irr
|
||||
|
|
|
@ -21,7 +21,7 @@ class CSoftwareTexture : public ITexture
|
|||
public:
|
||||
|
||||
//! constructor
|
||||
CSoftwareTexture(IImage* surface, const char* name);
|
||||
CSoftwareTexture(IImage* surface, const char* name, bool renderTarget=false);
|
||||
|
||||
//! destructor
|
||||
virtual ~CSoftwareTexture();
|
||||
|
@ -57,6 +57,9 @@ public:
|
|||
//! modifying the texture
|
||||
virtual void regenerateMipMapLevels();
|
||||
|
||||
//! is it a render target?
|
||||
virtual bool isRenderTarget() const;
|
||||
|
||||
private:
|
||||
|
||||
//! returns the size of a texture which would be the optimize size for rendering it
|
||||
|
@ -65,6 +68,7 @@ private:
|
|||
CImage* Image;
|
||||
CImage* Texture;
|
||||
core::dimension2d<s32> OrigSize;
|
||||
bool IsRenderTarget;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ namespace video
|
|||
{
|
||||
|
||||
//! constructor
|
||||
CSoftwareTexture2::CSoftwareTexture2(IImage* image, const char* name, bool generateMipLevels)
|
||||
: ITexture(name), MipMapLOD(0), HasMipMaps(generateMipLevels)
|
||||
CSoftwareTexture2::CSoftwareTexture2(IImage* image, const char* name, bool generateMipLevels, bool isRenderTarget)
|
||||
: ITexture(name), MipMapLOD(0), HasMipMaps(generateMipLevels), IsRenderTarget(isRenderTarget)
|
||||
{
|
||||
#ifndef SOFTWARE_DRIVER_2_MIPMAPPING
|
||||
HasMipMaps = false;
|
||||
|
|
|
@ -23,7 +23,7 @@ class CSoftwareTexture2 : public ITexture
|
|||
public:
|
||||
|
||||
//! constructor
|
||||
CSoftwareTexture2(IImage* surface, const char* name,bool generateMipLevels);
|
||||
CSoftwareTexture2(IImage* surface, const char* name, bool generateMipLevels, bool isRenderTarget=false);
|
||||
|
||||
//! destructor
|
||||
virtual ~CSoftwareTexture2();
|
||||
|
@ -107,6 +107,12 @@ public:
|
|||
return HasMipMaps;
|
||||
}
|
||||
|
||||
//! is a render target
|
||||
virtual bool isRenderTarget() const
|
||||
{
|
||||
return IsRenderTarget;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//! returns the size of a texture which would be the optimize size for rendering it
|
||||
|
@ -117,7 +123,7 @@ private:
|
|||
CImage * MipMap[SOFTWARE_DRIVER_2_MIPMAPPING_MAX];
|
||||
|
||||
s32 MipMapLOD;
|
||||
bool HasMipMaps;
|
||||
bool HasMipMaps, IsRenderTarget;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue