summaryrefslogtreecommitdiff
path: root/indra/newview/llmodelpreview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llmodelpreview.cpp')
-rw-r--r--indra/newview/llmodelpreview.cpp164
1 files changed, 89 insertions, 75 deletions
diff --git a/indra/newview/llmodelpreview.cpp b/indra/newview/llmodelpreview.cpp
index 092861a240..26f1206c85 100644
--- a/indra/newview/llmodelpreview.cpp
+++ b/indra/newview/llmodelpreview.cpp
@@ -132,25 +132,17 @@ std::string getLodSuffix(S32 lod)
void FindModel(LLModelLoader::scene& scene, const std::string& name_to_match, LLModel*& baseModelOut, LLMatrix4& matOut)
{
- LLModelLoader::scene::iterator base_iter = scene.begin();
- bool found = false;
- while (!found && (base_iter != scene.end()))
+ for (auto scene_iter = scene.begin(); scene_iter != scene.end(); scene_iter++)
{
- matOut = base_iter->first;
-
- LLModelLoader::model_instance_list::iterator base_instance_iter = base_iter->second.begin();
- while (!found && (base_instance_iter != base_iter->second.end()))
+ for (auto model_iter = scene_iter->second.begin(); model_iter != scene_iter->second.end(); model_iter++)
{
- LLModelInstance& base_instance = *base_instance_iter++;
- LLModel* base_model = base_instance.mModel;
-
- if (base_model && (base_model->mLabel == name_to_match))
+ if (model_iter->mModel && (model_iter->mModel->mLabel == name_to_match))
{
- baseModelOut = base_model;
+ baseModelOut = model_iter->mModel;
+ matOut = scene_iter->first;
return;
}
}
- base_iter++;
}
}
@@ -210,9 +202,12 @@ LLModelPreview::LLModelPreview(S32 width, S32 height, LLFloater* fmp)
LLModelPreview::~LLModelPreview()
{
+ LLMutexLock lock(this);
+
if (mModelLoader)
{
mModelLoader->shutdown();
+ mModelLoader = NULL;
}
if (mPreviewAvatar)
@@ -260,7 +255,7 @@ void LLModelPreview::updateDimentionsAndOffsets()
accounted.insert(instance.mModel);
// update instance skin info for each lods pelvisZoffset
- for (int j = 0; j<LLModel::NUM_LODS; ++j)
+ for (int j = 0; j < LLModel::NUM_LODS; ++j)
{
if (instance.mLOD[j])
{
@@ -301,7 +296,7 @@ void LLModelPreview::rebuildUploadData()
BOOL legacyMatching = gSavedSettings.getBOOL("ImporterLegacyMatching");
U32 load_state = 0;
- for (LLModelLoader::scene::iterator iter = mBaseScene.begin(); iter != mBaseScene.end(); ++iter)
+ for (auto iter = mBaseScene.begin(); iter != mBaseScene.end(); ++iter)
{ //for each transform in scene
LLMatrix4 mat = iter->first;
@@ -320,9 +315,9 @@ void LLModelPreview::rebuildUploadData()
mat *= scale_mat;
- for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end();)
+ for (auto model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter)
{ // for each instance with said transform applied
- LLModelInstance instance = *model_iter++;
+ LLModelInstance instance = *model_iter;
LLModel* base_model = instance.mModel;
@@ -882,7 +877,7 @@ void LLModelPreview::clearIncompatible(S32 lod)
{
mBaseModel = mModel[lod];
mBaseScene = mScene[lod];
- mVertexBuffer[5].clear();
+ mVertexBuffer[LLModel::NUM_LODS].clear();
replaced_base_model = true;
}
}
@@ -1081,7 +1076,7 @@ void LLModelPreview::loadModelCallback(S32 loaded_lod)
mBaseModel = mModel[loaded_lod];
mBaseScene = mScene[loaded_lod];
- mVertexBuffer[5].clear();
+ mVertexBuffer[LLModel::NUM_LODS].clear();
}
else
{
@@ -1186,7 +1181,7 @@ void LLModelPreview::loadModelCallback(S32 loaded_lod)
{
if (!mBaseModel.empty())
{
- const std::string& model_name = mBaseModel[0]->getName();
+ std::string model_name = mBaseModel.front()->getName();
LLLineEditor* description_form = mFMP->getChild<LLLineEditor>("description_form");
if (description_form->getText().empty())
{
@@ -1207,6 +1202,8 @@ void LLModelPreview::loadModelCallback(S32 loaded_lod)
void LLModelPreview::resetPreviewTarget()
{
+ LLMutexLock lock(this);
+
if (mModelLoader)
{
mPreviewTarget = (mModelLoader->mExtents[0] + mModelLoader->mExtents[1]) * 0.5f;
@@ -1252,7 +1249,7 @@ void LLModelPreview::generateNormals()
(*it)->generateNormals(angle_cutoff);
}
- mVertexBuffer[5].clear();
+ mVertexBuffer[LLModel::NUM_LODS].clear();
}
bool perform_copy = mModelFacesCopy[which_lod].empty();
@@ -2094,7 +2091,7 @@ void LLModelPreview::updateStatusMessages()
S32 total_verts[LLModel::NUM_LODS];
S32 total_submeshes[LLModel::NUM_LODS];
- for (U32 i = 0; i < LLModel::NUM_LODS - 1; i++)
+ for (U32 i = 0; i < LLModel::NUM_LODS; i++)
{
total_tris[i] = 0;
total_verts[i] = 0;
@@ -2398,12 +2395,16 @@ void LLModelPreview::updateStatusMessages()
}
}
- if (mModelNoErrors && mModelLoader)
+ if (mModelNoErrors)
{
- if (!mModelLoader->areTexturesReady() && mFMP->childGetValue("upload_textures").asBoolean())
+ LLMutexLock lock(this);
+ if (mModelLoader)
{
- // Some textures are still loading, prevent upload until they are done
- mModelNoErrors = false;
+ if (!mModelLoader->areTexturesReady() && mFMP->childGetValue("upload_textures").asBoolean())
+ {
+ // Some textures are still loading, prevent upload until they are done
+ mModelNoErrors = false;
+ }
}
}
@@ -2732,10 +2733,10 @@ void LLModelPreview::genBuffers(S32 lod, bool include_skin_weights)
{
LLModelLoader::model_list* model = NULL;
- if (lod < 0 || lod > 4)
+ if (lod < 0 || lod >= LLModel::NUM_LODS)
{
model = &mBaseModel;
- lod = 5;
+ lod = LLModel::NUM_LODS;
}
else
{
@@ -2972,8 +2973,9 @@ void LLModelPreview::loadedCallback(
S32 lod,
void* opaque)
{
- LLModelPreview* pPreview = static_cast< LLModelPreview* >(opaque);
- if (pPreview && !LLModelPreview::sIgnoreLoadedCallback)
+ LLModelPreview* pPreview = static_cast<LLModelPreview*>(opaque);
+ LLMutexLock lock(pPreview);
+ if (pPreview && pPreview->mModelLoader && !LLModelPreview::sIgnoreLoadedCallback)
{
// Load loader's warnings into floater's log tab
const LLSD out = pPreview->mModelLoader->logOut();
@@ -2994,7 +2996,9 @@ void LLModelPreview::loadedCallback(
}
const LLVOAvatar* avatarp = pPreview->getPreviewAvatar();
- if (avatarp) { // set up ground plane for possible rendering
+ if (avatarp && avatarp->mRoot && avatarp->mDrawable)
+ {
+ // set up ground plane for possible rendering
const LLVector3 root_pos = avatarp->mRoot->getPosition();
const LLVector4a* ext = avatarp->mDrawable->getSpatialExtents();
const LLVector4a min = ext[0], max = ext[1];
@@ -3131,12 +3135,12 @@ BOOL LLModelPreview::render()
LLMutexLock lock(this);
mNeedsUpdate = FALSE;
- bool edges = mViewOption["show_edges"];
- bool joint_overrides = mViewOption["show_joint_overrides"];
- bool joint_positions = mViewOption["show_joint_positions"];
- bool skin_weight = mViewOption["show_skin_weight"];
- bool textures = mViewOption["show_textures"];
- bool physics = mViewOption["show_physics"];
+ bool show_edges = mViewOption["show_edges"];
+ bool show_joint_overrides = mViewOption["show_joint_overrides"];
+ bool show_joint_positions = mViewOption["show_joint_positions"];
+ bool show_skin_weight = mViewOption["show_skin_weight"];
+ bool show_textures = mViewOption["show_textures"];
+ bool show_physics = mViewOption["show_physics"];
S32 width = getWidth();
S32 height = getHeight();
@@ -3213,15 +3217,15 @@ BOOL LLModelPreview::render()
fmp->childSetValue("upload_skin", true);
mFirstSkinUpdate = false;
upload_skin = true;
- skin_weight = true;
+ show_skin_weight = true;
mViewOption["show_skin_weight"] = true;
}
fmp->enableViewOption("show_skin_weight");
- fmp->setViewOptionEnabled("show_joint_overrides", skin_weight);
- fmp->setViewOptionEnabled("show_joint_positions", skin_weight);
+ fmp->setViewOptionEnabled("show_joint_overrides", show_skin_weight);
+ fmp->setViewOptionEnabled("show_joint_positions", show_skin_weight);
mFMP->childEnable("upload_skin");
- mFMP->childSetValue("show_skin_weight", skin_weight);
+ mFMP->childSetValue("show_skin_weight", show_skin_weight);
}
else if ((flags & LEGACY_RIG_FLAG_TOO_MANY_JOINTS) > 0)
@@ -3244,11 +3248,12 @@ BOOL LLModelPreview::render()
fmp->disableViewOption("show_joint_overrides");
fmp->disableViewOption("show_joint_positions");
- skin_weight = false;
+ show_skin_weight = false;
mFMP->childSetValue("show_skin_weight", false);
- fmp->setViewOptionEnabled("show_skin_weight", skin_weight);
+ fmp->setViewOptionEnabled("show_skin_weight", show_skin_weight);
}
}
+ //if (this) return TRUE;
if (upload_skin && !has_skin_weights)
{ //can't upload skin weights if model has no skin weights
@@ -3291,7 +3296,7 @@ BOOL LLModelPreview::render()
mFMP->childSetEnabled("upload_joints", upload_skin);
}
- F32 explode = mFMP->childGetValue("physics_explode").asReal();
+ F32 physics_explode = mFMP->childGetValue("physics_explode").asReal();
LLGLDepthTest gls_depth(GL_TRUE); // SL-12781 re-enable z-buffer for 3D model preview
@@ -3311,7 +3316,7 @@ BOOL LLModelPreview::render()
F32 z_near = 0.001f;
F32 z_far = mCameraDistance*10.0f + mPreviewScale.magVec() + mCameraOffset.magVec();
- if (skin_weight)
+ if (show_skin_weight)
{
target_pos = getPreviewAvatar()->getPositionAgent() + offset;
z_near = 0.01f;
@@ -3321,7 +3326,7 @@ BOOL LLModelPreview::render()
refresh();
}
- gObjectPreviewProgram.bind(skin_weight);
+ gObjectPreviewProgram.bind(show_skin_weight);
gGL.loadIdentity();
gPipeline.enableLightsPreview();
@@ -3330,7 +3335,7 @@ BOOL LLModelPreview::render()
LLQuaternion(mCameraYaw, LLVector3::z_axis);
LLQuaternion av_rot = camera_rot;
- F32 camera_distance = skin_weight ? SKIN_WEIGHT_CAMERA_DISTANCE : mCameraDistance;
+ F32 camera_distance = show_skin_weight ? SKIN_WEIGHT_CAMERA_DISTANCE : mCameraDistance;
LLViewerCamera::getInstance()->setOriginAndLookAt(
target_pos + ((LLVector3(camera_distance, 0.f, 0.f) + offset) * av_rot), // camera
LLVector3::z_axis, // up
@@ -3346,9 +3351,9 @@ BOOL LLModelPreview::render()
gGL.pushMatrix();
gGL.color4fv(PREVIEW_EDGE_COL.mV);
- if (!mBaseModel.empty() && mVertexBuffer[5].empty())
+ if (!mBaseModel.empty() && mVertexBuffer[LLModel::NUM_LODS].empty())
{
- genBuffers(-1, skin_weight);
+ genBuffers(-1, show_skin_weight);
//genBuffers(3);
}
@@ -3363,7 +3368,7 @@ BOOL LLModelPreview::render()
if (!vb_vec.empty())
{
const LLVertexBuffer* buff = vb_vec[0];
- regen = buff->hasDataType(LLVertexBuffer::TYPE_WEIGHT4) != skin_weight;
+ regen = buff->hasDataType(LLVertexBuffer::TYPE_WEIGHT4) != show_skin_weight;
}
else
{
@@ -3374,15 +3379,15 @@ BOOL LLModelPreview::render()
if (regen)
{
- genBuffers(mPreviewLOD, skin_weight);
+ genBuffers(mPreviewLOD, show_skin_weight);
}
- if (physics && mVertexBuffer[LLModel::LOD_PHYSICS].empty())
+ if (show_physics && mVertexBuffer[LLModel::LOD_PHYSICS].empty())
{
genBuffers(LLModel::LOD_PHYSICS, false);
}
- if (!skin_weight)
+ if (!show_skin_weight)
{
for (LLMeshUploadThread::instance_list::iterator iter = mUploadData.begin(); iter != mUploadData.end(); ++iter)
{
@@ -3404,11 +3409,7 @@ BOOL LLModelPreview::render()
U32 num_models = mVertexBuffer[mPreviewLOD][model].size();
for (U32 i = 0; i < num_models; ++i)
{
- LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i];
-
- buffer->setBuffer();
-
- if (textures)
+ if (show_textures)
{
int materialCnt = instance.mModel->mMaterialList.size();
if (i < materialCnt)
@@ -3432,10 +3433,16 @@ BOOL LLModelPreview::render()
gGL.diffuseColor4fv(PREVIEW_BASE_COL.mV);
}
+ // Zero this variable for an obligatory buffer initialization
+ // See https://github.com/secondlife/viewer/issues/912
+ LLVertexBuffer::sGLRenderBuffer = 0;
+ LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i];
+ buffer->setBuffer();
buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts() - 1, buffer->getNumIndices(), 0);
+
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.diffuseColor4fv(PREVIEW_EDGE_COL.mV);
- if (edges)
+ if (show_edges)
{
glLineWidth(PREVIEW_EDGE_WIDTH);
#if GL_VERSION_1_1
@@ -3452,7 +3459,7 @@ BOOL LLModelPreview::render()
gGL.popMatrix();
}
- if (physics)
+ if (show_physics)
{
glClear(GL_DEPTH_BUFFER_BIT);
@@ -3518,12 +3525,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]);
}
@@ -3538,7 +3545,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();
}
@@ -3553,14 +3560,17 @@ BOOL LLModelPreview::render()
if (render_mesh)
{
U32 num_models = mVertexBuffer[LLModel::LOD_PHYSICS][model].size();
- if (pass > 0){
+ if (pass > 0)
+ {
for (U32 i = 0; i < num_models; ++i)
{
- LLVertexBuffer* buffer = mVertexBuffer[LLModel::LOD_PHYSICS][model][i];
-
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.diffuseColor4fv(PREVIEW_PSYH_FILL_COL.mV);
+ // Zero this variable for an obligatory buffer initialization
+ // See https://github.com/secondlife/viewer/issues/912
+ LLVertexBuffer::sGLRenderBuffer = 0;
+ LLVertexBuffer* buffer = mVertexBuffer[LLModel::LOD_PHYSICS][model][i];
buffer->setBuffer();
buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts() - 1, buffer->getNumIndices(), 0);
@@ -3626,10 +3636,11 @@ BOOL LLModelPreview::render()
U32 num_models = mVertexBuffer[LLModel::LOD_PHYSICS][model].size();
for (U32 v = 0; v < num_models; ++v)
{
+ // Zero this variable for an obligatory buffer initialization
+ // See https://github.com/secondlife/viewer/issues/912
+ LLVertexBuffer::sGLRenderBuffer = 0;
LLVertexBuffer* buffer = mVertexBuffer[LLModel::LOD_PHYSICS][model][v];
-
buffer->setBuffer();
-
LLStrider<LLVector3> pos_strider;
buffer->getVertexStrider(pos_strider, 0);
LLVector4a* pos = (LLVector4a*)pos_strider.get();
@@ -3695,7 +3706,7 @@ BOOL LLModelPreview::render()
U32 joint_count = LLSkinningUtil::getMeshJointCount(skin);
U32 bind_count = skin->mAlternateBindMatrix.size();
- if (joint_overrides
+ if (show_joint_overrides
&& bind_count > 0
&& joint_count == bind_count)
{
@@ -3738,16 +3749,15 @@ BOOL LLModelPreview::render()
}
}
- for (U32 i = 0, e = mVertexBuffer[mPreviewLOD][model].size(); i < e; ++i)
+ std::size_t size = mVertexBuffer[mPreviewLOD][model].size();
+ for (U32 i = 0; i < size; ++i)
{
- LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i];
-
model->mSkinInfo.updateHash();
LLRenderPass::uploadMatrixPalette(mPreviewAvatar, &model->mSkinInfo);
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- if (textures)
+ if (show_textures)
{
int materialCnt = instance.mModel->mMaterialList.size();
if (i < materialCnt)
@@ -3771,10 +3781,14 @@ BOOL LLModelPreview::render()
gGL.diffuseColor4fv(PREVIEW_BASE_COL.mV);
}
+ // Zero this variable for an obligatory buffer initialization
+ // See https://github.com/secondlife/viewer/issues/912
+ LLVertexBuffer::sGLRenderBuffer = 0;
+ LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i];
buffer->setBuffer();
buffer->draw(LLRender::TRIANGLES, buffer->getNumIndices(), 0);
- if (edges)
+ if (show_edges)
{
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.diffuseColor4fv(PREVIEW_EDGE_COL.mV);
@@ -3793,7 +3807,7 @@ BOOL LLModelPreview::render()
}
}
- if (joint_positions)
+ if (show_joint_positions)
{
LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
if (shader)