2019-12-12 17:32:41 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#include "IrrCompileConfig.h"
|
|
|
|
#include "SoftwareDriver2_compile_config.h"
|
|
|
|
#include "CDepthBuffer.h"
|
|
|
|
|
|
|
|
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace video
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CDepthBuffer::CDepthBuffer(const core::dimension2d<u32>& size)
|
|
|
|
: Buffer(0), Size(0,0)
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
setDebugName("CDepthBuffer");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
setSize(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
CDepthBuffer::~CDepthBuffer()
|
|
|
|
{
|
2020-02-22 21:48:12 +01:00
|
|
|
if (Buffer)
|
|
|
|
{
|
|
|
|
delete[] Buffer;
|
|
|
|
Buffer = 0;
|
|
|
|
}
|
2019-12-12 17:32:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! clears the zbuffer
|
2020-02-22 21:48:12 +01:00
|
|
|
void CDepthBuffer::clear(f32 value)
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
2020-02-22 21:48:12 +01:00
|
|
|
ieee754 zMaxValue;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
#ifdef SOFTWARE_DRIVER_2_USE_WBUFFER
|
2020-02-22 21:48:12 +01:00
|
|
|
zMaxValue.f = 1.f-value;
|
2019-12-12 17:32:41 +01:00
|
|
|
#else
|
2020-02-22 21:48:12 +01:00
|
|
|
zMaxValue.f = value;
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
memset32 ( Buffer, zMaxValue.u, TotalSize );
|
2019-12-12 17:32:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
//! sets the new size of the buffer
|
2019-12-12 17:32:41 +01:00
|
|
|
void CDepthBuffer::setSize(const core::dimension2d<u32>& size)
|
|
|
|
{
|
|
|
|
if (size == Size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Size = size;
|
|
|
|
|
|
|
|
delete [] Buffer;
|
|
|
|
|
|
|
|
Pitch = size.Width * sizeof ( fp24 );
|
|
|
|
TotalSize = Pitch * size.Height;
|
2020-02-22 21:48:12 +01:00
|
|
|
Buffer = new u8[align_next(TotalSize,16)];
|
2019-12-12 17:32:41 +01:00
|
|
|
clear ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
//! returns the size of the buffer
|
2019-12-12 17:32:41 +01:00
|
|
|
const core::dimension2d<u32>& CDepthBuffer::getSize() const
|
|
|
|
{
|
|
|
|
return Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------
|
|
|
|
|
|
|
|
//! constructor
|
2020-02-22 21:48:12 +01:00
|
|
|
CStencilBuffer::CStencilBuffer(const core::dimension2d<u32>& size, unsigned bit)
|
|
|
|
: Buffer(0), Size(0,0),Bit(bit)
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
2020-02-22 21:48:12 +01:00
|
|
|
setDebugName("CStencilBuffer");
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
setSize(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
CStencilBuffer::~CStencilBuffer()
|
|
|
|
{
|
2020-02-22 21:48:12 +01:00
|
|
|
if (Buffer)
|
|
|
|
{
|
|
|
|
delete[] Buffer;
|
|
|
|
Buffer = 0;
|
|
|
|
}
|
2019-12-12 17:32:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
//! clears the buffer
|
|
|
|
void CStencilBuffer::clear(u8 value)
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
2020-02-22 21:48:12 +01:00
|
|
|
u32 set = value;
|
|
|
|
if (Bit == 8)
|
|
|
|
{
|
|
|
|
set |= set << 8;
|
|
|
|
set |= set << 16;
|
|
|
|
}
|
|
|
|
memset32 ( Buffer, set, TotalSize );
|
2019-12-12 17:32:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
//! sets the new size of the buffer
|
2019-12-12 17:32:41 +01:00
|
|
|
void CStencilBuffer::setSize(const core::dimension2d<u32>& size)
|
|
|
|
{
|
|
|
|
if (size == Size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Size = size;
|
|
|
|
|
|
|
|
delete [] Buffer;
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
Pitch = size.Width * sizeof (tStencilSample);
|
2019-12-12 17:32:41 +01:00
|
|
|
TotalSize = Pitch * size.Height;
|
2020-02-22 21:48:12 +01:00
|
|
|
Buffer = new u8[align_next(TotalSize,16)];
|
2019-12-12 17:32:41 +01:00
|
|
|
clear ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
//! returns the size of the buffer
|
2019-12-12 17:32:41 +01:00
|
|
|
const core::dimension2d<u32>& CStencilBuffer::getSize() const
|
|
|
|
{
|
|
|
|
return Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace video
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
#endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace video
|
|
|
|
{
|
|
|
|
|
|
|
|
//! creates a ZBuffer
|
|
|
|
IDepthBuffer* createDepthBuffer(const core::dimension2d<u32>& size)
|
|
|
|
{
|
|
|
|
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
|
|
|
|
return new CDepthBuffer(size);
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
//! creates a Stencil Buffer
|
|
|
|
IStencilBuffer* createStencilBuffer(const core::dimension2d<u32>& size, u32 bit)
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
|
2020-02-22 21:48:12 +01:00
|
|
|
return new CStencilBuffer(size,bit);
|
2019-12-12 17:32:41 +01:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace video
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
|
|
|
|
|