CmPixelBuffer.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #include "CmPixelBuffer.h"
  25. #include "CmException.h"
  26. namespace CamelotFramework
  27. {
  28. PixelBuffer::PixelBuffer(UINT32 width, UINT32 height, UINT32 depth,
  29. PixelFormat format,
  30. GpuBufferUsage usage, bool useSystemMemory):
  31. HardwareBuffer(usage, useSystemMemory),
  32. mWidth(width), mHeight(height), mDepth(depth),
  33. mFormat(format)
  34. {
  35. // Default
  36. mRowPitch = mWidth;
  37. mSlicePitch = mHeight*mWidth;
  38. mSizeInBytes = mHeight*mWidth*PixelUtil::getNumElemBytes(mFormat);
  39. }
  40. PixelBuffer::~PixelBuffer()
  41. {
  42. }
  43. void* PixelBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
  44. {
  45. assert(!isLocked() && "Cannot lock this buffer, it is already locked!");
  46. assert(offset == 0 && length == mSizeInBytes && "Cannot lock memory region, most lock box or entire buffer");
  47. Box myBox(0, 0, 0, mWidth, mHeight, mDepth);
  48. const PixelData &rv = lock(myBox, options);
  49. return rv.getData();
  50. }
  51. const PixelData& PixelBuffer::lock(const Box& lockBox, GpuLockOptions options)
  52. {
  53. // Lock the real buffer if there is no shadow buffer
  54. mCurrentLock = lockImpl(lockBox, options);
  55. mIsLocked = true;
  56. return mCurrentLock;
  57. }
  58. const PixelData& PixelBuffer::getCurrentLock()
  59. {
  60. assert(isLocked() && "Cannot get current lock: buffer not locked");
  61. return mCurrentLock;
  62. }
  63. void* PixelBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
  64. {
  65. CM_EXCEPT(InternalErrorException, "lockImpl(offset,length) is not valid for PixelBuffers and should never be called");
  66. }
  67. void PixelBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
  68. {
  69. // TODO
  70. CM_EXCEPT(NotImplementedException,
  71. "Reading a byte range is not implemented. Use blitToMemory.");
  72. }
  73. void PixelBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource,
  74. bool discardWholeBuffer)
  75. {
  76. // TODO
  77. CM_EXCEPT(NotImplementedException,
  78. "Writing a byte range is not implemented. Use blitFromMemory.");
  79. }
  80. }