コード例 #1
0
ファイル: SimpleRenderContext.cpp プロジェクト: bregma/ember
SimpleRenderContext::SimpleRenderContext(const std::string& prefix, Ogre::TexturePtr texture) :
    mMainLight(0), mSceneManager(0), mWidth(texture->getWidth()), mHeight(texture->getHeight()), mRenderTexture(0), mCameraNode(0), mCameraPitchNode(0), mEntityNode(0), mRootNode(0), mCamera(0), mViewPort(0), mResourceLoader(*this), mBackgroundColour(Ogre::ColourValue::Black), mCameraPositionMode(CPM_OBJECTCENTER), mTextureOwned(false)
{

    setupScene(prefix);
    setTexture(texture);

    Ogre::Real aspectRatio = static_cast<float>(texture->getWidth()) / static_cast<float>(texture->getHeight());

    S_LOG_VERBOSE("Setting aspect ratio of camera to " << aspectRatio);
    mCamera->setAspectRatio(aspectRatio);

}
コード例 #2
0
//------------------------------------------------------------------------------
void OgreVideoTexture::_initTexture(Ogre::TexturePtr _texture)
{
    // Get the pixel buffer
    Ogre::HardwarePixelBufferSharedPtr pixelBuffer = _texture->getBuffer();

    // Lock the pixel buffer and get a pixel box
    pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD!
    const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();

    Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);

    for (size_t j = 0; j < _texture->getHeight(); j++)
        for(size_t i = 0; i < _texture->getWidth() ; i++)
        {

            if (j<480-5 && i<640-5)
            {
                *pDest++ = 255; // B
                *pDest++ = 0; // G
                *pDest++ = 255; // R
            }
            else
            {
                *pDest++ = 255; // B
                *pDest++ = 0;   // G
                *pDest++ = 0; // R
            }
        }
 
        pixelBuffer->unlock();
}
コード例 #3
0
TexturePair AssetsManager::createTextureImage(Ogre::TexturePtr texturePtr, const std::string& imageSetName)
{
	// 	if (mOgreCEGUITexture) {
	// 		GUIManager::getSingleton().getGuiRenderer()->destroyTexture(mOgreCEGUITexture);
	// 		mOgreCEGUITexture = 0;
	// 	}


	CEGUI::Imageset* textureImageset;

	if (CEGUI::ImagesetManager::getSingleton().isDefined(imageSetName)) {
		textureImageset = &CEGUI::ImagesetManager::getSingleton().get(imageSetName);
	} else {
		//create a CEGUI texture from our Ogre texture
		S_LOG_VERBOSE("Creating new CEGUI texture from Ogre texture.");
		CEGUI::Texture* ogreCEGUITexture = &GUIManager::getSingleton().getGuiRenderer()->createTexture(texturePtr);

		//we need a imageset in order to create GUI elements from the ceguiTexture
		S_LOG_VERBOSE("Creating new CEGUI imageset with name " << imageSetName);
		textureImageset = &CEGUI::ImagesetManager::getSingleton().create(imageSetName, *ogreCEGUITexture);

		//we only want one element: the whole texture
		textureImageset->defineImage("full_image", CEGUI::Rect(0, 0, texturePtr->getWidth(), texturePtr->getHeight()), CEGUI::Point(0, 0));
	}
	//assign our image element to the StaticImage widget
	const CEGUI::Image* textureImage = &textureImageset->getImage("full_image");

	return TexturePair(texturePtr, textureImage, textureImageset);

}
コード例 #4
0
//!
//! Processes the node's input data to generate the node's output image.
//!
void BadPrintingNode::processOutputImage ()
{
    // obtain input image
    Ogre::TexturePtr inputTexture = getTextureValue("Input Map");
    if (inputTexture.isNull()) {
        //disable compositor (now that the input texture name was set)
        if (m_compositor)
            m_compositor->setEnabled(false);

        //render and set output
        m_renderTexture->getBuffer()->getRenderTarget()->update();
        setValue("Image", m_defaultTexture);
        Log::warning("No input image connected.", "BadPrintingNode::processOutputImage");
    }
    else if (!m_renderTexture.isNull()) {
        //resize render texture
        size_t width = inputTexture->getWidth();
        size_t height = inputTexture->getHeight();
        resizeRenderTexture(width, height);
        
        //enable compositor (now that the input texture name was set)
        if (m_compositor)
            m_compositor->setEnabled(true);

        m_renderTexture->getBuffer()->getRenderTarget()->update();
        setValue("Image", m_renderTexture);
    }
}
コード例 #5
0
void GraphicsController::addTextureDebugOverlay(const Ogre::String& texname, size_t i)
{
    using namespace Ogre;
    Overlay* debugOverlay = OverlayManager::getSingleton().getByName("PRJZ/DebugOverlay");

	MaterialPtr debugMat = MaterialManager::getSingleton().getByName("PRJZ/BasicTexture", "PROJECT_ZOMBIE");
	if(debugMat.isNull())
		OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "PRJZ/BasicTexture material was not found.", "GraphicsController::addTextureDebugOverlay");
    debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
    TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(texname);
    t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);

    Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().getByName(texname);
    Ogre::Real tWidth = tex->getWidth();
    Ogre::Real tHeight = tex->getHeight();

    //ratio 
    Ogre::Real ratio = tHeight / tWidth;
    OverlayContainer* debugPanel = (OverlayContainer*)
        (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugTexPanel" + StringConverter::toString(i)));
    debugPanel->_setPosition(0.0, 0.0);
    debugPanel->_setDimensions(0.5f, 0.5f * ratio);
    debugPanel->setMaterialName(debugMat->getName());
    debugOverlay->add2D(debugPanel);
}
コード例 #6
0
void video_display(VideoState *is)
{
  VideoPicture *vp;

  vp = &is->pictq[is->pictq_rindex];

  if (is->video_st->codec->width != 0 && is->video_st->codec->height != 0)
  {
    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton ().getByName("VideoTexture");
    if (texture.isNull () || texture->getWidth() != is->video_st->codec->width || texture->getHeight() != is->video_st->codec->height)
    {
      Ogre::TextureManager::getSingleton ().remove ("VideoTexture");
      texture = Ogre::TextureManager::getSingleton().createManual(
                  "VideoTexture",
                  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                  Ogre::TEX_TYPE_2D,
                  is->video_st->codec->width, is->video_st->codec->height,
                  0,
                  Ogre::PF_BYTE_RGBA,
                  Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
    }
    Ogre::PixelBox pb(is->video_st->codec->width, is->video_st->codec->height, 1, Ogre::PF_BYTE_RGBA, vp->data);
    Ogre::HardwarePixelBufferSharedPtr buffer = texture->getBuffer();
    buffer->blitFromMemory(pb);
  }

  free(vp->data);
}
コード例 #7
0
ファイル: EC_ChatBubble.cpp プロジェクト: A-K/naali
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);
}
コード例 #8
0
ファイル: UiManager.cpp プロジェクト: advancingu/Cutexture
	void UiManager::setViewSize(const Ogre::TexturePtr &aTexture)
	{
		// make sure that the view size matches the texture size
		if (!aTexture.isNull() && !isViewSizeMatching(aTexture))
		{
			mWidgetView->setGeometry(QRect(0, 0, aTexture->getWidth(), aTexture->getHeight()));
		}
	}
