diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 5190f91ab..78de9749d 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1096,15 +1096,7 @@ void LLRender::init() glBindVertexArray(ret); #endif } - - llassert_always(mBuffer.isNull()) ; - stop_glerror(); - mBuffer = new LLVertexBuffer(immediate_mask, 0); - mBuffer->allocateBuffer(4096, 0, TRUE); - mBuffer->getVertexStrider(mVerticesp); - mBuffer->getTexCoord0Strider(mTexcoordsp); - mBuffer->getColorStrider(mColorsp); - stop_glerror(); + restoreVertexBuffers(); } void LLRender::shutdown() @@ -1148,6 +1140,23 @@ void LLRender::refreshState(void) mDirty = false; } +void LLRender::resetVertexBuffers() +{ + mBuffer = NULL; +} + +void LLRender::restoreVertexBuffers() +{ + llassert_always(mBuffer.isNull()); + stop_glerror(); + mBuffer = new LLVertexBuffer(immediate_mask, 0); + mBuffer->allocateBuffer(4096, 0, TRUE); + mBuffer->getVertexStrider(mVerticesp); + mBuffer->getTexCoord0Strider(mTexcoordsp); + mBuffer->getColorStrider(mColorsp); + stop_glerror(); +} + void LLRender::syncLightState() { LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 82e212370..cdadd5b03 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -346,6 +346,9 @@ public: // Needed when the render context has changed and invalidated the current state void refreshState(void); + void resetVertexBuffers(); + void restoreVertexBuffers(); + LLMatrix4a genRot(const GLfloat& a, const LLVector4a& axis) const; LLMatrix4a genRot(const GLfloat& a, const GLfloat& x, const GLfloat& y, const GLfloat& z) const { return genRot(a,LLVector4a(x,y,z)); } LLMatrix4a genOrtho(const GLfloat& left, const GLfloat& right, const GLfloat& bottom, const GLfloat& top, const GLfloat& znear, const GLfloat& zfar) const; diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp index 0dfbd7707..8d562db67 100644 --- a/indra/newview/llspatialpartition.cpp +++ b/indra/newview/llspatialpartition.cpp @@ -2175,6 +2175,10 @@ public: for (LLSpatialGroup::element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i) { LLDrawable* drawable = *i; + if (drawable->getVObj().notNull()) + { + drawable->getVObj()->resetVertexBuffers(); + } if (drawable->getVObj().notNull() && !group->mSpatialPartition->mRenderByGroup) { gPipeline.markRebuild(drawable, LLDrawable::REBUILD_ALL, TRUE); diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h index d0f86260f..4b498507e 100644 --- a/indra/newview/llviewerobject.h +++ b/indra/newview/llviewerobject.h @@ -133,6 +133,7 @@ public: LLViewerObject(const LLUUID &id, const LLPCode type, LLViewerRegion *regionp, BOOL is_global = FALSE); + virtual void resetVertexBuffers() {} virtual void markDead(); // Mark this object as dead, and clean up its references BOOL isDead() const {return mDead;} BOOL isOrphaned() const { return mOrphaned; } diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index 77530b9f8..8fa766d29 100644 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -1737,7 +1737,6 @@ LLViewerWindow::LLViewerWindow( } LLVertexBuffer::initClass(gSavedSettings.getBOOL("RenderVBOEnable"), gSavedSettings.getBOOL("RenderVBOMappingDisable")); LL_INFOS("RenderInit") << "LLVertexBuffer initialization done." << LL_ENDL ; - gGL.init() ; LLImageGL::initClass(LLViewerTexture::MAX_GL_IMAGE_CATEGORY) ; if (LLFeatureManager::getInstance()->isSafe() @@ -5307,6 +5306,8 @@ void LLViewerWindow::stopGL(BOOL save_state) gGLManager.mIsDisabled = TRUE; stop_glerror(); + + gGL.resetVertexBuffers(); llinfos << "Remaining allocated texture memory: " << LLImageGL::sGlobalTextureMemoryInBytes << " bytes" << llendl; } @@ -5323,6 +5324,7 @@ void LLViewerWindow::restoreGL(const std::string& progress_message) llinfos << "Restoring GL..." << llendl; gGLManager.mIsDisabled = FALSE; + gGL.init(); initGLDefaults(); gGL.refreshState(); //Singu Note: Call immediately. Cached states may have prevented initGLDefaults from actually applying changes. LLGLState::restoreGL(); diff --git a/indra/newview/llvotree.cpp b/indra/newview/llvotree.cpp index 844562644..a10eadf14 100644 --- a/indra/newview/llvotree.cpp +++ b/indra/newview/llvotree.cpp @@ -550,6 +550,11 @@ const S32 LEAF_VERTICES = 16; static LLFastTimer::DeclareTimer FTM_UPDATE_TREE("Update Tree"); +void LLVOTree::resetVertexBuffers() +{ + mReferenceBuffer = NULL; +} + BOOL LLVOTree::updateGeometry(LLDrawable *drawable) { LLFastTimer ftm(FTM_UPDATE_TREE); diff --git a/indra/newview/llvotree.h b/indra/newview/llvotree.h index 7fc46e0b9..482434a57 100644 --- a/indra/newview/llvotree.h +++ b/indra/newview/llvotree.h @@ -77,6 +77,7 @@ public: /*virtual*/ BOOL updateGeometry(LLDrawable *drawable); /*virtual*/ void updateSpatialExtents(LLVector4a &min, LLVector4a &max); + void resetVertexBuffers(); virtual U32 getPartitionType() const; void updateRadius(); diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index a1f2f5ac3..a5c727df9 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -491,6 +491,8 @@ void LLPipeline::init() gSavedSettings.getControl("RenderFSAASamples")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings)); //gSavedSettings.getControl("RenderAvatarVP")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings)); //Already registered to handleSetShaderChanged //gSavedSettings.getControl("WindLightUseAtmosShaders")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings)); //Already registered to handleSetShaderChanged + + gGL.init(); } LLPipeline::~LLPipeline() @@ -6743,6 +6745,8 @@ void LLPipeline::doResetVertexBuffers() //delete all name pool caches LLGLNamePool::cleanupPools(); + gGL.resetVertexBuffers(); + if (LLVertexBuffer::sGLCount > 0) { llwarns << "VBO wipe failed -- " << LLVertexBuffer::sGLCount << " buffers remaining." << llendl; @@ -6762,6 +6766,8 @@ void LLPipeline::doResetVertexBuffers() LLVertexBuffer::initClass(LLVertexBuffer::sEnableVBOs, LLVertexBuffer::sDisableVBOMapping); LLVOPartGroup::restoreGL(); + + gGL.restoreVertexBuffers(); } void LLPipeline::renderObjects(U32 type, U32 mask, BOOL texture, BOOL batch_texture)