LLUUID get(LLViewerObject* object, S32 te_index) { LLUUID id; LLViewerTexture* image = object->getTEImage(te_index); if (image) id = image->getID(); if (!id.isNull() && LLViewerMedia::textureHasMedia(id)) { LLTextureEntry *te = object->getTE(te_index); if (te) { LLViewerTexture* tex = te->getID().notNull() ? gTextureList.findImage(te->getID()) : NULL ; if(!tex) { tex = LLViewerFetchedTexture::sDefaultImagep; } if (tex) { id = tex->getID(); } } } return id; }
LLUUID LLViewerPartSource::getImageUUID() const { LLViewerTexture* imagep = mImagep; if(imagep) { return imagep->getID(); } return LLUUID::null; }
LLVOClouds::LLVOClouds(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) : LLAlphaObject(id, LL_VO_CLOUDS, regionp) { mCloudGroupp = NULL; mbCanSelect = FALSE; setNumTEs(1); LLViewerTexture* image = LLViewerTextureManager::getFetchedTexture(gCloudTextureID); image->setBoostLevel(LLViewerTexture::BOOST_CLOUDS); setTEImage(0, image); }
void LLObjectBackup::exportNextTexture() { if (mTexturesList.empty()) { llinfos << "Finished exporting textures." << llendl; return; } LLUUID id; std::list<LLUUID>::iterator iter; iter = mTexturesList.begin(); while (1) { if (iter == mTexturesList.end()) { mNextTextureReady = true; return; } id = (*iter); LLViewerTexture* imagep = LLViewerTextureManager::findTexture(id); if (imagep != NULL) { S32 cur_discard = imagep->getDiscardLevel(); if (cur_discard > 0) { if (imagep->getBoostLevel() != LLViewerTexture::BOOST_PREVIEW) { // we want to force discard 0: this one does this. imagep->setBoostLevel(LLViewerTexture::BOOST_PREVIEW); } } else { break; } } else { llwarns << "We *DON'T* have the texture " << llendl; mNonExportedTextures |= TEXTURE_MISSING; } iter++; } mTexturesList.remove(id); llinfos << "Requesting texture " << id << llendl; LLImageJ2C* mFormattedImage = new LLImageJ2C; CacheReadResponder* responder = new CacheReadResponder(id, mFormattedImage); LLAppViewer::getTextureCache()->readFromCache(id, LLWorkerThread::PRIORITY_HIGH, 0, 999999, responder); }
// Updates asset from the user's avatar void LLWearable::readFromAvatar() { LLVOAvatar* avatar = gAgent.getAvatarObject(); llassert( avatar ); if( !avatar ) { return; } mDefinitionVersion = LLWearable::sCurrentDefinitionVersion; mVisualParamMap.clear(); for( LLVisualParam* param = avatar->getFirstVisualParam(); param; param = avatar->getNextVisualParam() ) { if( (((LLViewerVisualParam*)param)->getWearableType() == mType) && (param->isTweakable()) ) { //pretty sure is right if(param->getID() == 507) avatar->setActualBoobGrav(param->getWeight()); /*if(param->getID() == 151) avatar->setActualButtGrav(param->getWeight()); if(param->getID() == 157) avatar->setActualFatGrav(param->getWeight()); */ //if(param->getID() == 507) //{ // llwarns << "current = " << avatar->getActualBoobGrav() << llendl; // llwarns << "param weight = " << param->getWeight() << llendl; //} mVisualParamMap[param->getID()] = param->getWeight(); } } mTEMap.clear(); for( S32 te = 0; te < TEX_NUM_INDICES; te++ ) { if( LLVOAvatar::getTEWearableType((ETextureIndex) te ) == mType ) { LLViewerTexture* image = avatar->getTEImage( te ); if( image ) { mTEMap[te] = image->getID(); } } } //if( gFloaterCustomize ) //{ // mDescription = gFloaterCustomize->getWearableDescription( mType ); //} }
// Note: the caller SHOULD NOT keep the pointer that this function returns. It may be updated as more data arrives. LLViewerTexture* LLBumpImageList::getBrightnessDarknessImage(LLViewerFetchedTexture* src_image, U8 bump_code ) { llassert( (bump_code == BE_BRIGHTNESS) || (bump_code == BE_DARKNESS) ); LLViewerTexture* bump = NULL; bump_image_map_t* entries_list = NULL; void (*callback_func)( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata ) = NULL; switch( bump_code ) { case BE_BRIGHTNESS: entries_list = &mBrightnessEntries; callback_func = LLBumpImageList::onSourceBrightnessLoaded; break; case BE_DARKNESS: entries_list = &mDarknessEntries; callback_func = LLBumpImageList::onSourceDarknessLoaded; break; default: llassert(0); return NULL; } bump_image_map_t::iterator iter = entries_list->find(src_image->getID()); if (iter != entries_list->end() && iter->second.notNull()) { bump = iter->second; } else { LLPointer<LLImageRaw> raw = new LLImageRaw(1,1,1); raw->clear(0x77, 0x77, 0xFF, 0xFF); (*entries_list)[src_image->getID()] = LLViewerTextureManager::getLocalTexture( raw.get(), TRUE); bump = (*entries_list)[src_image->getID()]; // In case callback was called immediately and replaced the image } if (!src_image->hasCallbacks()) { //if image has no callbacks but resolutions don't match, trigger raw image loaded callback again if (src_image->getWidth() != bump->getWidth() || src_image->getHeight() != bump->getHeight())// || //(LLPipeline::sRenderDeferred && bump->getComponents() != 4)) { src_image->setBoostLevel(LLGLTexture::BOOST_BUMP) ; src_image->setLoadedCallback( callback_func, 0, TRUE, FALSE, new LLUUID(src_image->getID()), NULL ); src_image->forceToSaveRawImage(0) ; } } return bump; }
void LLBumpImageList::updateImages() { llpushcallstacks ; for (bump_image_map_t::iterator iter = mBrightnessEntries.begin(); iter != mBrightnessEntries.end(); ) { bump_image_map_t::iterator curiter = iter++; LLViewerTexture* image = curiter->second; if( image ) { BOOL destroy = TRUE; if( image->hasGLTexture()) { if( image->getBoundRecently() ) { destroy = FALSE; } else { image->destroyGLTexture(); } } if( destroy ) { //llinfos << "*** Destroying bright " << (void*)image << llendl; mBrightnessEntries.erase(curiter); // deletes the image thanks to reference counting } } } llpushcallstacks ; for (bump_image_map_t::iterator iter = mDarknessEntries.begin(); iter != mDarknessEntries.end(); ) { bump_image_map_t::iterator curiter = iter++; LLViewerTexture* image = curiter->second; if( image ) { BOOL destroy = TRUE; if( image->hasGLTexture()) { if( image->getBoundRecently() ) { destroy = FALSE; } else { image->destroyGLTexture(); } } if( destroy ) { //llinfos << "*** Destroying dark " << (void*)image << llendl;; mDarknessEntries.erase(curiter); // deletes the image thanks to reference counting } } } llpushcallstacks ; }
void LLVOTextBubble::updateTextures() { // Update the image levels of all textures... for (U32 i = 0; i < getNumTEs(); i++) { const LLTextureEntry *te = getTE(i); F32 texel_area_ratio = fabs(te->mScaleS * te->mScaleT); texel_area_ratio = llclamp(texel_area_ratio, .125f, 16.f); LLViewerTexture *imagep = getTEImage(i); if (imagep) { imagep->addTextureStats(mPixelArea / texel_area_ratio); } } }
// static void LLTexLayerParamAlpha::getCacheByteCount(S32* gl_bytes) { *gl_bytes = 0; for (param_alpha_ptr_list_t::iterator iter = sInstances.begin(); iter != sInstances.end(); iter++) { LLTexLayerParamAlpha* instance = *iter; LLViewerTexture* tex = instance->mCachedProcessedTexture; if (tex) { S32 bytes = (S32)tex->getWidth() * tex->getHeight() * tex->getComponents(); if (tex->hasGLTexture()) { *gl_bytes += bytes; } } } }
BOOL LLToolTexEyedropper::handleMouseDown(S32 x, S32 y, MASK mask) { // this will affect framerate on mouse down const LLPickInfo& pick = gViewerWindow->pickImmediate(x, y, FALSE); LLViewerObject* hit_obj = pick.getObject(); if (hit_obj && !hit_obj->isAvatar()) { if( (0 <= pick.mObjectFace) && (pick.mObjectFace < hit_obj->getNumTEs()) ) { LLViewerTexture* image = hit_obj->getTEImage( pick.mObjectFace ); if( image ) { if( mCallback ) { mCallback( hit_obj->getID(), image->getID(), mCallbackUserData ); } } } } return TRUE; }
void LLDrawPoolAvatar::renderRigged(LLVOAvatar* avatar, U32 type, bool glow) { if ((avatar->isSelf() && !gAgent.needsRenderAvatar()) || !gMeshRepo.meshRezEnabled()) { return; } stop_glerror(); for (U32 i = 0; i < mRiggedFace[type].size(); ++i) { LLFace* face = mRiggedFace[type][i]; LLDrawable* drawable = face->getDrawable(); if (!drawable) { continue; } LLVOVolume* vobj = drawable->getVOVolume(); if (!vobj) { continue; } LLVolume* volume = vobj->getVolume(); S32 te = face->getTEOffset(); if (!volume || volume->getNumVolumeFaces() <= te || !volume->isMeshAssetLoaded()) { continue; } LLUUID mesh_id = volume->getParams().getSculptID(); if (mesh_id.isNull()) { continue; } const LLMeshSkinInfo* skin = gMeshRepo.getSkinInfo(mesh_id, vobj); if (!skin) { continue; } //stop_glerror(); //const LLVolumeFace& vol_face = volume->getVolumeFace(te); //updateRiggedFaceVertexBuffer(avatar, face, skin, volume, vol_face); //stop_glerror(); U32 data_mask = LLFace::getRiggedDataMask(type); LLVertexBuffer* buff = face->getVertexBuffer(); if (buff) { if (sShaderLevel > 0) { //upload matrix palette to shader LLMatrix4 mat[JOINT_COUNT]; U32 count = llmin((U32) skin->mJointNames.size(), (U32) JOINT_COUNT); for (U32 i = 0; i < count; ++i) { LLJoint* joint = avatar->getJoint(skin->mJointNames[i]); if(!joint) { joint = avatar->getJoint("mRoot"); } if (joint) { LLMatrix4a tmp; tmp.loadu((F32*)skin->mInvBindMatrix[i].mMatrix); tmp.setMul(joint->getWorldMatrix(),tmp); mat[i] = LLMatrix4(tmp.getF32ptr()); } } stop_glerror(); F32 mp[JOINT_COUNT*12]; for (U32 i = 0; i < count; ++i) { F32* m = (F32*) mat[i].mMatrix; U32 idx = i*12; mp[idx+0] = m[0]; mp[idx+1] = m[1]; mp[idx+2] = m[2]; mp[idx+3] = m[12]; mp[idx+4] = m[4]; mp[idx+5] = m[5]; mp[idx+6] = m[6]; mp[idx+7] = m[13]; mp[idx+8] = m[8]; mp[idx+9] = m[9]; mp[idx+10] = m[10]; mp[idx+11] = m[14]; } LLDrawPoolAvatar::sVertexProgram->uniformMatrix3x4fv(LLViewerShaderMgr::AVATAR_MATRIX, count, FALSE, (GLfloat*) mp); LLDrawPoolAvatar::sVertexProgram->uniform1f(LLShaderMgr::AVATAR_MAX_WEIGHT, F32(count-1)); stop_glerror(); } else { data_mask &= ~LLVertexBuffer::MAP_WEIGHT4; } U16 start = face->getGeomStart(); U16 end = start + face->getGeomCount()-1; S32 offset = face->getIndicesStart(); U32 count = face->getIndicesCount(); /*if (glow) { gGL.diffuseColor4f(0,0,0,face->getTextureEntry()->getGlow()); }*/ const LLTextureEntry* te = face->getTextureEntry(); LLMaterial* mat = te->getMaterialParams().get(); if (mat && is_deferred_render) { gGL.getTexUnit(sDiffuseChannel)->bind(face->getTexture(LLRender::DIFFUSE_MAP)); gGL.getTexUnit(normal_channel)->bind(face->getTexture(LLRender::NORMAL_MAP)); gGL.getTexUnit(specular_channel)->bind(face->getTexture(LLRender::SPECULAR_MAP)); LLColor4 col = mat->getSpecularLightColor(); F32 spec = llmax(0.0001f, mat->getSpecularLightExponent() / 255.f); F32 env = mat->getEnvironmentIntensity()/255.f; if (mat->getSpecularID().isNull()) { env = te->getShiny()*0.25f; col.set(env,env,env,0); spec = env; } BOOL fullbright = te->getFullbright(); sVertexProgram->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, fullbright ? 1.f : 0.f); sVertexProgram->uniform4f(LLShaderMgr::SPECULAR_COLOR, col.mV[0], col.mV[1], col.mV[2], spec); sVertexProgram->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, env); if (mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_MASK) { sVertexProgram->setMinimumAlpha(mat->getAlphaMaskCutoff()/255.f); } else { sVertexProgram->setMinimumAlpha(0.004f); } for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i) { LLViewerTexture* tex = face->getTexture(i); if (tex) { tex->addTextureStats(avatar->getPixelArea()); } } } else { gGL.getTexUnit(sDiffuseChannel)->bind(face->getTexture()); if(sVertexProgram) { if (mat && mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_MASK) { sVertexProgram->setMinimumAlpha(mat->getAlphaMaskCutoff()/255.f); } else { sVertexProgram->setMinimumAlpha(0.004f); } } if (normal_channel > -1) { LLDrawPoolBump::bindBumpMap(face, normal_channel); } } if (face->mTextureMatrix && vobj->mTexAnimMode) { gGL.matrixMode(LLRender::MM_TEXTURE); gGL.loadMatrix(*face->mTextureMatrix); buff->setBuffer(data_mask); buff->drawRange(LLRender::TRIANGLES, start, end, count, offset); gGL.loadIdentity(); gGL.matrixMode(LLRender::MM_MODELVIEW); } else { buff->setBuffer(data_mask); buff->drawRange(LLRender::TRIANGLES, start, end, count, offset); } gPipeline.addTrianglesDrawn(count, LLRender::TRIANGLES); } } }
LLUUID get(LLViewerObject* object, S32 te) { LLViewerTexture* image = object->getTEImage(te); return image ? image->getID() : LLUUID::null; }
BOOL LLVLComposition::generateTexture(const F32 x, const F32 y, const F32 width, const F32 height) { llassert(mSurfacep); llassert(x >= 0.f); llassert(y >= 0.f); LLTimer gen_timer; /////////////////////////// // // Generate raw data arrays for surface textures // // // These have already been validated by generateComposition. U8* st_data[4]; S32 st_data_size[4]; // for debugging for (S32 i = 0; i < 4; i++) { if (mRawImages[i].isNull()) { // Read back a raw image for this discard level, if it exists S32 min_dim = llmin(mDetailTextures[i]->getFullWidth(), mDetailTextures[i]->getFullHeight()); S32 ddiscard = 0; while (min_dim > BASE_SIZE && ddiscard < MAX_DISCARD_LEVEL) { ddiscard++; min_dim /= 2; } BOOL delete_raw = (mDetailTextures[i]->reloadRawImage(ddiscard) != NULL) ; if(mDetailTextures[i]->getRawImageLevel() != ddiscard)//raw iamge is not ready, will enter here again later. { if(delete_raw) { mDetailTextures[i]->destroyRawImage() ; } lldebugs << "cached raw data for terrain detail texture is not ready yet: " << mDetailTextures[i]->getID() << llendl; return FALSE; } mRawImages[i] = mDetailTextures[i]->getRawImage() ; if(delete_raw) { mDetailTextures[i]->destroyRawImage() ; } if (mDetailTextures[i]->getWidth(ddiscard) != BASE_SIZE || mDetailTextures[i]->getHeight(ddiscard) != BASE_SIZE || mDetailTextures[i]->getComponents() != 3) { LLPointer<LLImageRaw> newraw = new LLImageRaw(BASE_SIZE, BASE_SIZE, 3); newraw->composite(mRawImages[i]); mRawImages[i] = newraw; // deletes old } } st_data[i] = mRawImages[i]->getData(); st_data_size[i] = mRawImages[i]->getDataSize(); } /////////////////////////////////////// // // Generate and clamp x/y bounding box. // // S32 x_begin, y_begin, x_end, y_end; x_begin = (S32)(x * mScaleInv); y_begin = (S32)(y * mScaleInv); x_end = llround( (x + width) * mScaleInv ); y_end = llround( (y + width) * mScaleInv ); if (x_end > mWidth) { llwarns << "x end > width" << llendl; x_end = mWidth; } if (y_end > mWidth) { llwarns << "y end > width" << llendl; y_end = mWidth; } /////////////////////////////////////////// // // Generate target texture information, stride ratios. // // LLViewerTexture *texturep; U32 tex_width, tex_height, tex_comps; U32 tex_stride; F32 tex_x_scalef, tex_y_scalef; S32 tex_x_begin, tex_y_begin, tex_x_end, tex_y_end; F32 tex_x_ratiof, tex_y_ratiof; texturep = mSurfacep->getSTexture(); tex_width = texturep->getWidth(); tex_height = texturep->getHeight(); tex_comps = texturep->getComponents(); tex_stride = tex_width * tex_comps; U32 st_comps = 3; U32 st_width = BASE_SIZE; U32 st_height = BASE_SIZE; if (tex_comps != st_comps) { llwarns << "Base texture comps != input texture comps" << llendl; return FALSE; } tex_x_scalef = (F32)tex_width / (F32)mWidth; tex_y_scalef = (F32)tex_height / (F32)mWidth; tex_x_begin = (S32)((F32)x_begin * tex_x_scalef); tex_y_begin = (S32)((F32)y_begin * tex_y_scalef); tex_x_end = (S32)((F32)x_end * tex_x_scalef); tex_y_end = (S32)((F32)y_end * tex_y_scalef); tex_x_ratiof = (F32)mWidth*mScale / (F32)tex_width; tex_y_ratiof = (F32)mWidth*mScale / (F32)tex_height; LLPointer<LLImageRaw> raw = new LLImageRaw(tex_width, tex_height, tex_comps); U8 *rawp = raw->getData(); F32 tex_width_inv = 1.f/tex_width; F32 tex_height_inv = 1.f/tex_height; F32 st_x_stride, st_y_stride; st_x_stride = ((F32)st_width / (F32)mTexScaleX)*((F32)mWidth / (F32)tex_width); st_y_stride = ((F32)st_height / (F32)mTexScaleY)*((F32)mWidth / (F32)tex_height); llassert(st_x_stride > 0.f); llassert(st_y_stride > 0.f); //////////////////////////////// // // Iterate through the target texture, striding through the // subtextures and interpolating appropriately. // // F32 sti, stj; S32 st_offset; sti = (tex_x_begin * st_x_stride) - st_width*(llfloor((tex_x_begin * st_x_stride)/st_width)); stj = (tex_y_begin * st_y_stride) - st_height*(llfloor((tex_y_begin * st_y_stride)/st_height)); st_offset = (llfloor(stj * st_width) + llfloor(sti)) * st_comps; for (S32 j = tex_y_begin; j < tex_y_end; j++) { U32 offset = j * tex_stride + tex_x_begin * tex_comps; sti = (tex_x_begin * st_x_stride) - st_width*((U32)(tex_x_begin * st_x_stride)/st_width); for (S32 i = tex_x_begin; i < tex_x_end; i++) { S32 tex0, tex1; F32 composition = getValueScaled(i*tex_x_ratiof, j*tex_y_ratiof); tex0 = llfloor( composition ); tex0 = llclamp(tex0, 0, 3); composition -= tex0; tex1 = tex0 + 1; tex1 = llclamp(tex1, 0, 3); F32 xy_int_i, xy_int_j; xy_int_i = i * tex_width_inv; xy_int_j = j * tex_height_inv; st_offset = (lltrunc(sti) + lltrunc(stj)*st_width) * st_comps; for (U32 k = 0; k < tex_comps; k++) { // Linearly interpolate based on composition. if (st_offset >= st_data_size[tex0] || st_offset >= st_data_size[tex1]) { // SJB: This shouldn't be happening, but does... Rounding error? //llwarns << "offset 0 [" << tex0 << "] =" << st_offset << " >= size=" << st_data_size[tex0] << llendl; //llwarns << "offset 1 [" << tex1 << "] =" << st_offset << " >= size=" << st_data_size[tex1] << llendl; } else { F32 a = *(st_data[tex0] + st_offset); F32 b = *(st_data[tex1] + st_offset); rawp[ offset ] = (U8)lltrunc( a + composition * (b - a) ); } offset++; st_offset++; } sti += st_x_stride; if (sti >= st_width) { sti -= st_width; } } stj += st_y_stride; if (stj >= st_height) { stj -= st_height; } } if (!texturep->hasGLTexture()) { texturep->createGLTexture(0, raw); } texturep->setSubImage(raw, tex_x_begin, tex_y_begin, tex_x_end - tex_x_begin, tex_y_end - tex_y_begin); LLSurface::sTextureUpdateTime += gen_timer.getElapsedTimeF32(); LLSurface::sTexelsUpdated += (tex_x_end - tex_x_begin) * (tex_y_end - tex_y_begin); for (S32 i = 0; i < 4; i++) { // Un-boost detatil textures (will get re-boosted if rendering in high detail) mDetailTextures[i]->setBoostLevel(LLViewerTexture::BOOST_NONE); mDetailTextures[i]->setMinDiscardLevel(MAX_DISCARD_LEVEL + 1); } return TRUE; }
void LLObjectBackup::exportNextTexture() { LLUUID id; textures_set_t::iterator iter = mTexturesList.begin(); while (true) { if (mTexturesList.empty()) { mCheckNextTexture = true; LL_INFOS() << "Finished exporting textures." << LL_ENDL; return; } if (iter == mTexturesList.end()) { // Not yet ready, wait and re-check at next idle callback... mCheckNextTexture = true; return; } id = *iter++; if (id.isNull()) { // NULL texture id: just remove and ignore. mTexturesList.erase(id); LL_DEBUGS("ObjectBackup") << "Null texture UUID found, ignoring." << LL_ENDL; continue; } LLViewerTexture* imagep = LLViewerTextureManager::findTexture(id); if (imagep) { if (imagep->getDiscardLevel() > 0) { // Boost texture loading imagep->setBoostLevel(LLGLTexture::BOOST_PREVIEW); LL_DEBUGS("ObjectBackup") << "Boosting texture: " << id << LL_ENDL; LLViewerFetchedTexture* tex; tex = LLViewerTextureManager::staticCastToFetchedTexture(imagep); if (tex && tex->getDesiredDiscardLevel() > 0) { // Set min discard level to 0 tex->setMinDiscardLevel(0); LL_DEBUGS("ObjectBackup") << "Min discard level set to 0 for texture: " << id << LL_ENDL; } } else { // Texture is ready ! break; } } else { LL_WARNS() << "We *DON'T* have the texture " << id << LL_ENDL; mNonExportedTextures |= TEXTURE_MISSING; mTexturesList.erase(id); } } mTexturesList.erase(id); LL_INFOS() << "Requesting texture " << id << " from cache." << LL_ENDL; LLImageJ2C* mFormattedImage = new LLImageJ2C; BackupCacheReadResponder* responder; responder = new BackupCacheReadResponder(id, mFormattedImage); LLAppViewer::getTextureCache()->readFromCache(id, LLWorkerThread::PRIORITY_HIGH, 0, 999999, responder); }