示例#1
0
void EC_ChatBubble::Refresh()
{
    if (renderer_.expired() || !billboardSet_ || !billboard_)
        return;

    // If no messages in the log, hide the chat bubble.
    if (messages_.isEmpty())
    {
        billboardSet_->setVisible(false);
        return;
    }
    else
        billboardSet_->setVisible(true);

    // Get image buffer and texture
    QImage buffer = GetChatBubblePixmap().toImage();
    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texture_name_);
    if (buffer.isNull() || texture.isNull())
        return;

    // Check texture size
    if ((int)texture->getWidth() != buffer.width() || (int)texture->getHeight() != buffer.height())
    {
        texture->freeInternalResources();
        texture->setWidth(buffer.width());
        texture->setHeight(buffer.height());
        texture->createInternalResources();
    }

    // Update texture buffer
    Ogre::Box update_box(0,0, buffer.width(), buffer.height());
    Ogre::PixelBox pixel_box(update_box, Ogre::PF_A8R8G8B8, (void*)buffer.bits());
    if (!texture->getBuffer().isNull())
        texture->getBuffer()->blitFromMemory(pixel_box, update_box);
}
示例#2
0
bool EC_WidgetCanvas::Blit(const QImage &source, Ogre::TexturePtr destination)
{
#if defined(DIRECTX_ENABLED) && defined(WIN32)
    Ogre::HardwarePixelBufferSharedPtr pb = destination->getBuffer();
    Ogre::D3D9HardwarePixelBuffer *pixelBuffer = dynamic_cast<Ogre::D3D9HardwarePixelBuffer*>(pb.get());
    if (!pixelBuffer)
        return false;

    LPDIRECT3DSURFACE9 surface = pixelBuffer->getSurface(Ogre::D3D9RenderSystem::getActiveD3D9Device());
    if (surface)
    {
        D3DSURFACE_DESC desc;
        HRESULT hr = surface->GetDesc(&desc);
        if (SUCCEEDED(hr))
        {
            D3DLOCKED_RECT lock;
            HRESULT hr = surface->LockRect(&lock, 0, 0);
            if (SUCCEEDED(hr))
            {
                const int bytesPerPixel = 4; ///\todo Count from Ogre::PixelFormat!
                const int sourceStride = bytesPerPixel * source.width();
                if (lock.Pitch == sourceStride)
                    memcpy(lock.pBits, source.bits(), sourceStride * source.height());
                else
                    for(int y = 0; y < source.height(); ++y)
                        memcpy((u8*)lock.pBits + lock.Pitch * y, source.bits() + sourceStride * y, sourceStride);
                surface->UnlockRect();
            }
        }
    }
#else
    if (!destination->getBuffer().isNull())
    {
        Ogre::Box update_box(0, 0, source.width(), source.height());
        Ogre::PixelBox pixel_box(update_box, Ogre::PF_A8R8G8B8, (void*)source.bits());
        destination->getBuffer()->blitFromMemory(pixel_box, update_box);
    }
#endif

    return true;
}
示例#3
0
    bool OgreTextureResource::SetData(Foundation::TexturePtr source)
    {
        if (!source)
        {
            OgreRenderingModule::LogError("Null source texture data pointer");
            return false;
        }
        if ((!source->GetWidth()) || (!source->GetHeight()))
        {
            OgreRenderingModule::LogError("Texture with zero dimension(s)");
            return false;
        }
            
        Ogre::PixelFormat pixel_format;
        switch (source->GetComponents())
        {
        case 1:
            pixel_format = Ogre::PF_L8;
            break;

        case 2:
            pixel_format = Ogre::PF_BYTE_LA;
            break;

        case 3:
            pixel_format = Ogre::PF_B8G8R8;
            break;

        case 4:
            pixel_format = Ogre::PF_A8B8G8R8;
            break;

        default:
            OgreRenderingModule::LogError("Illegal number of components in texture: " + ToString<uint>(source->GetComponents()));
            return false; 
        }

        try
        {
            if (ogre_texture_.isNull())
            {   
                ogre_texture_ = Ogre::TextureManager::getSingleton().createManual(
                    id_, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
                    source->GetWidth(), source->GetHeight(), Ogre::MIP_DEFAULT, pixel_format, Ogre::TU_DEFAULT); 

                if (ogre_texture_.isNull())
                {
                    OgreRenderingModule::LogError("Failed to create texture " + id_);
                    return false; 
                }   
            }
            else
            {
                // See if size/format changed, have to delete/recreate internal resources
                if ((source->GetWidth() != ogre_texture_->getWidth()) ||
                    (source->GetHeight() != ogre_texture_->getHeight()) ||
                    (pixel_format != ogre_texture_->getFormat()))
                {
                    ogre_texture_->freeInternalResources();
                    ogre_texture_->setWidth(source->GetWidth());
                    ogre_texture_->setHeight(source->GetHeight());
                    ogre_texture_->setFormat(pixel_format);
                    ogre_texture_->createInternalResources();
                }
            }

            Ogre::Box dimensions(0,0, source->GetWidth(), source->GetHeight());
            Ogre::PixelBox pixel_box(dimensions, pixel_format, (void*)source->GetData());
            ogre_texture_->getBuffer()->blitFromMemory(pixel_box);   
        }
        catch (Ogre::Exception &e)
        {
            OgreRenderingModule::LogError("Failed to create texture " + id_ + ": " + std::string(e.what()));
            return false;
        }

        OgreRenderingModule::LogDebug("Ogre texture " + id_ + " updated");
        level_ = source->GetLevel();
        return true;
    }