diff options
Diffstat (limited to 'indra/newview/llmodelpreview.cpp')
-rw-r--r-- | indra/newview/llmodelpreview.cpp | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/indra/newview/llmodelpreview.cpp b/indra/newview/llmodelpreview.cpp index 0055684e56..64ea1710f5 100644 --- a/indra/newview/llmodelpreview.cpp +++ b/indra/newview/llmodelpreview.cpp @@ -227,6 +227,8 @@ LLModelPreview::~LLModelPreview() } mBaseModel.clear(); mBaseScene.clear(); + + LLLoadedCallbackEntry::cleanUpCallbackList(&mCallbackTextureList); } void LLModelPreview::updateDimentionsAndOffsets() @@ -553,7 +555,7 @@ void LLModelPreview::rebuildUploadData() { // in case user provided a missing file later texture->setIsMissingAsset(false); - texture->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, this, NULL, false); + texture->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, new LLHandle<LLModelPreview>(getHandle()), &mCallbackTextureList, false); texture->forceToSaveRawImage(0, F32_MAX); texture->updateFetch(); if (mModelLoader) @@ -782,6 +784,10 @@ void LLModelPreview::loadModel(std::string filename, S32 lod, bool force_disable std::map<std::string, std::string> joint_alias_map; getJointAliases(joint_alias_map); + LLHandle<LLModelPreview> preview_handle = getHandle(); + auto load_textures_cb = + [preview_handle](LLImportMaterial& material, void* opaque) { return LLModelPreview::loadTextures(material, preview_handle); }; + // three possible file extensions, .dae .gltf .glb // check for .dae and if not then assume one of the .gl?? std::string filename_lc(filename); @@ -793,7 +799,7 @@ void LLModelPreview::loadModel(std::string filename, S32 lod, bool force_disable lod, &LLModelPreview::loadedCallback, &LLModelPreview::lookupJointByName, - &LLModelPreview::loadTextures, + load_textures_cb, &LLModelPreview::stateChangedCallback, this, mJointTransformMap, @@ -810,7 +816,7 @@ void LLModelPreview::loadModel(std::string filename, S32 lod, bool force_disable lod, &LLModelPreview::loadedCallback, &LLModelPreview::lookupJointByName, - &LLModelPreview::loadTextures, + load_textures_cb, &LLModelPreview::stateChangedCallback, this, mJointTransformMap, @@ -2829,9 +2835,9 @@ void LLModelPreview::genBuffers(S32 lod, bool include_skin_weights) LLMatrix4a mat_normal; if (skinned) { - glh::matrix4f m((F32*)mdl->mSkinInfo.mBindShapeMatrix.getF32ptr()); - m = m.inverse().transpose(); - mat_normal.loadu(m.m); + glm::mat4 m = glm::make_mat4((F32*)mdl->mSkinInfo.mBindShapeMatrix.getF32ptr()); + m = glm::transpose(glm::inverse(m)); + mat_normal.loadu(glm::value_ptr(m)); } S32 num_faces = mdl->getNumVolumeFaces(); @@ -3128,11 +3134,9 @@ LLJoint* LLModelPreview::lookupJointByName(const std::string& str, void* opaque) return NULL; } -U32 LLModelPreview::loadTextures(LLImportMaterial& material, void* opaque) +U32 LLModelPreview::loadTextures(LLImportMaterial& material, LLHandle<LLModelPreview> handle) { - (void)opaque; - - if (material.mDiffuseMapFilename.size()) + if (material.mDiffuseMapFilename.size() && !handle.isDead()) { material.mOpaqueData = new LLPointer< LLViewerFetchedTexture >; LLPointer< LLViewerFetchedTexture >& tex = (*reinterpret_cast< LLPointer< LLViewerFetchedTexture > * >(material.mOpaqueData)); @@ -3143,9 +3147,8 @@ U32 LLModelPreview::loadTextures(LLImportMaterial& material, void* opaque) // file was loaded previosly, reload image to get potential changes tex->clearFetchedResults(); } - // Todo: might cause a crash if preview gets closed before we get the callback. - // Use a callback list or guard callback in some way - tex->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, opaque, NULL, false); + LLModelPreview* preview = (LLModelPreview*)handle.get(); + tex->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, new LLHandle<LLModelPreview>(handle), &preview->mCallbackTextureList, false); tex->forceToSaveRawImage(0, F32_MAX); material.setDiffuseMap(tex->getID()); // record tex ID return 1; @@ -3365,7 +3368,7 @@ bool LLModelPreview::render() mFMP->childSetEnabled("upload_joints", upload_skin); } - F32 explode = (F32)mFMP->childGetValue("physics_explode").asReal(); + F32 physics_explode = (F32)mFMP->childGetValue("physics_explode").asReal(); LLGLDepthTest gls_depth(GL_TRUE); // SL-12781 re-enable z-buffer for 3D model preview @@ -3594,12 +3597,12 @@ bool LLModelPreview::render() for (U32 i = 0; i < physics.mMesh.size(); ++i) { - if (explode > 0.f) + if (physics_explode > 0.f) { gGL.pushMatrix(); LLVector3 offset = model->mHullCenter[i] - model->mCenterOfHullCenters; - offset *= explode; + offset *= physics_explode; gGL.translatef(offset.mV[0], offset.mV[1], offset.mV[2]); } @@ -3614,7 +3617,7 @@ bool LLModelPreview::render() gGL.diffuseColor4ubv(hull_colors[i].mV); LLVertexBuffer::drawArrays(LLRender::TRIANGLES, physics.mMesh[i].mPositions); - if (explode > 0.f) + if (physics_explode > 0.f) { gGL.popMatrix(); } @@ -3629,7 +3632,8 @@ bool LLModelPreview::render() if (render_mesh) { auto num_models = mVertexBuffer[LLModel::LOD_PHYSICS][model].size(); - if (pass > 0){ + if (pass > 0) + { for (size_t i = 0; i < num_models; ++i) { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); @@ -3817,7 +3821,8 @@ bool LLModelPreview::render() } } - for (U32 i = 0, e = static_cast<U32>(mVertexBuffer[mPreviewLOD][model].size()); i < e; ++i) + std::size_t size = mVertexBuffer[mPreviewLOD][model].size(); + for (U32 i = 0; i < size; ++i) { model->mSkinInfo.updateHash(); LLRenderPass::uploadMatrixPalette(mPreviewAvatar, &model->mSkinInfo); @@ -4016,16 +4021,29 @@ void LLModelPreview::textureLoadedCallback( bool final, void* userdata) { - LLModelPreview* preview = (LLModelPreview*)userdata; - preview->refresh(); + if (!userdata) + return; + + LLHandle<LLModelPreview>* handle = (LLHandle<LLModelPreview>*)userdata; - if (final && preview->mModelLoader) + if (!handle->isDead()) { - if (preview->mModelLoader->mNumOfFetchingTextures > 0) + LLModelPreview* preview = static_cast<LLModelPreview*>(handle->get()); + preview->refresh(); + + if (final && preview->mModelLoader) { - preview->mModelLoader->mNumOfFetchingTextures--; + if (preview->mModelLoader->mNumOfFetchingTextures > 0) + { + preview->mModelLoader->mNumOfFetchingTextures--; + } } } + + if (final || !success) + { + delete handle; + } } // static |