// ------------------------------------------------------------------------------------------------ void LWOImporter::LoadLWO2TextureBlock(LE_NCONST IFF::SubChunkHeader* head, unsigned int size ) { ai_assert(!mSurfaces->empty()); LWO::Surface& surf = mSurfaces->back(); LWO::Texture tex; // load the texture header LoadLWO2TextureHeader(head->length,tex); size -= head->length + 6; // now get the exact type of the texture switch (head->type) { case AI_LWO_PROC: LoadLWO2Procedural(size,tex); break; case AI_LWO_GRAD: LoadLWO2Gradient(size,tex); break; case AI_LWO_IMAP: LoadLWO2ImageMap(size,tex); } // get the destination channel TextureList* listRef = NULL; switch (tex.type) { case AI_LWO_COLR: listRef = &surf.mColorTextures;break; case AI_LWO_DIFF: listRef = &surf.mDiffuseTextures;break; case AI_LWO_SPEC: listRef = &surf.mSpecularTextures;break; case AI_LWO_GLOS: listRef = &surf.mGlossinessTextures;break; case AI_LWO_BUMP: listRef = &surf.mBumpTextures;break; case AI_LWO_TRAN: listRef = &surf.mOpacityTextures;break; case AI_LWO_REFL: listRef = &surf.mReflectionTextures;break; default: DefaultLogger::get()->warn("LWO2: Encountered unknown texture type"); return; } // now attach the texture to the parent surface - sort by ordinal string for (TextureList::iterator it = listRef->begin();it != listRef->end(); ++it) { if (::strcmp(tex.ordinal.c_str(),(*it).ordinal.c_str()) < 0) { listRef->insert(it,tex); return; } } listRef->push_back(tex); }
//--------------------------------------------------------------------- TexturePtr CompositorManager::getPooledTexture(const String& name, const String& localName, size_t w, size_t h, PixelFormat f, uint aa, const String& aaHint, bool srgb, CompositorManager::UniqueTextureSet& texturesAssigned, CompositorInstance* inst, CompositionTechnique::TextureScope scope) { if (scope == CompositionTechnique::TS_GLOBAL) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Global scope texture can not be pooled.", "CompositorManager::getPooledTexture"); } TextureDef def(w, h, f, aa, aaHint, srgb); if (scope == CompositionTechnique::TS_CHAIN) { StringPair pair = std::make_pair(inst->getCompositor()->getName(), localName); TextureDefMap& defMap = mChainTexturesByDef[pair]; TextureDefMap::iterator it = defMap.find(def); if (it != defMap.end()) { return it->second; } // ok, we need to create a new one TexturePtr newTex = TextureManager::getSingleton().createManual( name, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME, TEX_TYPE_2D, (uint)w, (uint)h, 0, f, TU_RENDERTARGET, 0, srgb, aa, aaHint); defMap.insert(TextureDefMap::value_type(def, newTex)); return newTex; } TexturesByDef::iterator i = mTexturesByDef.find(def); if (i == mTexturesByDef.end()) { TextureList* texList = OGRE_NEW_T(TextureList, MEMCATEGORY_GENERAL); i = mTexturesByDef.insert(TexturesByDef::value_type(def, texList)).first; } CompositorInstance* previous = inst->getChain()->getPreviousInstance(inst); CompositorInstance* next = inst->getChain()->getNextInstance(inst); TexturePtr ret; TextureList* texList = i->second; // iterate over the existing textures and check if we can re-use for (TextureList::iterator t = texList->begin(); t != texList->end(); ++t) { TexturePtr& tex = *t; // check not already used if (texturesAssigned.find(tex.get()) == texturesAssigned.end()) { bool allowReuse = true; // ok, we didn't use this one already // however, there is an edge case where if we re-use a texture // which has an 'input previous' pass, and it is chained from another // compositor, we can end up trying to use the same texture for both // so, never allow a texture with an input previous pass to be // shared with its immediate predecessor in the chain if (isInputPreviousTarget(inst, localName)) { // Check whether this is also an input to the output target of previous // can't use CompositorInstance::mPreviousInstance, only set up // during compile if (previous && isInputToOutputTarget(previous, tex)) allowReuse = false; } // now check the other way around since we don't know what order they're bound in if (isInputToOutputTarget(inst, localName)) { if (next && isInputPreviousTarget(next, tex)) allowReuse = false; } if (allowReuse) { ret = tex; break; } } } if (ret.isNull()) { // ok, we need to create a new one ret = TextureManager::getSingleton().createManual( name, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME, TEX_TYPE_2D, (uint)w, (uint)h, 0, f, TU_RENDERTARGET, 0, srgb, aa, aaHint); texList->push_back(ret); } // record that we used this one in the requester's list texturesAssigned.insert(ret.get()); return ret; }
double GraphicsEntity::Render( TextureList& out, float frameTime, AnimSpeed speed ) { if( !Active() ) return 0.; // Shouldn't happen; inactive doesn't collide with camera const size_t layCount = m_Layers.Size(); if( layCount == 0 ) return 0.; std::vector<GraphCompLoc> layers; RSKMAP_ITERATE( m_Layers ) layers.push_back( iter->first ); if( layCount > 1 ) { // // Basic loc value sorting to maintain layer consistency GraphCompLoc nll, naa; for( size_t lll = layCount-1; lll < layCount; --lll ) { nll = layers[lll]; for( size_t aaa = lll-1; aaa < layCount; --aaa ) { naa = layers[aaa]; if( naa < nll ) { layers[lll] = naa; layers[aaa] = nll; nll = naa; } } } if( m_HaveOffset && mp_Sort ) { // // At least one loc has an offset, so sort by loc offset size_t lll, aaa; GraphCompLoc mll; int ox, oy, oz, aox, aoy, aoz; for( lll = 0; lll < layCount; ++lll ) { nll = layers[lll]; const rsk::Vector3I& offset = m_Offsets[nll]; ox = offset.x; oy = offset.y; oz = offset.z; for( aaa = lll+1; aaa < layCount; ++aaa ) { naa = layers[aaa]; const rsk::Vector3I& offset = m_Offsets[naa]; aox = offset.x; aoy = offset.y; aoz = offset.z; mll = mp_Sort( nll, naa, ox, oy, oz, aox, aoy, aoz ); if( mll != nll ) { layers[lll] = mll; layers[aaa] = nll; nll = mll; ox = aox; oy = aoy; oz = aoz; } } } // for lll } // if have offset } // if layCount > 1 // // Commit the layers to be rendered for( size_t lll = layCount-1; lll < layCount; --lll ) out.push_back( m_Layers[ layers[lll] ]->Render(frameTime, speed) ); return m_Rotation; }