| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #include "CmPixelData.h"
- #include "CmPixelUtil.h"
- #include "CmPixelDataRTTI.h"
- #include "CmColor.h"
- namespace BansheeEngine
- {
- PixelData::PixelData(const PixelData& copy)
- :GpuResourceData(copy)
- {
- mFormat = copy.mFormat;
- mRowPitch = copy.mRowPitch;
- mSlicePitch = copy.mSlicePitch;
- mExtents = copy.mExtents;
- }
- PixelData& PixelData::operator=(const PixelData& rhs)
- {
- GpuResourceData::operator= (rhs);
- mFormat = rhs.mFormat;
- mRowPitch = rhs.mRowPitch;
- mSlicePitch = rhs.mSlicePitch;
- mExtents = rhs.mExtents;
- return *this;
- }
- UINT32 PixelData::getConsecutiveSize() const
- {
- return PixelUtil::getMemorySize(getWidth(), getHeight(), getDepth(), mFormat);
- }
- PixelData PixelData::getSubVolume(const PixelVolume &def) const
- {
- if (PixelUtil::isCompressed(mFormat))
- {
- if (def.left == getLeft() && def.top == getTop() && def.front == getFront() &&
- def.right == getRight() && def.bottom == getBottom() && def.back == getBack())
- {
- // Entire buffer is being queried
- return *this;
- }
- CM_EXCEPT(InvalidParametersException, "Cannot return subvolume of compressed PixelBuffer");
- }
- if (!mExtents.contains(def))
- {
- CM_EXCEPT(InvalidParametersException, "Bounds out of range");
- }
- const size_t elemSize = PixelUtil::getNumElemBytes(mFormat);
- PixelData rval(def.getWidth(), def.getHeight(), def.getDepth(), mFormat);
- rval.setExternalBuffer(((UINT8*)getData()) + ((def.left - getLeft())*elemSize)
- + ((def.top - getTop())*mRowPitch*elemSize)
- + ((def.front - getFront())*mSlicePitch*elemSize));
- rval.mRowPitch = mRowPitch;
- rval.mSlicePitch = mSlicePitch;
- rval.mFormat = mFormat;
- return rval;
- }
- Color PixelData::getColorAt(UINT32 x, UINT32 y, UINT32 z)
- {
- Color cv;
- UINT32 pixelSize = PixelUtil::getNumElemBytes(mFormat);
- UINT32 pixelOffset = pixelSize * (z * mSlicePitch + y * mRowPitch + x);
- PixelUtil::unpackColour(&cv, mFormat, (unsigned char *)getData() + pixelOffset);
- return cv;
- }
- void PixelData::setColorAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z)
- {
- UINT32 pixelSize = PixelUtil::getNumElemBytes(mFormat);
- UINT32 pixelOffset = pixelSize * (z * mSlicePitch + y * mRowPitch + x);
- PixelUtil::packColour(cv, mFormat, (unsigned char *)getData() + pixelOffset);
- }
- UINT32 PixelData::getInternalBufferSize()
- {
- return PixelUtil::getMemorySize(getWidth(), getHeight(), getDepth(), getFormat());
- }
- /************************************************************************/
- /* SERIALIZATION */
- /************************************************************************/
- RTTITypeBase* PixelData::getRTTIStatic()
- {
- return PixelDataRTTI::instance();
- }
- RTTITypeBase* PixelData::getRTTI() const
- {
- return PixelData::getRTTIStatic();
- }
- }
|