コード例 #9
0
ファイル: imagebutton.cpp プロジェクト: Adrian-Revk/openmw
 MyGUI::IntSize ImageButton::getRequestedSize()
 {
     Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(mImageNormal);
     if (texture.isNull())
     {
         std::cerr << "ImageButton: can't find " << mImageNormal << std::endl;
         return MyGUI::IntSize(0,0);
     }
     return MyGUI::IntSize (texture->getWidth(), texture->getHeight());
 }
コード例 #10
0
void EC_WidgetCanvas::Update()
{
    if (framework->IsHeadless())
        return;

    if (!widget_.data() || texture_name_.empty())
        return;
    if (widget_->width() <= 0 || widget_->height() <= 0)
        return;

    try
    {
        Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texture_name_);
        if (texture.isNull())
            return;

        if (buffer_.size() != widget_->size())
            buffer_ = QImage(widget_->size(), QImage::Format_ARGB32_Premultiplied);
        if (buffer_.width() <= 0 || buffer_.height() <= 0)
            return;

        QPainter painter(&buffer_);
        widget_->render(&painter);

        // Set texture to material
        if (update_internals_ && !material_name_.empty())
        {
            Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(material_name_);
            if (material.isNull())
                return;
            // Just for good measure, this is done once in the ctor already if everything went well.
            OgreRenderer::SetTextureUnitOnMaterial(material, texture_name_);
            UpdateSubmeshes();
            update_internals_ = false;
        }

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

        Blit(buffer_, texture);
    }
    catch (Ogre::Exception &e) // inherits std::exception
    {
        LogError("Exception occurred while blitting texture data from memory: " + std::string(e.what()));
    }
    catch (...)
    {
        LogError("Unknown exception occurred while blitting texture data from memory.");
    }
}
コード例 #11
0
void EC_WidgetCanvas::Update(QImage buffer)
{
    if (framework->IsHeadless())
        return;
    if (buffer.width() <= 0 || buffer.height() <= 0)
        return;

    if (buffer.format() != QImage::Format_ARGB32 && buffer.format() != QImage::Format_ARGB32_Premultiplied)
    {
        LogWarning("EC_WidgetCanvas::Update(QImage buffer): Input format needs to be Format_ARGB32 or Format_ARGB32_Premultiplied, preforming auto conversion!");
        buffer = buffer.convertToFormat(QImage::Format_ARGB32);
        if (buffer.isNull())
        {
            LogError("-- Auto conversion failed, not updating!");
            return;
        }
    }

    try
    {
        Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texture_name_);
        if (texture.isNull())
            return;

        // Set texture to material if need be
        if (update_internals_ && !material_name_.empty())
        {
            Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(material_name_);
            if (material.isNull())
                return;
            // Just for good measure, this is done once in the ctor already if everything went well.
            OgreRenderer::SetTextureUnitOnMaterial(material, texture_name_);
            UpdateSubmeshes();
            update_internals_ = false;
        }

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

        Blit(buffer, texture);
    }
    catch (Ogre::Exception &e) // inherits std::exception
    {
        LogError("Exception occurred while blitting texture data from memory: " + std::string(e.what()));
    }
    catch (...)
    {
        LogError("Unknown exception occurred while blitting texture data from memory.");
    }
}
コード例 #12
0
ファイル: GUIHelper.cpp プロジェクト: agudpp/CordobaZombie
/**
 * Returns the texture width of a material or -1 if have not texture
 */
