void OgreNode::updateFBO() { Ogre::TexturePtr rttTexture = mRenderSystem->getRtt("RttTex", mSize.width(), mSize.height()); mRenderTarget = rttTexture->getBuffer()->getRenderTarget(); Ogre::Camera* cam = mRenderSystem->getOgreCamera(); mRenderTarget->addViewport(cam); Ogre::Real aspectRatio = Ogre::Real(mSize.width()) / Ogre::Real(mSize.height()); cam->setAspectRatio(aspectRatio); QSGGeometry::updateTexturedRectGeometry(&mGeometry, QRectF(0, 0, mSize.width(), mSize.height()), QRectF(0, 0, 1, 1)); Ogre::GLTexture *nativeTexture = static_cast<Ogre::GLTexture *>(rttTexture.get()); delete mTexture; mTexture = mQuickWindow->createTextureFromId(nativeTexture->getGLID(), mSize); mMaterial.setTexture(mTexture); mMaterialO.setTexture(mTexture); LOG(INFO) << "Updated FBO, new size: " << mSize.width() << "x" << mSize.height() << ", texture id: " << nativeTexture->getGLID(); }
void ReplaceTextureOnMaterial(Ogre::MaterialPtr material, const std::string& original_name, const std::string& texture_name) { if (material.isNull()) return; Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton(); Ogre::TexturePtr tex = tm.getByName(texture_name); Ogre::Material::TechniqueIterator iter = material->getTechniqueIterator(); while(iter.hasMoreElements()) { Ogre::Technique *tech = iter.getNext(); assert(tech); Ogre::Technique::PassIterator passIter = tech->getPassIterator(); while(passIter.hasMoreElements()) { Ogre::Pass *pass = passIter.getNext(); Ogre::Pass::TextureUnitStateIterator texIter = pass->getTextureUnitStateIterator(); while(texIter.hasMoreElements()) { Ogre::TextureUnitState *texUnit = texIter.getNext(); if (texUnit->getTextureName() == original_name) { if (tex.get()) texUnit->setTextureName(texture_name); else texUnit->setTextureName("TextureMissing.png"); } } } } }
void RenderWindow::Resize(int width, int height) { renderWindow->resize(width, height); renderWindow->windowMovedOrResized(); if (Ogre::TextureManager::getSingletonPtr() && Ogre::OverlayManager::getSingletonPtr()) { PROFILE(RenderWindow_Resize); // recenter the overlay // int left = (renderWindow->getWidth() - width) / 2; // int top = (renderWindow->getHeight() - height) / 2; // resize the container // overlayContainer->setDimensions(width, height); // overlayContainer->setPosition(left, top); overlayContainer->setDimensions((Ogre::Real)width, (Ogre::Real)height); overlayContainer->setPosition(0,0); // resize the backing texture Ogre::TextureManager &mgr = Ogre::TextureManager::getSingleton(); Ogre::TexturePtr texture = mgr.getByName(rttTextureName); assert(texture.get()); texture->freeInternalResources(); texture->setWidth(width); texture->setHeight(height); texture->createInternalResources(); } }
void QOgreWorldView::ResizeOverlay(int width, int height) { if (Ogre::TextureManager::getSingletonPtr() && Ogre::OverlayManager::getSingletonPtr()) { PROFILE(QOgreWorldView_ResizeOverlay); // recenter the overlay int left = (win_->getWidth() - width) / 2; int top = (win_->getHeight() - height) / 2; // resize the container ui_overlay_container_->setDimensions(width, height); ui_overlay_container_->setPosition(left, top); // resize the backing texture Ogre::TextureManager &mgr = Ogre::TextureManager::getSingleton(); Ogre::TexturePtr texture = mgr.getByName(texture_name_); assert(texture.get()); texture->freeInternalResources(); texture->setWidth(width); texture->setHeight(height); texture->createInternalResources(); } }
void QOgreWorldView::OverlayUI(Ogre::PixelBox &ui) { PROFILE(QOgreWorldView_OverlayUI); Ogre::TextureManager &mgr = Ogre::TextureManager::getSingleton(); Ogre::TexturePtr texture = mgr.getByName(texture_name_); assert(texture.get()); texture->getBuffer()->blitFromMemory(ui); }
void RenderWindow::UpdateOverlayImage(const QImage &src) { PROFILE(RenderWindow_UpdateOverlayImage); Ogre::Box bounds(0, 0, src.width(), src.height()); Ogre::PixelBox bufbox(bounds, Ogre::PF_A8R8G8B8, (void *)src.bits()); Ogre::TextureManager &mgr = Ogre::TextureManager::getSingleton(); Ogre::TexturePtr texture = mgr.getByName(rttTextureName); assert(texture.get()); texture->getBuffer()->blitFromMemory(bufbox); }
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); } } } } }
void TerrainWeightEditor::ApplyWeightTexture() { if(!GetSceneManager()) return; QImage map = CreateImageFromCanvases(); if(map.isNull()) return; if(map.format() != QImage::Format_ARGB32) { map = map.convertToFormat(QImage::Format_ARGB32/*,Qt::NoOpaqueDetection*/); } Ogre::Box bounds(0, 0, map.width(), map.height()); Ogre::PixelBox bufbox(bounds, Ogre::PF_A8R8G8B8, (void *)map.bits()); Scene::EntityList list = scene_manager_->GetEntitiesWithComponent("EC_Terrain"); Scene::EntityList::const_iterator it = list.begin(); while(it!= list.end()) { boost::shared_ptr<EC_Terrain> ptr = (*it)->GetComponent<EC_Terrain>(); QString texname; texname += (*it)->GetName(); texname += ptr->TypeName(); texname += ptr->Name(); texname += ".png"; Ogre::String str(texname.toStdString()); Ogre::TextureManager::getSingleton().remove(str); Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().createManual(str, "General", Ogre::TEX_TYPE_2D, bufbox.getWidth(), bufbox.getHeight(),bufbox.getDepth(),0,bufbox.format,Ogre::TU_DYNAMIC_WRITE_ONLY); if(tex.get()) { tex->getBuffer()->blitFromMemory(bufbox); } ptr->texture0.Set(AssetReference(texname/*, "OgreTexture"*/), AttributeChange::Disconnected); it++; ///For now we just save this to assets folder. Later on, this should be replicated to server/clients etc. QImageWriter writer("data/assets/" + texname); writer.setCompression(0); writer.write(map); } }
bool NxTextureVideo::OpenVideoFile( const std::string & filename, const std::string & TextureName, bool useOpenGL, NxVideoPixelFormatInfo & info ) { mNxVideoFile = NxVideoManager::getSingleton().OpenVideoFile( filename, info ); Type = TYPE_AVI; if( mNxVideoFile->HasAudio() ) { mHasAudio = true; mAudioSampleRate = mNxVideoFile->GetAudioSampleRate() ; mAudioChannels = mNxVideoFile->GetAudioNumChannels(); mAudioBufferSize = mNxVideoFile->GetAudioBufferSize(); mAudioBitsPerSamples = mNxVideoFile->GetAudioBitsperSamples(); } if( mNxVideoFile->HasVideo() ) { NxVideoPixelFormat format = mNxVideoFile->GetVideoFormat(); std::vector<VideoPlaneInfo> info; GetVideoPlaneInfo( mNxVideoFile, info ); for( int i = 0 ; i < info.size(); i++ ) { int numMipMaps = 0; Ogre::TexturePtr tex = TextureManager::getSingleton().createManual( TextureName+"_"+Ogre::StringConverter::toString( i ), "NxMaterialVideo", TEX_TYPE_2D, info[i].width, info[i].height, numMipMaps, (Ogre::PixelFormat)info[i].format, TU_DYNAMIC_WRITE_ONLY_DISCARDABLE ); mTexture.push_back( tex.get() ); mNxVideoFile->SetOpenGLID( i, GetTextureID( i ) ); } mFrameBuffer = new NxFrameBufferVideo( this ); //NxPixelBuffer = mVideoTexture->mTexture->getBuffer(0,0).get(); //if( mVideoTexture->NxPixelBuffer->getFormat() != mVideoTexture->FormatType ) { // LogMsg("----- ERROR texture depth INVALID2 !"); // // doesnt matter so much since when uploading to gpu, pixelbox will be converted... // LogMsg("pixel buffer format : " + Ogre::StringConverter::toString( mVideoTexture->mTexture->getFormat() ) ); // LogMsg("texture format : " + Ogre::StringConverter::toString( mVideoTexture->FormatType ) ); //} //mVideoTexture->Width = mVideoTexture->GetVideoWidth(); //mVideoTexture->Height = mVideoTexture->GetVideoHeight(); //mVideoTexture->NxTextureName = TextureName; //mVideoTexture->Bpp = mVideoTexture->GetVideoBpp(); //mVideoTexture->Bpp == 4 ? mVideoTexture->FormatType = NXPF_A8R8G8B8 : mVideoTexture->FormatType = NXPF_BYTE_BGR; // PixelFormat::PF_BYTE_BGRA // -> PF_A8R8G8B8 } return mNxVideoFile != NULL; }