bool ShadowUpdateTask::executeTaskInMainThread() { if (!mPageGeometries.empty()) { auto pageGeometry = mPageGeometries.back(); mPageGeometries.pop_back(); auto& page = pageGeometry->getPage(); if (page.getSurface()) { auto shadow = page.getSurface()->getShadow(); if (shadow) { auto& shadowTextureName = shadow->getShadowTextureName(); if (!shadowTextureName.empty()) { Ogre::TexturePtr texture = Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(shadowTextureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); if (texture) { Ogre::Image ogreImage; shadow->loadIntoImage(ogreImage); texture->loadImage(ogreImage); //blit the whole image to the hardware buffer Ogre::PixelBox sourceBox(ogreImage.getPixelBox()); //blit for each mipmap for (unsigned int i = 0; i <= texture->getNumMipmaps(); ++i) { Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(texture->getBuffer(0, i)); hardwareBuffer->blitFromMemory(sourceBox); } } } } } } return mPageGeometries.empty(); }
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); } }
Ogre::TexturePtr Simple::updateShadowTexture(Ogre::MaterialPtr material, const TerrainPageShadow* terrainPageShadow, std::set<std::string>& managedTextures) const { auto shadowTextureName = getShadowTextureName(material); Ogre::TexturePtr texture = static_cast<Ogre::TexturePtr>(Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(shadowTextureName)); if (texture.isNull()) { texture = Ogre::Root::getSingletonPtr()->getTextureManager()->createManual(shadowTextureName, "General", Ogre::TEX_TYPE_2D, mPage.getBlendMapSize(), mPage.getBlendMapSize(), 1, Ogre::PF_L8, Ogre::TU_DYNAMIC_WRITE_ONLY); managedTextures.insert(texture->getName()); } Ogre::Image ogreImage; terrainPageShadow->loadIntoImage(ogreImage); texture->loadImage(ogreImage); //blit the whole image to the hardware buffer Ogre::PixelBox sourceBox(ogreImage.getPixelBox()); //blit for each mipmap for (unsigned int i = 0; i <= texture->getNumMipmaps(); ++i) { Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(texture->getBuffer(0, i)); hardwareBuffer->blitFromMemory(sourceBox); } return texture; }
Ogre::TexturePtr Simple::updateShadowTexture(Ogre::MaterialPtr material, const TerrainPageShadow* terrainPageShadow) { //we need an unique name for our alpha texture std::stringstream shadowTextureNameSS; shadowTextureNameSS << material->getName() << "_shadow"; const Ogre::String shadowTextureName(shadowTextureNameSS.str()); Ogre::TexturePtr texture = static_cast<Ogre::TexturePtr> (Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(shadowTextureName)); if (texture.isNull()) { texture = Ogre::Root::getSingletonPtr()->getTextureManager()->createManual(shadowTextureName, "General", Ogre::TEX_TYPE_2D, mPage.getAlphaTextureSize(), mPage.getAlphaTextureSize(), 1, Ogre::PF_L8, Ogre::TU_DYNAMIC_WRITE_ONLY); } Ogre::Image ogreImage; terrainPageShadow->loadIntoImage(ogreImage); texture->loadImage(ogreImage); //blit the whole image to the hardware buffer Ogre::PixelBox sourceBox(ogreImage.getPixelBox()); //blit for each mipmap for (unsigned int i = 0; i <= texture->getNumMipmaps(); ++i) { Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(texture->getBuffer(0, i)); hardwareBuffer->blitFromMemory(sourceBox); } return texture; }
void EMBOgre::createOgreTexture(EMBFile *file, size_t index) { string ogre_emb_name = name + "_"; string emb_texture_name = file->getName(); if (emb_texture_name.size()) { ogre_emb_name += emb_texture_name; } else { ogre_emb_name += ToString(index); } Ogre::DataStreamPtr data_stream(new EMBOgreDataStream(file)); Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createResource(ogre_emb_name, XENOVIEWER_RESOURCE_GROUP).staticCast<Ogre::Texture>(); Ogre::Image image; image.load(data_stream, "DDS"); texture->loadImage(image); ogre_textures[index] = texture; }
void Simple::addLightingPass(Ogre::Technique* technique, std::set<std::string>& managedTextures) const { Ogre::Pass* lightingPass = technique->createPass(); lightingPass->setSceneBlending(Ogre::SBT_MODULATE); lightingPass->setLightingEnabled(false); Ogre::TextureUnitState * textureUnitStateSplat = lightingPass->createTextureUnitState(); //we need an unique name for our alpha texture std::stringstream lightingTextureNameSS; lightingTextureNameSS << technique->getParent()->getName() << "_lighting"; const Ogre::String lightingTextureName(lightingTextureNameSS.str()); Ogre::TexturePtr texture = static_cast<Ogre::TexturePtr>(Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(lightingTextureName)); if (texture.isNull()) { texture = Ogre::Root::getSingletonPtr()->getTextureManager()->createManual(lightingTextureName, "General", Ogre::TEX_TYPE_2D, mPage.getBlendMapSize(), mPage.getBlendMapSize(), 1, Ogre::PF_L8, Ogre::TU_DYNAMIC_WRITE_ONLY); managedTextures.insert(texture->getName()); } Ogre::Image ogreImage; ogreImage.loadDynamicImage(const_cast<unsigned char*>(mLightingImage->getData()), mLightingImage->getResolution(), mLightingImage->getResolution(), 1, Ogre::PF_L8); texture->loadImage(ogreImage); //blit the whole image to the hardware buffer Ogre::PixelBox sourceBox(ogreImage.getPixelBox()); //blit for each mipmap for (unsigned int i = 0; i <= texture->getNumMipmaps(); ++i) { Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(texture->getBuffer(0, i)); hardwareBuffer->blitFromMemory(sourceBox); } textureUnitStateSplat->setTextureName(texture->getName()); textureUnitStateSplat->setTextureCoordSet(0); textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP); textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC); }
void GlobalMap::read(ESM::GlobalMap& map) { const ESM::GlobalMap::Bounds& bounds = map.mBounds; if (bounds.mMaxX-bounds.mMinX < 0) return; if (bounds.mMaxY-bounds.mMinY < 0) return; if (bounds.mMinX > bounds.mMaxX || bounds.mMinY > bounds.mMaxY) throw std::runtime_error("invalid map bounds"); Ogre::Image image; Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&map.mImageData[0], map.mImageData.size())); image.load(stream, "png"); int xLength = (bounds.mMaxX-bounds.mMinX+1); int yLength = (bounds.mMaxY-bounds.mMinY+1); // Size of one cell in image space int cellImageSizeSrc = image.getWidth() / xLength; if (int(image.getHeight() / yLength) != cellImageSizeSrc) throw std::runtime_error("cell size must be quadratic"); // If cell bounds of the currently loaded content and the loaded savegame do not match, // we need to resize source/dest boxes to accommodate // This means nonexisting cells will be dropped silently int cellImageSizeDst = mCellSize; // Completely off-screen? -> no need to blit anything if (bounds.mMaxX < mMinX || bounds.mMaxY < mMinY || bounds.mMinX > mMaxX || bounds.mMinY > mMaxY) return; int leftDiff = (mMinX - bounds.mMinX); int topDiff = (bounds.mMaxY - mMaxY); int rightDiff = (bounds.mMaxX - mMaxX); int bottomDiff = (mMinY - bounds.mMinY); Ogre::Image::Box srcBox ( std::max(0, leftDiff * cellImageSizeSrc), std::max(0, topDiff * cellImageSizeSrc), std::min(image.getWidth(), image.getWidth() - rightDiff * cellImageSizeSrc), std::min(image.getHeight(), image.getHeight() - bottomDiff * cellImageSizeSrc)); Ogre::Image::Box destBox ( std::max(0, -leftDiff * cellImageSizeDst), std::max(0, -topDiff * cellImageSizeDst), std::min(mOverlayTexture->getWidth(), mOverlayTexture->getWidth() + rightDiff * cellImageSizeDst), std::min(mOverlayTexture->getHeight(), mOverlayTexture->getHeight() + bottomDiff * cellImageSizeDst)); // Looks like there is no interface for blitting from memory with src/dst boxes. // So we create a temporary texture for blitting. Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().createManual("@temp", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, image.getWidth(), image.getHeight(), 0, Ogre::PF_A8B8G8R8); tex->loadImage(image); mOverlayTexture->load(); mOverlayTexture->getBuffer()->blit(tex->getBuffer(), srcBox, destBox); if (srcBox.left == destBox.left && srcBox.right == destBox.right && srcBox.top == destBox.top && srcBox.bottom == destBox.bottom && int(image.getWidth()) == mWidth && int(image.getHeight()) == mHeight) mOverlayImage = image; else mOverlayTexture->convertToImage(mOverlayImage); Ogre::TextureManager::getSingleton().remove("@temp"); }
void SaveGameDialog::onSlotSelected(MyGUI::ListBox *sender, size_t pos) { if (pos == MyGUI::ITEM_NONE) { mCurrentSlot = NULL; mInfoText->setCaption(""); mScreenshot->setImageTexture(""); return; } if (mSaving) mSaveNameEdit->setCaption(sender->getItemNameAt(pos)); mCurrentSlot = NULL; unsigned int i=0; for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end(); ++it, ++i) { if (i == pos) mCurrentSlot = &*it; } assert(mCurrentSlot && "Can't find selected slot"); std::stringstream text; time_t time = mCurrentSlot->mTimeStamp; struct tm* timeinfo; timeinfo = localtime(&time); // Use system/environment locale settings for datetime formatting setlocale(LC_TIME, ""); const int size=1024; char buffer[size]; if (std::strftime(buffer, size, "%x %X", timeinfo) > 0) text << buffer << "\n"; text << "Level " << mCurrentSlot->mProfile.mPlayerLevel << "\n"; text << mCurrentSlot->mProfile.mPlayerCell << "\n"; // text << "Time played: " << slot->mProfile.mTimePlayed << "\n"; int hour = int(mCurrentSlot->mProfile.mInGameTime.mGameHour); bool pm = hour >= 12; if (hour >= 13) hour -= 12; if (hour == 0) hour = 12; text << mCurrentSlot->mProfile.mInGameTime.mDay << " " << MWBase::Environment::get().getWorld()->getMonthName(mCurrentSlot->mProfile.mInGameTime.mMonth) << " " << hour << " " << (pm ? "#{sSaveMenuHelp05}" : "#{sSaveMenuHelp04}"); mInfoText->setCaptionWithReplacing(text.str()); // Decode screenshot std::vector<char> data = mCurrentSlot->mProfile.mScreenshot; // MemoryDataStream doesn't work with const data :( Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&data[0], data.size())); Ogre::Image image; image.load(stream, "jpg"); const std::string textureName = "@savegame_screenshot"; Ogre::TexturePtr texture; texture = Ogre::TextureManager::getSingleton().getByName(textureName); mScreenshot->setImageTexture(""); if (texture.isNull()) { texture = Ogre::TextureManager::getSingleton().createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, image.getWidth(), image.getHeight(), 0, Ogre::PF_BYTE_RGBA, Ogre::TU_DYNAMIC_WRITE_ONLY); } texture->unload(); texture->setWidth(image.getWidth()); texture->setHeight(image.getHeight()); texture->loadImage(image); mScreenshot->setImageTexture(textureName); }
void FontLoader::loadFont(const std::string &fileName, bool exportToFile) { Ogre::DataStreamPtr file = Ogre::ResourceGroupManager::getSingleton().openResource(fileName); float fontSize; int one; file->read(&fontSize, sizeof(fontSize)); file->read(&one, sizeof(int)); assert(one == 1); file->read(&one, sizeof(int)); assert(one == 1); char name_[284]; file->read(name_, sizeof(name_)); std::string name(name_); GlyphInfo data[256]; file->read(data, sizeof(data)); file->close(); // Create the font texture std::string bitmapFilename = "Fonts/" + std::string(name) + ".tex"; Ogre::DataStreamPtr bitmapFile = Ogre::ResourceGroupManager::getSingleton().openResource(bitmapFilename); int width, height; bitmapFile->read(&width, sizeof(int)); bitmapFile->read(&height, sizeof(int)); std::vector<Ogre::uchar> textureData; textureData.resize(width*height*4); bitmapFile->read(&textureData[0], width*height*4); bitmapFile->close(); std::string resourceName; if (name.size() >= 5 && Misc::StringUtils::ciEqual(name.substr(0, 5), "magic")) resourceName = "Magic Cards"; else if (name.size() >= 7 && Misc::StringUtils::ciEqual(name.substr(0, 7), "century")) resourceName = "Century Gothic"; else if (name.size() >= 7 && Misc::StringUtils::ciEqual(name.substr(0, 7), "daedric")) resourceName = "Daedric"; else return; // no point in loading it, since there is no way of using additional fonts std::string textureName = name; Ogre::Image image; image.loadDynamicImage(&textureData[0], width, height, Ogre::PF_BYTE_RGBA); Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_BYTE_RGBA); texture->loadImage(image); if (exportToFile) image.save(resourceName + ".png"); // Register the font with MyGUI MyGUI::ResourceManualFont* font = static_cast<MyGUI::ResourceManualFont*>( MyGUI::FactoryManager::getInstance().createObject("Resource", "ResourceManualFont")); // We need to emulate loading from XML because the data members are private as of mygui 3.2.0 MyGUI::xml::Document xmlDocument; MyGUI::xml::ElementPtr root = xmlDocument.createRoot("ResourceManualFont"); root->addAttribute("name", resourceName); MyGUI::xml::ElementPtr defaultHeight = root->createChild("Property"); defaultHeight->addAttribute("key", "DefaultHeight"); defaultHeight->addAttribute("value", fontSize); MyGUI::xml::ElementPtr source = root->createChild("Property"); source->addAttribute("key", "Source"); source->addAttribute("value", std::string(textureName)); MyGUI::xml::ElementPtr codes = root->createChild("Codes"); for(int i = 0; i < 256; i++) { float x1 = data[i].top_left.x*width; float y1 = data[i].top_left.y*height; float w = data[i].top_right.x*width - x1; float h = data[i].bottom_left.y*height - y1; ToUTF8::Utf8Encoder encoder(mEncoding); unsigned long unicodeVal = utf8ToUnicode(getUtf8(i, encoder, mEncoding)); MyGUI::xml::ElementPtr code = codes->createChild("Code"); code->addAttribute("index", unicodeVal); code->addAttribute("coord", MyGUI::utility::toString(x1) + " " + MyGUI::utility::toString(y1) + " " + MyGUI::utility::toString(w) + " " + MyGUI::utility::toString(h)); code->addAttribute("advance", data[i].width); code->addAttribute("bearing", MyGUI::utility::toString(data[i].kerning) + " " + MyGUI::utility::toString((fontSize-data[i].ascent))); code->addAttribute("size", MyGUI::IntSize(data[i].width, data[i].height)); // More hacks! The french game uses several win1252 characters that are not included // in the cp437 encoding of the font. Fall back to similar available characters. if (mEncoding == ToUTF8::CP437) { std::multimap<int, int> additional; // <cp437, unicode> additional.insert(std::make_pair(39, 0x2019)); // apostrophe additional.insert(std::make_pair(45, 0x2013)); // dash additional.insert(std::make_pair(45, 0x2014)); // dash additional.insert(std::make_pair(34, 0x201D)); // right double quotation mark additional.insert(std::make_pair(34, 0x201C)); // left double quotation mark additional.insert(std::make_pair(44, 0x201A)); additional.insert(std::make_pair(44, 0x201E)); additional.insert(std::make_pair(43, 0x2020)); additional.insert(std::make_pair(94, 0x02C6)); additional.insert(std::make_pair(37, 0x2030)); additional.insert(std::make_pair(83, 0x0160)); additional.insert(std::make_pair(60, 0x2039)); additional.insert(std::make_pair(79, 0x0152)); additional.insert(std::make_pair(90, 0x017D)); additional.insert(std::make_pair(39, 0x2019)); additional.insert(std::make_pair(126, 0x02DC)); additional.insert(std::make_pair(84, 0x2122)); additional.insert(std::make_pair(83, 0x0161)); additional.insert(std::make_pair(62, 0x203A)); additional.insert(std::make_pair(111, 0x0153)); additional.insert(std::make_pair(122, 0x017E)); additional.insert(std::make_pair(89, 0x0178)); additional.insert(std::make_pair(156, 0x00A2)); additional.insert(std::make_pair(46, 0x2026)); for (std::multimap<int, int>::iterator it = additional.begin(); it != additional.end(); ++it) { if (it->first != i) continue; MyGUI::xml::ElementPtr code = codes->createChild("Code"); code->addAttribute("index", it->second); code->addAttribute("coord", MyGUI::utility::toString(x1) + " " + MyGUI::utility::toString(y1) + " " + MyGUI::utility::toString(w) + " " + MyGUI::utility::toString(h)); code->addAttribute("advance", data[i].width); code->addAttribute("bearing", MyGUI::utility::toString(data[i].kerning) + " " + MyGUI::utility::toString((fontSize-data[i].ascent))); code->addAttribute("size", MyGUI::IntSize(data[i].width, data[i].height)); } } // ASCII vertical bar, use this as text input cursor if (i == 124) { MyGUI::xml::ElementPtr cursorCode = codes->createChild("Code"); cursorCode->addAttribute("index", MyGUI::FontCodeType::Cursor); cursorCode->addAttribute("coord", MyGUI::utility::toString(x1) + " " + MyGUI::utility::toString(y1) + " " + MyGUI::utility::toString(w) + " " + MyGUI::utility::toString(h)); cursorCode->addAttribute("advance", data[i].width); cursorCode->addAttribute("bearing", MyGUI::utility::toString(data[i].kerning) + " " + MyGUI::utility::toString((fontSize-data[i].ascent))); cursorCode->addAttribute("size", MyGUI::IntSize(data[i].width, data[i].height)); } // Question mark, use for NotDefined marker (used for glyphs not existing in the font) if (i == 63) { MyGUI::xml::ElementPtr cursorCode = codes->createChild("Code"); cursorCode->addAttribute("index", MyGUI::FontCodeType::NotDefined); cursorCode->addAttribute("coord", MyGUI::utility::toString(x1) + " " + MyGUI::utility::toString(y1) + " " + MyGUI::utility::toString(w) + " " + MyGUI::utility::toString(h)); cursorCode->addAttribute("advance", data[i].width); cursorCode->addAttribute("bearing", MyGUI::utility::toString(data[i].kerning) + " " + MyGUI::utility::toString((fontSize-data[i].ascent))); cursorCode->addAttribute("size", MyGUI::IntSize(data[i].width, data[i].height)); } } // These are required as well, but the fonts don't provide them for (int i=0; i<2; ++i) { MyGUI::FontCodeType::Enum type; if(i == 0) type = MyGUI::FontCodeType::Selected; else if (i == 1) type = MyGUI::FontCodeType::SelectedBack; MyGUI::xml::ElementPtr cursorCode = codes->createChild("Code"); cursorCode->addAttribute("index", type); cursorCode->addAttribute("coord", "0 0 0 0"); cursorCode->addAttribute("advance", "0"); cursorCode->addAttribute("bearing", "0 0"); cursorCode->addAttribute("size", "0 0"); } if (exportToFile) { xmlDocument.createDeclaration(); xmlDocument.save(resourceName + ".xml"); } font->deserialization(root, MyGUI::Version(3,2,0)); MyGUI::ResourceManager::getInstance().removeByName(font->getResourceName()); MyGUI::ResourceManager::getInstance().addResource(font); }
// void TerrainPageSurfaceCompiler::addTextureUnitsToPass(Ogre::Pass* pass, const Ogre::String& splatTextureName) { // // if (getMaxTextureUnits() - pass->getNumTextureUnitStates() < 2 || pass->getParent()->getNumPasses() > 1) { // addPassToTechnique(pass->getParent(), splatTextureName); // // S_LOG_WARNING("Trying to add texture units to pass with too few available texture unit states."); // return; // } // // S_LOG_VERBOSE("Adding new texture unit (detailtexture: " << mTextureName << " alphatexture: " << splatTextureName << ") to pass nr " << pass->getIndex() << " in technique for material " << pass->getParent()->getParent()->getName()); // // /* pass->setSelfIllumination(Ogre::ColourValue(1,1,1)); // pass->setAmbient(Ogre::ColourValue(1,1,1)); // pass->setDiffuse(Ogre::ColourValue(1,1,1)); // pass->setLightingEnabled(true);*/ // Ogre::TextureUnitState * textureUnitStateSplat = pass->createTextureUnitState(); // textureUnitStateSplat->setTextureName(splatTextureName); // // textureUnitStateSplat->setTextureCoordSet(0); // textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC); // textureUnitStateSplat->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE); // textureUnitStateSplat->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT); // textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP); // // textureUnitStateSplat->setColourOperationEx(Ogre::LBX_BLEND_DIFFUSE_ALPHA, Ogre::LBS_CURRENT, Ogre::LBS_TEXTURE); // // textureUnitStateSplat->setColourOperationEx(Ogre::LBX_BLEND_TEXTURE_ALPHA, Ogre::LBS_CURRENT, Ogre::LBS_TEXTURE); // // Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState(); // textureUnitState->setTextureName(mTextureName); // textureUnitState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP); // /* textureUnitState->setTextureCoordSet(0);*/ // textureUnitState->setTextureScale(0.025, 0.025); // textureUnitState->setColourOperationEx(Ogre::LBX_BLEND_CURRENT_ALPHA, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT); // // /* Ogre::TextureUnitState * alphaTextureState= pass->createTextureUnitState(); // alphaTextureState->setTextureName(mTextureName); // // alphaTextureState->setTextureName(splatTextureName); // alphaTextureState->setTextureCoordSet(0); // alphaTextureState->setTextureFiltering(Ogre::TFO_ANISOTROPIC); // alphaTextureState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP); // alphaTextureState->setColourOperationEx(Ogre::LBX_BLEND_DIFFUSE_ALPHA, Ogre::LBS_CURRENT, Ogre::LBS_TEXTURE); // // // // // detailTextureState->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE); // // detailTextureState->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT); // // Ogre::TextureUnitState * detailTextureState = pass->createTextureUnitState(); // detailTextureState ->setTextureName(splatTextureName); // // detailTextureState ->setTextureName(mTextureName); // detailTextureState ->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP); // detailTextureState ->setTextureCoordSet(0); // detailTextureState ->setTextureScale(0.01, 0.01); // //detailTextureState ->setColourOperationEx(Ogre::LBX_BLEND_CURRENT_ALPHA, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT);*/ // // } // Ogre::Pass* Simple::addPassToTechnique(const TerrainPageGeometry& geometry, Ogre::Technique* technique, const Layer& layer, std::set<std::string>& managedTextures) const { //check if we instead can reuse the existing pass // if (technique->getNumPasses() != 0) { // Ogre::Pass* pass = technique->getPass(technique->getNumPasses() - 1); // if (4 - pass->getNumTextureUnitStates() >= 2) { // //there's more than two texture units available, use those instead of creating a new pass // S_LOG_VERBOSE("Reusing existing pass. ("<< pass->getNumTextureUnitStates() << " of "<< mNumberOfTextureUnitsOnCard << " texture unit used)"); // addTextureUnitsToPass(pass, splatTextureName); // return pass; // } // // } const OgreImage& ogreImage = *layer.blendMap; Ogre::Image image; image.loadDynamicImage(const_cast<unsigned char*>(ogreImage.getData()), ogreImage.getResolution(), ogreImage.getResolution(), 1, Ogre::PF_A8); std::stringstream splatTextureNameSS; splatTextureNameSS << "terrain_" << mPage.getWFPosition().x() << "_" << mPage.getWFPosition().y() << "_" << technique->getNumPasses(); const Ogre::String splatTextureName(splatTextureNameSS.str()); Ogre::TexturePtr blendMapTexture; if (Ogre::Root::getSingletonPtr()->getTextureManager()->resourceExists(splatTextureName)) { blendMapTexture = static_cast<Ogre::TexturePtr>(Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(splatTextureName)); blendMapTexture->loadImage(image); Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(blendMapTexture->getBuffer()); //blit the whole image to the hardware buffer Ogre::PixelBox sourceBox(image.getPixelBox()); hardwareBuffer->blitFromMemory(sourceBox); } else { blendMapTexture = Ogre::Root::getSingletonPtr()->getTextureManager()->loadImage(splatTextureName, "General", image, Ogre::TEX_TYPE_2D, 0); managedTextures.insert(blendMapTexture->getName()); } //we need to create the image, update it and then destroy it again (to keep the memory usage down) // if (layer->getBlendMapTextureName() == "") { // //no texture yet; let's create one // layer->createBlendMapImage(); // layer->updateBlendMapImage(geometry); // layer->createTexture(); // } else { // //a texture exists, so we just need to update the image // layer->updateBlendMapImage(geometry); //calling this will also update the texture since the method will blit the image onto it // } Ogre::Pass* pass = technique->createPass(); pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); pass->setAmbient(1, 1, 1); pass->setDiffuse(1, 1, 1, 1); pass->setLightingEnabled(false); Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState(); textureUnitState->setTextureName(layer.surfaceLayer.getDiffuseTextureName()); textureUnitState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP); textureUnitState->setTextureCoordSet(0); textureUnitState->setTextureScale(1.0f / layer.surfaceLayer.getScale(), 1.0f / layer.surfaceLayer.getScale()); Ogre::TextureUnitState * textureUnitStateSplat = pass->createTextureUnitState(); textureUnitStateSplat->setTextureName(blendMapTexture->getName()); textureUnitStateSplat->setTextureCoordSet(0); textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP); textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC); // textureUnitStateSplat->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE); textureUnitStateSplat->setAlphaOperation(Ogre::LBX_BLEND_DIFFUSE_COLOUR, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT); textureUnitStateSplat->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT); return pass; }