I add 6 new color format:
Code: Select all
ECF_R16F
ECF_G16R16F
ECF_A16B16G16R16F
ECF_R32F
ECF_G32R32F
ECF_A32B32G32R32F
Code: Select all
*** Irrlicht Include ***
---------------------------------------- IImage.h ----------------------------------------
enum ECOLOR_FORMAT
{
//! 16 bit color format used by the software driver, and thus preferred
//! by all other irrlicht engine video drivers. There are 5 bits for every
//! color component, and a single bit is left for alpha information.
ECF_A1R5G5B5 = 0,
//! Standard 16 bit color format.
ECF_R5G6B5,
//! 24 bit color, no alpha channel, but 8 bit for red, green and blue.
ECF_R8G8B8,
//! Default 32 bit color format. 8 bits are used for every component:
//! red, green, blue and alpha.
ECF_A8R8G8B8,
// ** Floating Point ***
//! 16 bit float format using. 16 bits for red:
ECF_R16F,
//! 32 bit float format using. 16 bits for red and 16 bits for green:
ECF_G16R16F,
//! 64 bit float format. 16 bits are used for every component:
//! red, green, blue and alpha.
ECF_A16B16G16R16F,
//! 32 bit float format using. 32 bits for red:
ECF_R32F,
//! 64 bit float format using. 32 bits for red and 32 bits for green:
ECF_G32R32F,
//! 128 bit float format. 32 bits are used for every component:
//! red, green, blue and alpha.
ECF_A32B32G32R32F,
//! Unknown color format:
ECF_UNKNOWN,
};
------------------------------------------------------------------------------------------
********************************************************************
------------------------------------- IVideoDriver.h -------------------------------------
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name = 0, ECOLOR_FORMAT format = ECF_UNKNOWN) = 0;
------------------------------------------------------------------------------------------
********************************************************************
*** Irrlicht Source ***
------------------------------------- CNullDriver.h -------------------------------------
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name = 0, ECOLOR_FORMAT format = ECF_UNKNOWN);
------------------------------------------------------------------------------------------
********************************************************************
------------------------------------ CNullDriver.cpp ------------------------------------
ITexture* CNullDriver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name, ECOLOR_FORMAT format)
{
return 0;
}
------------------------------------------------------------------------------------------
********************************************************************
------------------------------------ CD3D9Driver.h ------------------------------------
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name = 0, ECOLOR_FORMAT format = ECF_UNKNOWN);
------------------------------------------------------------------------------------------
********************************************************************
----------------------------------- CD3D9Driver.cpp -----------------------------------
ITexture* CD3D9Driver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name, ECOLOR_FORMAT format)
{
return new CD3D9Texture(this, size, name, format);
}
------------------------------------------------------------------------------------------
********************************************************************
------------------------------------ CD3D9Texture.h -----------------------------------
//! rendertarget constructor
CD3D9Texture(CD3D9Driver* driver, core::dimension2d<s32> size, const char* name, ECOLOR_FORMAT format = ECF_UNKNOWN);
------------------------------------------------------------------------------------------
void createRenderTarget(ECOLOR_FORMAT format);
------------------------------------------------------------------------------------------
********************************************************************
----------------------------------- CD3D9Texture.cpp ----------------------------------
//! rendertarget constructor
CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, core::dimension2d<s32> size, const char* name, ECOLOR_FORMAT format)
: ITexture(name), Texture(0), RTTSurface(0), Driver(driver),
TextureSize(size), ImageSize(size), Pitch(0),
HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(true)
{
#ifdef _DEBUG
setDebugName("CD3D9Texture");
#endif
Device=driver->getExposedVideoData().D3D9.D3DDev9;
if (Device)
Device->AddRef();
createRenderTarget( format );
}
------------------------------------------------------------------------------------------
void CD3D9Texture::createRenderTarget(video::ECOLOR_FORMAT format)
{
TextureSize.Width = getTextureSizeFromImageSize(TextureSize.Width);
TextureSize.Height = getTextureSizeFromImageSize(TextureSize.Height);
D3DFORMAT d3DFormat = D3DFMT_A8R8G8B8;
if( format == ECF_UNKNOWN )
{
// get backbuffer format to create the render target in the
// same format
IDirect3DSurface9* bb;
if (!FAILED(Device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &bb)))
{
D3DSURFACE_DESC desc;
bb->GetDesc(&desc);
d3DFormat = desc.Format;
if (d3DFormat == D3DFMT_X8R8G8B8)
d3DFormat = D3DFMT_A8R8G8B8;
bb->Release();
}
else
{
os::Printer::log("Could not create RenderTarget texture: could not get BackBuffer.",
ELL_WARNING);
return;
}
}
else
{
d3DFormat = getD3DFormatFromColorFormat( format );
}
if( d3DFormat != D3DFMT_UNKNOWN )
{
// create texture
HRESULT hr;
hr = Device->CreateTexture(
TextureSize.Width,
TextureSize.Height,
1, // mip map level count, we don't want mipmaps here
D3DUSAGE_RENDERTARGET,
d3DFormat,
D3DPOOL_DEFAULT,
&Texture,
NULL);
// get irrlicht format from D3D format
ColorFormat = getColorFormatFromD3DFormat(d3DFormat);
if (FAILED(hr))
os::Printer::log("Could not create render target texture");
}
else
{
os::Printer::log( "Can not create render target of format D3DFMT_UNKNOWN" );
}
}
------------------------------------------------------------------------------------------
D3DFORMAT CD3D9Texture::getD3DFormatFromColorFormat(ECOLOR_FORMAT format) const
{
switch(format)
{
case ECF_A1R5G5B5:
return D3DFMT_A1R5G5B5;
case ECF_R5G6B5:
return D3DFMT_R5G6B5;
case ECF_R8G8B8:
return D3DFMT_R8G8B8;
case ECF_A8R8G8B8:
return D3DFMT_A8R8G8B8;
// ** Floating Point ***
case ECF_R16F:
return D3DFMT_R16F;
case ECF_G16R16F:
return D3DFMT_G16R16F;
case ECF_A16B16G16R16F:
return D3DFMT_A16B16G16R16F;
case ECF_R32F:
return D3DFMT_R32F;
case ECF_G32R32F:
return D3DFMT_G32R32F;
case ECF_A32B32G32R32F:
return D3DFMT_A32B32G32R32F;
}
return D3DFMT_UNKNOWN;
}
------------------------------------------------------------------------------------------
********************************************************************
Simple usage:
Code: Select all
ITexture* rt = driver->createRenderTargetTexture(core::dimension2d<s32>(256,256),0,video::ECF_A16B16G16R16F);