int GUIHelper::getTextureWidth(const Ogre::String &materialName)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(materialName);
	if(mat.isNull() || /*!mat->getTechnique(0) ||
			!mat->getTechnique(0)->getPass(0) ||*/
			!mat->getTechnique(0)->getPass(0)->getTextureUnitState(0))
		return -1;

	Ogre::TexturePtr text = Ogre::TextureManager::getSingleton().getByName(
			mat->getTechnique(0)->getPass(0)->getTextureUnitState(
					0)->getTextureName());
	if(text.isNull()) return -1;
	return text->getWidth();
}
コード例 #13
0
/**
Constructor for when we already have a texture of the whole icon.
*/
IconImageStore::IconImageStore(const std::string& imagesetName, Ogre::TexturePtr texPtr)
: mImagesetName(imagesetName)
, mTexPtr(texPtr)
, mImageDataStream(nullptr)
, mCeguiTexture(nullptr)
{
	mCeguiTexture = &GUIManager::getSingleton().createTexture(mTexPtr, imagesetName);
	

	//we'll assume that height and width are the same
	mImageSize = texPtr->getWidth();
	mIconSize = mImageSize;
	
	//this will only create one entry
	createEntries();
}
コード例 #14
0
ファイル: skin.cpp プロジェクト: Joooo/pseudoform
        skin::skin(const string &n):
            _name(n),
            _prefix("gui/skins/" + _name + "/" + _name)
        {
            txml::document doc;
            doc.LoadFile((engine::DATA_DIR + _prefix + ".xml").c_str());
            if (doc.Error())
            {
                engine::log("failed to load GUI skin " + _name);
                return;
            }

            txml::element *rootElem = doc.RootElement();

            for (txml::node *i = rootElem->FirstChild(); i; i = i->NextSibling())
            {
                pieceList &pl = _elements[i->Value()];

                for (txml::node *j = i->FirstChild(); j; j = j->NextSibling())
                {
                    txml::element *element = j->ToElement();
                    if (element)
                    {
                        piece &p = pl[element->Value()];
                        string tex = element->attrib<string>("image", string());

                        if (!tex.empty())
                        {
                            p.tex = "gui/skins/" + _name + "/" + tex;

                            Ogre::TexturePtr tex = gfx::getTexture(p.tex);
                            if (tex.get())
                                p.size = vec2(tex->getWidth(), tex->getHeight());
                            else
                                p.size = vec2(0, 0);
                        }
                        else
                        {
                            p.tex.clear();
                            p.size = vec2(0, 0);
                        }
                    }
                }
            }
        }
