CZBuffer.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #include "IrrCompileConfig.h"
  5. #include "CZBuffer.h"
  6. #include "irrString.h"
  7. #ifdef _IRR_COMPILE_WITH_SOFTWARE_
  8. namespace irr
  9. {
  10. namespace video
  11. {
  12. //! constructor
  13. CZBuffer::CZBuffer(const core::dimension2d<u32>& size)
  14. : Buffer(0), BufferEnd(0), Size(0,0), TotalSize(0)
  15. {
  16. #ifdef _DEBUG
  17. setDebugName("CZBuffer");
  18. #endif
  19. setSize(size);
  20. }
  21. //! destructor
  22. CZBuffer::~CZBuffer()
  23. {
  24. delete [] Buffer;
  25. }
  26. //! clears the zbuffer
  27. void CZBuffer::clear()
  28. {
  29. memset(Buffer, 0, (BufferEnd-Buffer)*sizeof(TZBufferType));
  30. }
  31. //! sets the new size of the zbuffer
  32. void CZBuffer::setSize(const core::dimension2d<u32>& size)
  33. {
  34. if (size == Size)
  35. return;
  36. Size = size;
  37. delete [] Buffer;
  38. TotalSize = size.Width * size.Height;
  39. Buffer = new TZBufferType[TotalSize];
  40. BufferEnd = Buffer + TotalSize;
  41. }
  42. //! returns the size of the zbuffer
  43. const core::dimension2d<u32>& CZBuffer::getSize() const
  44. {
  45. return Size;
  46. }
  47. //! locks the zbuffer
  48. TZBufferType* CZBuffer::lock()
  49. {
  50. return Buffer;
  51. }
  52. //! unlocks the zbuffer
  53. void CZBuffer::unlock()
  54. {
  55. }
  56. } // end namespace video
  57. } // end namespace irr
  58. #endif // _IRR_COMPILE_WITH_SOFTWARE_
  59. namespace irr
  60. {
  61. namespace video
  62. {
  63. //! creates a ZBuffer
  64. IZBuffer* createZBuffer(const core::dimension2d<u32>& size)
  65. {
  66. #ifdef _IRR_COMPILE_WITH_SOFTWARE_
  67. return new CZBuffer(size);
  68. #else
  69. return 0;
  70. #endif // _IRR_COMPILE_WITH_SOFTWARE_
  71. }
  72. } // end namespace video
  73. } // end namespace irr