39#include <OgreBitwise.h>
43SBitmapWidget::SBitmapWidget(
SScene* targetScene,
const std::string& bitmapWidgetName,
const int& xPos,
const int& yPos,
const unsigned short& widgetWidth,
const unsigned short& widgetHeight,
SViewPort* targetViewport,
const unsigned int& widgetZOrder) :
SWidget(targetScene, bitmapWidgetName, xPos, yPos, widgetWidth, widgetHeight, targetViewport, widgetZOrder, SO3_BITMAP_WIDGET_TYPE)
48SBitmapWidget::SBitmapWidget(
SScene* targetScene,
const std::string& bitmapWidgetName,
const int& xPos,
const int& yPos,
const unsigned short& widgetWidth,
const unsigned short& widgetHeight,
SViewPort* targetViewport) :
SWidget(targetScene, bitmapWidgetName, xPos, yPos, widgetWidth, widgetHeight, targetViewport, SO3_BITMAP_WIDGET_TYPE)
53SBitmapWidget::SBitmapWidget(
SScene* targetScene,
const std::string& bitmapWidgetName,
const unsigned short& widgetWidth,
const unsigned short& widgetHeight,
SMaterial* targetMaterial,
const unsigned short& targetTechnique,
const unsigned short& targetPass,
const unsigned short& targetTextureUnit) :
SWidget(targetScene, bitmapWidgetName, widgetWidth, widgetHeight, targetMaterial, targetTechnique, targetPass, targetTextureUnit, SO3_BITMAP_WIDGET_TYPE)
63 bLastAlphaState =
false;
69 SAFE_FREE(pixelsData);
76 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED,
"Cannot directly load an URL in a Bitmap widget, use \"UpdateRawData\" function!",
"SBitmapWidget::LoadURL");
83 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED,
"Cannot load a file directly in a Bitmap widget, use \"UpdateRawData\" function!",
"SBitmapWidget::LoadFile");
95 CheckSizeAndAlloc(
width,
height, (bitperpixel == 4) ?
true :
false);
99 MMechostr(MSKDEBUG,
">>>> SBitmapWidget : Texture creation failed.");
104 Ogre::HardwarePixelBufferSharedPtr pixelBuffer =
renderingTexture->getBuffer();
108 int align =
width * bitperpixel;
113 if ((pixelBuffer->getWidth() ==
width) && ((pixelBuffer->getHeight() ==
height)))
115 memcpy(pixelsData, buffer,
width *
height * bitperpixel);
123 const Ogre::PixelBox scolPixelBox(
width,
height, 1, (bitperpixel == 4) ? Ogre::PF_BYTE_BGRA : Ogre::PF_BYTE_BGR, pixelsData);
124 pixelBuffer->blitFromMemory(scolPixelBox);
129 const Ogre::PixelBox scolPixelBox(
width,
height, 1, (bitperpixel == 4) ? Ogre::PF_BYTE_BGRA : Ogre::PF_BYTE_BGR, buffer);
134 const Ogre::PixelBox scolPixelBox(pixelBuffer->getWidth(), pixelBuffer->getHeight(), 1, pixelBuffer->getFormat(), pixelsData);
136 pixelBuffer->blitFromMemory(scolPixelBox);
146 if((scolBitmap->TailleW > 0) && (scolBitmap->TailleH > 0))
148 CheckSizeAndAlloc(scolBitmap->TailleW, scolBitmap->TailleH,
false);
152 MMechostr(MSKDEBUG,
">>>> SBitmapWidget : Texture creation failed.");
157 Ogre::HardwarePixelBufferSharedPtr pixelBuffer =
renderingTexture->getBuffer();
162 ConversionTools::ScolBitmapGetRGBA(scolBitmap, 0, pixelBuffer->getWidth(), pixelBuffer->getHeight(), pixelBuffer->getFormat(),
static_cast<Ogre::uint32*
>(pixelsData));
165 const Ogre::PixelBox scolPixelBox(pixelBuffer->getWidth(), pixelBuffer->getHeight(), 1, pixelBuffer->getFormat(), pixelsData);
166 pixelBuffer->blitFromMemory(scolPixelBox);
174 if (scolAlphaBitmap == 0)
181 if((scolBitmap->TailleW > 0) && (scolBitmap->TailleH > 0))
183 CheckSizeAndAlloc(scolBitmap->TailleW, scolBitmap->TailleH,
true);
187 MMechostr(MSKDEBUG,
">>>> SBitmapWidget : Texture creation failed.");
192 Ogre::HardwarePixelBufferSharedPtr pixelBuffer =
renderingTexture->getBuffer();
197 ConversionTools::ScolBitmapGetRGBA(scolBitmap, scolAlphaBitmap, pixelBuffer->getWidth(), pixelBuffer->getHeight(), pixelBuffer->getFormat(),
static_cast<Ogre::uint32*
>(pixelsData));
199 const Ogre::PixelBox scolPixelBox(pixelBuffer->getWidth(), pixelBuffer->getHeight(), 1, pixelBuffer->getFormat(), pixelsData);
200 pixelBuffer->blitFromMemory(scolPixelBox);
277 CheckSizeAndAlloc(newWidth, newHeight, bLastAlphaState);
291 Ogre::HardwarePixelBufferSharedPtr pixelBuffer =
renderingTexture->getBuffer();
292 pixelBuffer->lock(Ogre::HardwareBuffer::HBL_READ_ONLY);
293 Ogre::PixelBox pixelBox = pixelBuffer->getCurrentLock();
295 Ogre::ColourValue tempColor = pixelBox.getColourAt(nxpos, nypos, 0);
299 pixelBuffer->unlock();
310void SBitmapWidget::CheckSizeAndAlloc(
const unsigned int& newWidth,
const unsigned int& newHeight,
const bool& alpha)
312 unsigned short nCalcTexWidth = 0;
313 unsigned short nCalcTexHeight = 0;
316 nCalcTexWidth = Ogre::Bitwise::firstPO2From(
static_cast <unsigned short>(newWidth *
textureRatio));
317 nCalcTexHeight = Ogre::Bitwise::firstPO2From(
static_cast <unsigned short>(newHeight *
textureRatio));
319#if defined(ANDROID) || defined(APPLE_IOS)
320 if (nCalcTexWidth > 512 || nCalcTexHeight > 512)
322 nCalcTexWidth = nCalcTexWidth / 2;
323 nCalcTexHeight = nCalcTexHeight / 2;
329 nCalcTexWidth =
static_cast <unsigned short>(newWidth *
textureRatio);
330 nCalcTexHeight =
static_cast <unsigned short>(newHeight *
textureRatio);
333 if ((nCalcTexWidth != iLastWidth) || (nCalcTexHeight != iLastHeight) || (alpha != bLastAlphaState))
339 SAFE_FREE(pixelsData);
343 Ogre::HardwarePixelBufferSharedPtr pixelBuffer =
renderingTexture->getBuffer();
345 iLastWidth = pixelBuffer->getWidth();
346 iLastHeight = pixelBuffer->getHeight();
347 bLastAlphaState = alpha;
351 int size =
sizeof(Ogre::uint32*);
352 pixelsData = (
void*)malloc(iLastWidth * iLastHeight * size);
369 Ogre::HardwarePixelBufferSharedPtr pixelBuffer =
renderingTexture->getBuffer();
372 const Ogre::PixelBox scolPixelBox(iLastWidth, iLastHeight, 1, pixelBuffer->getFormat(), pixelsData);
373 pixelBuffer->blitFromMemory(scolPixelBox);
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")