コード例 #15
0
ファイル: GUIHelper.cpp プロジェクト: agudpp/CordobaZombie
/**
 * Create a new PanelOverlayElement
 * @param	matName		The name of the material
 * @param	rSize		The resulting size of the texture (width)
 * @param	name		The name of the panel
 */
Ogre::PanelOverlayElement *GUIHelper::createPanel(const Ogre::String &matName,
		int &rSize, const Ogre::String &name)
{
	static int counter = 0;

	Ogre::PanelOverlayElement *result = 0;
	Ogre::String realName;

	if(name.empty()){
		realName = "pan" + Ogre::StringConverter::toString(counter);
		counter++;
	} else {
		realName = name;
	}

#ifdef DEBUG
	// ensures the material exists
	Ogre::MaterialPtr		material;
	material = Ogre::MaterialManager::getSingleton().getByName(matName);
	if(material.isNull()){
		debug("Material %s not found\n", matName.c_str());
	}
//	ASSERT(!material.isNull());
#endif

	Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton();
	result = static_cast<Ogre::PanelOverlayElement*>(
		overlayManager.createOverlayElement("Panel", realName));
	result->setMetricsMode(Ogre::GMM_RELATIVE);
	result->setMaterialName(matName); // Optional background material

	// get the texture size
	Ogre::String text = result->getMaterial()->getTechnique(0)->getPass(0)->
			getTextureUnitState(0)->getTextureName();
	Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(text);
	ASSERT(!texture.isNull());
	rSize = texture->getWidth();

	return result;
}
コード例 #16
0
void CLASS::ResizePreviewImage()
{
	MyGUI::IntSize imgSize(0, 0);
	Ogre::TexturePtr t = Ogre::TextureManager::getSingleton().load(m_preview_image_texture, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
	if (!t.isNull())
	{
		imgSize.width = (int)t->getWidth() * 10;
		imgSize.height = (int)t->getHeight() * 10;
	}

	if (imgSize.width != 0 && imgSize.height != 0)
	{
		MyGUI::IntSize maxSize = m_PreviewBox->getSize();

		float imgRatio = imgSize.width / (float)imgSize.height;
		float maxRatio = maxSize.width / (float)maxSize.height;

		MyGUI::IntSize newSize(0, 0);
		MyGUI::IntPoint newPosition(0, 0);

		// scale with aspect ratio
		if (imgRatio > maxRatio)
		{
			newSize.width = maxSize.width;
			newSize.height = maxSize.width / imgRatio;
			newPosition.left = 0;
			newPosition.top = maxSize.height - newSize.height;
		}
		else
		{
			newSize.width = maxSize.height * imgRatio;
			newSize.height = maxSize.height;
			newPosition.left = maxSize.width - newSize.width;
			newPosition.top = 0;
		}

		m_Preview->setSize(newSize);
		m_Preview->setPosition(newPosition);
	}
}
コード例 #17
0
ファイル: globalmap.cpp プロジェクト: AAlderman/openmw
    void GlobalMap::exploreCell(int cellX, int cellY)
    {
        float originX = static_cast<float>((cellX - mMinX) * mCellSize);
        // NB y + 1, because we want the top left corner, not bottom left where the origin of the cell is
        float originY = static_cast<float>(mHeight - (cellY + 1 - mMinY) * mCellSize);

        if (cellX > mMaxX || cellX < mMinX || cellY > mMaxY || cellY < mMinY)
            return;

        Ogre::TexturePtr localMapTexture = Ogre::TextureManager::getSingleton().getByName("Cell_"
            + boost::lexical_cast<std::string>(cellX) + "_" + boost::lexical_cast<std::string>(cellY));

        if (!localMapTexture.isNull())
        {
            int mapWidth = localMapTexture->getWidth();
            int mapHeight = localMapTexture->getHeight();
            mOverlayTexture->load();
            mOverlayTexture->getBuffer()->blit(localMapTexture->getBuffer(), Ogre::Image::Box(0,0,mapWidth,mapHeight),
                         Ogre::Image::Box(static_cast<Ogre::uint32>(originX), static_cast<Ogre::uint32>(originY),
                         static_cast<Ogre::uint32>(originX + mCellSize), static_cast<Ogre::uint32>(originY + mCellSize)));

            Ogre::Image backup;
            std::vector<Ogre::uchar> data;
            data.resize(mCellSize*mCellSize*4, 0);
            backup.loadDynamicImage(&data[0], mCellSize, mCellSize, Ogre::PF_A8B8G8R8);

            localMapTexture->getBuffer()->blitToMemory(Ogre::Image::Box(0,0,mapWidth,mapHeight), backup.getPixelBox());

            for (int x=0; x<mCellSize; ++x)
                for (int y=0; y<mCellSize; ++y)
                {
                    assert (originX+x < mOverlayImage.getWidth());
                    assert (originY+y < mOverlayImage.getHeight());
                    assert (x < int(backup.getWidth()));
                    assert (y < int(backup.getHeight()));
                    mOverlayImage.setColourAt(backup.getColourAt(x, y, 0), static_cast<size_t>(originX + x), static_cast<size_t>(originY + y), 0);
                }
        }
    }
コード例 #18
0
bool RocketInterface::LoadTexture(Rocket::Core::TextureHandle& textureHandle,
                                  Rocket::Core::Vector2i& textureDimensions,
                                  const Rocket::Core::String& source)
{
    Ogre::TextureManager* tm = Ogre::TextureManager::getSingletonPtr();
    Ogre::TexturePtr texture = tm->getByName(Ogre::String(source.CString()));

    if (texture.isNull())
    {
        texture = tm->load(
            Ogre::String(source.CString()), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
            Ogre::TEX_TYPE_2D, 0, 1.0f, false, Ogre::PF_UNKNOWN, true);
    }

    if (texture.isNull())
        return false;

    textureDimensions.x = texture->getWidth();
    textureDimensions.y = texture->getHeight();

    textureHandle = reinterpret_cast<Rocket::Core::TextureHandle>(new RocketOgreTexture(texture));
    return true;
}
コード例 #19
0
ファイル: UiManager.cpp プロジェクト: advancingu/Cutexture
	bool UiManager::isViewSizeMatching(const Ogre::TexturePtr &aTexture) const
	{
		assert(!aTexture.isNull());
		
		return (aTexture->getWidth() == mWidgetView->width() && aTexture->getHeight() == mWidgetView->height());
	}
コード例 #20
0
ファイル: Terrain.cpp プロジェクト: gitrider/wxsj2
void
Terrain::_createAtlasPixmap(size_t pixmapId)
{
    const TerrainData::Pixmap& pixmap = mData->mPixmaps[pixmapId];
    size_t textureId = pixmap.textureId;
    assert(textureId < mData->mTextures.size());
    const Ogre::String& textureName = mData->mTextures[textureId];

    // If the atlas texture already exist, use it.

    AtlasArray::const_iterator it;
    for (it = mAtlases.begin(); it != mAtlases.end(); ++it)
    {
        if (it->texture->getName() == textureName)
            break;
    }
    if (it != mAtlases.end())
    {
        // Fill up atlas pixmap info
        size_t atlasId = it - mAtlases.begin() + 1;
        mAtlasPixmaps[pixmapId].atlasId = atlasId;
        mAtlasPixmaps[pixmapId].left = pixmap.left;
        mAtlasPixmaps[pixmapId].top = pixmap.top;
        mAtlasPixmaps[pixmapId].right = pixmap.right;
        mAtlasPixmaps[pixmapId].bottom = pixmap.bottom;
        return;
    }

    // If texture already loaded and is composited, use it without any modify.
    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(textureName);
    if (!texture.isNull() &&
        (texture->getWidth() > mAtlasPixmapSize || texture->getHeight() > mAtlasPixmapSize))
    {
        mAtlases.push_back(Atlas());
        Atlas& atlas = mAtlases.back();

        atlas.texture = texture;

        // Fill up atlas pixmap info
        size_t atlasId = mAtlases.size();
        mAtlasPixmaps[pixmapId].atlasId = atlasId;
        mAtlasPixmaps[pixmapId].left = pixmap.left;
        mAtlasPixmaps[pixmapId].top = pixmap.top;
        mAtlasPixmaps[pixmapId].right = pixmap.right;
        mAtlasPixmaps[pixmapId].bottom = pixmap.bottom;
        return;
    }

    // Load the image
    Ogre::Image image;
    image.load(textureName, BRUSH_RESOURCE_GROUP_NAME);

    // If the image is composited, use it without any modify.
    if (image.getWidth() > mAtlasPixmapSize || image.getHeight() > mAtlasPixmapSize)
    {
        mAtlases.push_back(Atlas());
        Atlas& atlas = mAtlases.back();

        // re-use the loaded image avoid load it again
        atlas.texture =
            Ogre::TextureManager::getSingleton()
            .loadImage(textureName, BRUSH_RESOURCE_GROUP_NAME, image);

        // Fill up atlas pixmap info
        size_t atlasId = mAtlases.size();
        mAtlasPixmaps[pixmapId].atlasId = atlasId;
        mAtlasPixmaps[pixmapId].left = pixmap.left;
        mAtlasPixmaps[pixmapId].top = pixmap.top;
        mAtlasPixmaps[pixmapId].right = pixmap.right;
        mAtlasPixmaps[pixmapId].bottom = pixmap.bottom;
        return;
    }

    // Composite into the atlas texture.

    bool isTransparent = image.getHasAlpha();
    AtlasAllocInfo& allocInfo = isTransparent ? mTransparentAtlasAllocInfo : mSolidAtlasAllocInfo;
    if (allocInfo.blockId >= mMaxAtlasBlockId)
    {
        // Use special name to avoid confuse with other reference with this texture
       Ogre::String atlasName = "<Terrain/Atlas>:" + Ogre::StringConverter::toString(mAtlases.size());

        mAtlases.push_back(Atlas());
        Atlas& atlas = mAtlases.back();

        Ogre::PixelFormat pixelFormat = isTransparent ? Ogre::PF_A8R8G8B8 : Ogre::PF_X8R8G8B8;
        atlas.image.bind(new Ogre::Image);
        atlas.image->loadDynamicImage(0, mAtlasTextureSize, mAtlasTextureSize, 1, pixelFormat, true, 1, mAtlasNumMipMaps);
        memset(atlas.image->getData(), 0, atlas.image->getSize());

        atlas.texture =
            Ogre::TextureManager::getSingleton().createManual(atlasName,
                BRUSH_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
                atlas.image->getWidth(), atlas.image->getHeight(),
                mAtlasNumMipMaps, atlas.image->getFormat(),
                Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE,
                this);

        allocInfo.atlasId = mAtlases.size();
        allocInfo.blockId = 0;
    }

    // Copy origin pixmap to atlas image
    Atlas& atlas = mAtlases[allocInfo.atlasId - 1];
    int blockX = allocInfo.blockId % mAtlasBlockSize;
    int blockY = allocInfo.blockId / mAtlasBlockSize;
    Ogre::PixelBox dst = atlas.image->getPixelBox().getSubVolume(Ogre::Box(
        blockX * mAtlasPixmapSize,
        blockY * mAtlasPixmapSize,
        blockX * mAtlasPixmapSize + mAtlasPixmapSize,
        blockY * mAtlasPixmapSize + mAtlasPixmapSize));
    Ogre::PixelBox src = image.getPixelBox().getSubVolume(Ogre::Box(
        fast_ifloor(pixmap.left * image.getWidth() + 0.5f),
        fast_ifloor(pixmap.top * image.getHeight() + 0.5f),
        fast_ifloor(pixmap.right * image.getWidth() + 0.5f),
        fast_ifloor(pixmap.bottom * image.getHeight() + 0.5f)));
    if (src.getWidth() == mAtlasPixmapSize && src.getHeight() == mAtlasPixmapSize)
        Ogre::PixelUtil::bulkPixelConversion(src, dst);
    else
        Ogre::Image::scale(src, dst);

    // Generate mipmaps manual
    for (size_t mipmap = 1; mipmap <= mAtlasNumMipMaps; ++mipmap)
    {
        src = dst;
        size_t pixmapSize = mAtlasPixmapSize >> mipmap;
        dst = atlas.image->getPixelBox(0, mipmap).getSubVolume(Ogre::Box(
            blockX * pixmapSize,
            blockY * pixmapSize,
            blockX * pixmapSize + pixmapSize,
            blockY * pixmapSize + pixmapSize));
        Ogre::Image::scale(src, dst);
    }

    // Notify that the atlas texture need to reload
    if (atlas.texture->isLoaded())
        atlas.texture->unload();

    ++allocInfo.blockId;

    // Fill up atlas pixmap info

    mAtlasPixmaps[pixmapId].atlasId = allocInfo.atlasId;
    mAtlasPixmaps[pixmapId].left = blockX * mAtlasBlockTexCoordInc + 0.5f / mAtlasTextureSize;
    mAtlasPixmaps[pixmapId].top = blockY * mAtlasBlockTexCoordInc + 0.5f / mAtlasTextureSize;
    mAtlasPixmaps[pixmapId].right = mAtlasPixmaps[pixmapId].left + mAtlasBlockTexCoordInc -  1.0f / mAtlasTextureSize;
    mAtlasPixmaps[pixmapId].bottom = mAtlasPixmaps[pixmapId].top + mAtlasBlockTexCoordInc -  1.0f / mAtlasTextureSize;
}
コード例 #21
0
	void Material::update() {
		if(!baseMaterial.isNull()) {
			Ogre::ColourValue ambient = baseMaterial->getTechnique(0)->getPass(0)->getAmbient();
			Ogre::ColourValue diffuse = baseMaterial->getTechnique(0)->getPass(0)->getDiffuse();
			Ogre::ColourValue specular = baseMaterial->getTechnique(0)->getPass(0)->getSpecular();
			Ogre::ColourValue emissive = baseMaterial->getTechnique(0)->getPass(0)->getEmissive();
			float shininess = baseMaterial->getTechnique(0)->getPass(0)->getShininess();
			GLuint tex = 0;
			if(baseMaterial->getNumTechniques()!=0 && baseMaterial->getTechnique(0)->getNumPasses()!=0 && baseMaterial->getTechnique(0)->getPass(0)->getNumTextureUnitStates()!=0) {
				Ogre::String texName = baseMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName();
				if(Ogre::TextureManager::getSingleton().resourceExists(texName)) {
					Ogre::TexturePtr texPtr = Ogre::TextureManager::getSingleton().getByName(texName);
					Ogre::Image img;
					texPtr->convertToImage(img);
					Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual(texPtr->getName()+"_optixformat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, texPtr->getWidth(), texPtr->getHeight(), 0, Ogre::PF_FLOAT32_RGBA, Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
					texture->loadImage(img);
					tex = ((Ogre::GLTexturePtr)texture)->getGLID();
				}
			}
			prepareMaterial(glm::vec3(ambient.r,ambient.g,ambient.b),
							glm::vec3(diffuse.r,diffuse.g,diffuse.b),
							glm::vec3(specular.r,specular.g,specular.b),
							glm::vec3(emissive.r,emissive.g,emissive.b),
							shininess,tex);
		}
	}
コード例 #22
0
ファイル: DrawCommon.cpp プロジェクト: volca02/openDarkEngine
//------------------------------------------------------
DrawSourceBase::DrawSourceBase(ID srcID, const Ogre::MaterialPtr &mat,
                               const Ogre::TexturePtr &tex)
    : mMaterial(mat), mTexture(tex), mSourceID(srcID) {
    mPixelSize.width = tex->getWidth();
    mPixelSize.height = tex->getHeight();
};
コード例 #23
0
 bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect)
 {
     rect = CefRect(0, 0, m_renderTexture->getWidth(), m_renderTexture->getHeight());
     return true;
 }