From 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:44:50 -0500 Subject: Second Life viewer sources 1.14.0.0 --- linden/indra/newview/llface.cpp | 1478 ++++++++++++++------------------------- 1 file changed, 528 insertions(+), 950 deletions(-) (limited to 'linden/indra/newview/llface.cpp') diff --git a/linden/indra/newview/llface.cpp b/linden/indra/newview/llface.cpp index a6de94b..e46fcd3 100644 --- a/linden/indra/newview/llface.cpp +++ b/linden/indra/newview/llface.cpp @@ -29,13 +29,13 @@ #include "lldrawable.h" // lldrawable needs to be included before llface #include "llface.h" +#include "llviewertextureanim.h" #include "llviewercontrol.h" #include "llvolume.h" #include "m3math.h" #include "v3color.h" -#include "llagparray.h" #include "lldrawpoolsimple.h" #include "lldrawpoolbump.h" #include "llgl.h" @@ -47,8 +47,6 @@ #include "llvovolume.h" #include "pipeline.h" -#include "llagparray.inl" - #define LL_MAX_INDICES_COUNT 1000000 extern BOOL gPickFaces; @@ -137,25 +135,23 @@ void cylindricalProjection(LLVector2 &tc, const LLVolumeFace::VertexData &vd, co void LLFace::init(LLDrawable* drawablep, LLViewerObject* objp) { - mGeneration = DIRTY; + mLastUpdateTime = gFrameTimeSeconds; + mVSize = 0.f; + mPixelArea = 1024.f; mState = GLOBAL; mDrawPoolp = NULL; + mPoolType = 0; mGeomIndex = -1; - mSkipRender = FALSE; - mNextFace = NULL; // mCenterLocal // mCenterAgent mDistance = 0.f; - mPrimType = LLTriangles; mGeomCount = 0; mIndicesCount = 0; mIndicesIndex = -1; mTexture = NULL; mTEOffset = -1; - mBackupMem = NULL; - setDrawable(drawablep); mVObjp = objp; @@ -163,6 +159,12 @@ void LLFace::init(LLDrawable* drawablep, LLViewerObject* objp) mAlphaFade = 0.f; mFaceColor = LLColor4(1,0,0,1); + + mLastVertexBuffer = mVertexBuffer; + mLastGeomCount = mGeomCount; + mLastGeomIndex = mGeomIndex; + mLastIndicesCount = mIndicesCount; + mLastIndicesIndex = mIndicesIndex; } @@ -176,11 +178,6 @@ void LLFace::destroy() mDrawPoolp->removeFace(this); mDrawPoolp = NULL; } - - // Remove light and blocker list references - - delete[] mBackupMem; - mBackupMem = NULL; } @@ -194,13 +191,7 @@ void LLFace::setWorldMatrix(const LLMatrix4 &mat) llerrs << "Faces on this drawable are not independently modifiable\n" << llendl; } - -void LLFace::setDirty() -{ - mGeneration = DIRTY; -} - -void LLFace::setPool(LLDrawPool* new_pool, LLViewerImage *texturep) +void LLFace::setPool(LLFacePool* new_pool, LLViewerImage *texturep) { LLMemType mt1(LLMemType::MTYPE_DRAWABLE); @@ -215,22 +206,12 @@ void LLFace::setPool(LLDrawPool* new_pool, LLViewerImage *texturep) if (mDrawPoolp) { mDrawPoolp->removeFace(this); - mSkipRender = FALSE; - mNextFace = NULL; - // Invalidate geometry (will get rebuilt next frame) - setDirty(); if (mDrawablep) { gPipeline.markRebuild(mDrawablep, LLDrawable::REBUILD_ALL, TRUE); } } - if (isState(BACKLIST)) - { - delete[] mBackupMem; - mBackupMem = NULL; - clearState(BACKLIST); - } mGeomIndex = -1; // Add to new pool @@ -239,7 +220,6 @@ void LLFace::setPool(LLDrawPool* new_pool, LLViewerImage *texturep) new_pool->addFace(this); } mDrawPoolp = new_pool; - } mTexture = texturep; } @@ -268,91 +248,12 @@ void LLFace::setDrawable(LLDrawable *drawable) mXform = &drawable->mXform; } -S32 LLFace::allocBackupMem() -{ - LLMemType mt1(LLMemType::MTYPE_DRAWABLE); - - S32 size = 0; - size += mIndicesCount * 4; - size += mGeomCount * mDrawPoolp->getStride(); - - if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_VERTEX_WEIGHTS_MASK) - { - size += mGeomCount * mDrawPoolp->sDataSizes[LLDrawPool::DATA_VERTEX_WEIGHTS]; - } - - if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_CLOTHING_WEIGHTS_MASK) - { - size += mGeomCount * mDrawPoolp->sDataSizes[LLDrawPool::DATA_CLOTHING_WEIGHTS]; - } - - delete[] mBackupMem; - mBackupMem = new U8[size]; - return size; -} - - void LLFace::setSize(const S32 num_vertices, const S32 num_indices) { LLMemType mt1(LLMemType::MTYPE_DRAWABLE); - if (getState() & SHARED_GEOM) - { - mGeomCount = num_vertices; - mIndicesCount = num_indices; - return; // Shared, don't allocate or do anything with memory - } - if (num_vertices != (S32)mGeomCount || num_indices != (S32)mIndicesCount) - { - setDirty(); - - delete[] mBackupMem; - mBackupMem = NULL; - clearState(BACKLIST); - - mGeomCount = num_vertices; - mIndicesCount = num_indices; - } - -} - -BOOL LLFace::reserveIfNeeded() -{ - LLMemType mt1(LLMemType::MTYPE_DRAWABLE); - - if (getDirty()) - { - if (isState(BACKLIST)) - { - llwarns << "Reserve on backlisted object!" << llendl; - } - - if (0 == mGeomCount) - { - //llwarns << "Reserving zero bytes for face!" << llendl; - mGeomCount = 0; - mIndicesCount = 0; - return FALSE; - } - - mGeomIndex = mDrawPoolp->reserveGeom(mGeomCount); - // (reserveGeom() always returns a valid index) - mIndicesIndex = mDrawPoolp->reserveInd (mIndicesCount); - mGeneration = mDrawPoolp->mGeneration; - } - - return TRUE; -} - -void LLFace::unReserve() -{ - LLMemType mt1(LLMemType::MTYPE_DRAWABLE); - - if (!(isState(SHARED_GEOM))) - { - mGeomIndex = mDrawPoolp->unReserveGeom(mGeomIndex, mGeomCount); - mIndicesIndex = mDrawPoolp->unReserveInd(mIndicesIndex, mIndicesCount); - } + mGeomCount = num_vertices; + mIndicesCount = num_indices; } //============================================================================ @@ -366,55 +267,22 @@ S32 LLFace::getGeometryAvatar( LLStrider &clothing_weights) { LLMemType mt1(LLMemType::MTYPE_DRAWABLE); - - if (mGeomCount <= 0) - { - return -1; - } - - if (isState(BACKLIST)) - { - if (!mBackupMem) - { - llerrs << "No backup memory for backlist" << llendl; - } - - vertices = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_VERTICES]); - normals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_NORMALS]); - binormals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_BINORMALS]); - tex_coords = (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS0]); - clothing_weights = (LLVector4*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_CLOTHING_WEIGHTS]); - vertex_weights = (F32*)(mBackupMem + (4 * mIndicesCount) + (mGeomCount * mDrawPoolp->getStride())); - tex_coords.setStride( mDrawPoolp->getStride()); - vertices.setStride( mDrawPoolp->getStride()); - normals.setStride( mDrawPoolp->getStride()); - binormals.setStride( mDrawPoolp->getStride()); - clothing_weights.setStride( mDrawPoolp->getStride()); - return 0; + if (mVertexBuffer.notNull()) + { + mVertexBuffer->getVertexStrider (vertices, mGeomIndex); + mVertexBuffer->getNormalStrider (normals, mGeomIndex); + mVertexBuffer->getBinormalStrider (binormals, mGeomIndex); + mVertexBuffer->getTexCoordStrider (tex_coords, mGeomIndex); + mVertexBuffer->getWeightStrider(vertex_weights, mGeomIndex); + mVertexBuffer->getClothWeightStrider(clothing_weights, mGeomIndex); } else { - if (!reserveIfNeeded()) - { - return -1; - } - - llassert(mGeomIndex >= 0); - llassert(mIndicesIndex >= 0); - - mDrawPoolp->getVertexStrider (vertices, mGeomIndex); - mDrawPoolp->getNormalStrider (normals, mGeomIndex); - mDrawPoolp->getBinormalStrider (binormals, mGeomIndex); - mDrawPoolp->getTexCoordStrider (tex_coords, mGeomIndex); - mDrawPoolp->getVertexWeightStrider(vertex_weights, mGeomIndex); - mDrawPoolp->getClothingWeightStrider(clothing_weights, mGeomIndex); - - mDrawPoolp->setDirty(); - - llassert(mGeomIndex >= 0); - return mGeomIndex; + mGeomIndex = -1; } + + return mGeomIndex; } S32 LLFace::getGeometryTerrain( @@ -423,64 +291,29 @@ S32 LLFace::getGeometryTerrain( LLStrider &colors, LLStrider &texcoords0, LLStrider &texcoords1, - U32 *&indicesp) + LLStrider &indicesp) { LLMemType mt1(LLMemType::MTYPE_DRAWABLE); - if (mGeomCount <= 0) - { - return -1; - } - - if (isState(BACKLIST)) + if (mVertexBuffer.notNull()) { - if (!mBackupMem) - { - printDebugInfo(); - llerrs << "No backup memory for face" << llendl; - } - vertices = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_VERTICES]); - normals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_NORMALS]); - colors = (LLColor4U*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_COLORS]); - texcoords0= (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS0]); - texcoords1= (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS1]); - texcoords0.setStride(mDrawPoolp->getStride()); - texcoords1.setStride(mDrawPoolp->getStride()); - vertices.setStride( mDrawPoolp->getStride()); - normals.setStride( mDrawPoolp->getStride()); - colors.setStride( mDrawPoolp->getStride()); - indicesp = (U32*)mBackupMem; - - return 0; + mVertexBuffer->getVertexStrider(vertices, mGeomIndex); + mVertexBuffer->getNormalStrider(normals, mGeomIndex); + mVertexBuffer->getColorStrider(colors, mGeomIndex); + mVertexBuffer->getTexCoordStrider(texcoords0, mGeomIndex); + mVertexBuffer->getTexCoord2Strider(texcoords1, mGeomIndex); + mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex); } else { - if (!reserveIfNeeded()) - { - llinfos << "Get geometry failed!" << llendl; - return -1; - } - - llassert(mGeomIndex >= 0); - llassert(mIndicesIndex >= 0); - - mDrawPoolp->getVertexStrider(vertices, mGeomIndex); - mDrawPoolp->getNormalStrider(normals, mGeomIndex); - mDrawPoolp->getColorStrider(colors, mGeomIndex); - mDrawPoolp->getTexCoordStrider(texcoords0, mGeomIndex, 0); - mDrawPoolp->getTexCoordStrider(texcoords1, mGeomIndex, 1); - - indicesp = mDrawPoolp->getIndices(mIndicesIndex); - - mDrawPoolp->setDirty(); - - llassert(mGeomIndex >= 0); - return mGeomIndex; + mGeomIndex = -1; } + + return mGeomIndex; } S32 LLFace::getGeometry(LLStrider &vertices, LLStrider &normals, - LLStrider &tex_coords, U32 *&indicesp) + LLStrider &tex_coords, LLStrider &indicesp) { LLMemType mt1(LLMemType::MTYPE_DRAWABLE); @@ -489,55 +322,31 @@ S32 LLFace::getGeometry(LLStrider &vertices, LLStrider &no return -1; } - if (isState(BACKLIST)) + if (mVertexBuffer.notNull()) { - if (!mBackupMem) + mVertexBuffer->getVertexStrider(vertices, mGeomIndex); + if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_NORMAL)) { - printDebugInfo(); - llerrs << "No backup memory for face" << llendl; + mVertexBuffer->getNormalStrider(normals, mGeomIndex); + } + if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD)) + { + mVertexBuffer->getTexCoordStrider(tex_coords, mGeomIndex); } - vertices = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_VERTICES]); - normals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_NORMALS]); - tex_coords= (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS0]); - tex_coords.setStride(mDrawPoolp->getStride()); - vertices.setStride( mDrawPoolp->getStride()); - normals.setStride( mDrawPoolp->getStride()); - indicesp = (U32*)mBackupMem; - return 0; + mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex); } else { - if (!reserveIfNeeded()) - { - return -1; - } - - llassert(mGeomIndex >= 0); - llassert(mIndicesIndex >= 0); - - mDrawPoolp->getVertexStrider(vertices, mGeomIndex); - if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_NORMALS_MASK) - { - mDrawPoolp->getNormalStrider(normals, mGeomIndex); - } - if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_TEX_COORDS0_MASK) - { - mDrawPoolp->getTexCoordStrider(tex_coords, mGeomIndex); - } - - indicesp =mDrawPoolp->getIndices (mIndicesIndex); - - mDrawPoolp->setDirty(); - - llassert(mGeomIndex >= 0); - return mGeomIndex; + mGeomIndex = -1; } + + return mGeomIndex; } S32 LLFace::getGeometryColors(LLStrider &vertices, LLStrider &normals, LLStrider &tex_coords, LLStrider &colors, - U32 *&indicesp) + LLStrider &indicesp) { S32 res = getGeometry(vertices, normals, tex_coords, indicesp); if (res >= 0) @@ -547,95 +356,25 @@ S32 LLFace::getGeometryColors(LLStrider &vertices, LLStrider &vertices, - LLStrider &normals, - LLStrider &binormals, - LLStrider &tex_coords0, - LLStrider &tex_coords1, - U32 *&indicesp) +void LLFace::updateCenterAgent() { - LLMemType mt1(LLMemType::MTYPE_DRAWABLE); - - if (mGeomCount <= 0) + if (mDrawablep->isActive()) { - return -1; - } - - if (isState(BACKLIST)) - { - if (!mBackupMem) - { - printDebugInfo(); - llerrs << "No backup memory for face" << llendl; - } - vertices = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_VERTICES]); - normals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_NORMALS]); - tex_coords0 = (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS0]); - tex_coords0.setStride( mDrawPoolp->getStride() ); - vertices.setStride( mDrawPoolp->getStride() ); - normals.setStride( mDrawPoolp->getStride() ); - if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_BINORMALS_MASK) - { - binormals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_BINORMALS]); - binormals.setStride( mDrawPoolp->getStride() ); - } - if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_TEX_COORDS1_MASK) - { - tex_coords1 = (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS1]); - tex_coords1.setStride( mDrawPoolp->getStride() ); - } - indicesp = (U32*)mBackupMem; - - return 0; + mCenterAgent = mCenterLocal * getRenderMatrix(); } else { - if (!reserveIfNeeded()) - { - return -1; - } - - llassert(mGeomIndex >= 0); - llassert(mIndicesIndex >= 0); - - mDrawPoolp->getVertexStrider(vertices, mGeomIndex); - if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_NORMALS_MASK) - { - mDrawPoolp->getNormalStrider(normals, mGeomIndex); - } - if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_TEX_COORDS0_MASK) - { - mDrawPoolp->getTexCoordStrider(tex_coords0, mGeomIndex); - } - if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_BINORMALS_MASK) - { - mDrawPoolp->getBinormalStrider(binormals, mGeomIndex); - } - if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_TEX_COORDS1_MASK) - { - mDrawPoolp->getTexCoordStrider(tex_coords1, mGeomIndex, 1); - } - indicesp = mDrawPoolp->getIndices(mIndicesIndex); - - mDrawPoolp->setDirty(); - - llassert(mGeomIndex >= 0); - return mGeomIndex; + mCenterAgent = mCenterLocal; } } -void LLFace::updateCenterAgent() -{ - mCenterAgent = mCenterLocal * getRenderMatrix(); -} - -void LLFace::renderForSelect() const +void LLFace::renderForSelect(U32 data_mask) { - if(mGeomIndex < 0 || mDrawablep.isNull()) + if(mGeomIndex < 0 || mDrawablep.isNull() || mVertexBuffer.isNull()) { return; } + if (mVObjp->mGLName) { S32 name = mVObjp->mGLName; @@ -649,47 +388,25 @@ void LLFace::renderForSelect() const #endif glColor4ubv(color.mV); - if (mVObjp->getPCode() == LL_PCODE_VOLUME) + if (!getPool()) { - LLVOVolume *volp; - volp = (LLVOVolume *)(LLViewerObject*)mVObjp; - if (volp->getNumFaces() == 1 && !volp->getVolumeChanged()) + switch (getPoolType()) { - // We need to special case the coalesced face model. - S32 num_vfs = volp->getVolume()->getNumFaces(); - S32 offset = 0; - S32 i; - - for (i = 0; i < num_vfs; i++) - { - if (gPickFaces) - { - // mask off high 4 bits (16 total possible faces) - color.mV[0] &= 0x0f; - color.mV[0] |= (i & 0x0f) << 4; - glColor4ubv(color.mV); - } - S32 count = volp->getVolume()->getVolumeFace(i).mIndices.size(); - if (isState(GLOBAL)) - { - glDrawElements(mPrimType, count, GL_UNSIGNED_INT, getRawIndices() + offset); - } - else - { - glPushMatrix(); - glMultMatrixf((float*)getRenderMatrix().mMatrix); - glDrawElements(mPrimType, count, GL_UNSIGNED_INT, getRawIndices() + offset); - glPopMatrix(); - } - offset += count; - } - // We're done, return. - return; + case LLDrawPool::POOL_ALPHA: + getTexture()->bind(); + break; + default: + LLImageGL::unbindTexture(0); + break; } - - // We don't have coalesced faces, do this the normal way. } + mVertexBuffer->setBuffer(data_mask); +#if !LL_RELEASE_FOR_DOWNLOAD + LLGLState::checkClientArrays(data_mask); +#endif + U32* indicesp = (U32*) mVertexBuffer->getIndicesPointer() + mIndicesIndex; + if (gPickFaces && mTEOffset != -1) { // mask off high 4 bits (16 total possible faces) @@ -702,13 +419,13 @@ void LLFace::renderForSelect() const { if (isState(GLOBAL)) { - glDrawElements(mPrimType, mIndicesCount, GL_UNSIGNED_INT, getRawIndices()); + glDrawElements(GL_TRIANGLES, mIndicesCount, GL_UNSIGNED_INT, indicesp); } else { glPushMatrix(); glMultMatrixf((float*)getRenderMatrix().mMatrix); - glDrawElements(mPrimType, mIndicesCount, GL_UNSIGNED_INT, getRawIndices()); + glDrawElements(GL_TRIANGLES, mIndicesCount, GL_UNSIGNED_INT, indicesp); glPopMatrix(); } } @@ -716,13 +433,13 @@ void LLFace::renderForSelect() const { if (isState(GLOBAL)) { - glDrawArrays(mPrimType, mGeomIndex, mGeomCount); + glDrawArrays(GL_TRIANGLES, mGeomIndex, mGeomCount); } else { glPushMatrix(); glMultMatrixf((float*)getRenderMatrix().mMatrix); - glDrawArrays(mPrimType, mGeomIndex, mGeomCount); + glDrawArrays(GL_TRIANGLES, mGeomIndex, mGeomCount); glPopMatrix(); } } @@ -731,11 +448,12 @@ void LLFace::renderForSelect() const void LLFace::renderSelected(LLImageGL *imagep, const LLColor4& color, const S32 offset, const S32 count) { - if(mGeomIndex < 0 || mDrawablep.isNull()) + if(mGeomIndex < 0 || mDrawablep.isNull() || mVertexBuffer.isNull()) { return; } - if (mGeomCount > 0) + + if (mGeomCount > 0 && mIndicesCount > 0) { LLGLSPipelineAlpha gls_pipeline_alpha; glColor4fv(color.mV); @@ -748,110 +466,27 @@ void LLFace::renderSelected(LLImageGL *imagep, const LLColor4& color, const S32 glMultMatrixf((float*)getRenderMatrix().mMatrix); } - if (sSafeRenderSelect) - { - glBegin(mPrimType); - if (count) - { - for (S32 i = offset; i < offset + count; i++) - { - LLVector2 tc = mDrawPoolp->getTexCoord(mDrawPoolp->getIndex(getIndicesStart() + i), 0); - glTexCoord2fv(tc.mV); - LLVector3 normal = mDrawPoolp->getNormal(mDrawPoolp->getIndex(getIndicesStart() + i)); - glNormal3fv(normal.mV); - LLVector3 vertex = mDrawPoolp->getVertex(mDrawPoolp->getIndex(getIndicesStart() + i)); - glVertex3fv(vertex.mV); - } - } - else - { - for (U32 i = 0; i < getIndicesCount(); i++) - { - LLVector2 tc = mDrawPoolp->getTexCoord(mDrawPoolp->getIndex(getIndicesStart() + i), 0); - glTexCoord2fv(tc.mV); - LLVector3 normal = mDrawPoolp->getNormal(mDrawPoolp->getIndex(getIndicesStart() + i)); - glNormal3fv(normal.mV); - LLVector3 vertex = mDrawPoolp->getVertex(mDrawPoolp->getIndex(getIndicesStart() + i)); - glVertex3fv(vertex.mV); - } - } - glEnd(); - - if( gSavedSettings.getBOOL("ShowTangentBasis") ) - { - S32 start; - S32 end; - if (count) - { - start = offset; - end = offset + count; - } - else - { - start = 0; - end = getIndicesCount(); - } + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); - LLGLSNoTexture gls_no_texture; - glColor4f(1, 1, 1, 1); - glBegin(GL_LINES); - for (S32 i = start; i < end; i++) - { - LLVector3 vertex = mDrawPoolp->getVertex(mDrawPoolp->getIndex(getIndicesStart() + i)); - glVertex3fv(vertex.mV); - LLVector3 normal = mDrawPoolp->getNormal(mDrawPoolp->getIndex(getIndicesStart() + i)); - glVertex3fv( (vertex + normal * 0.1f).mV ); - } - glEnd(); + mVertexBuffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD); +#if !LL_RELEASE_FOR_DOWNLOAD + LLGLState::checkClientArrays(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD); +#endif + U32* indicesp = ((U32*) mVertexBuffer->getIndicesPointer()) + mIndicesIndex; - if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_BINORMALS_MASK) - { - glColor4f(0, 1, 0, 1); - glBegin(GL_LINES); - for (S32 i = start; i < end; i++) - { - LLVector3 vertex = mDrawPoolp->getVertex(mDrawPoolp->getIndex(getIndicesStart() + i)); - glVertex3fv(vertex.mV); - LLVector3 binormal = mDrawPoolp->getBinormal(mDrawPoolp->getIndex(getIndicesStart() + i)); - glVertex3fv( (vertex + binormal * 0.1f).mV ); - } - glEnd(); - } - } + if (count) + { + glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, indicesp + offset); } else { - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - if (count) - { - if (mIndicesCount > 0) - { - glDrawElements(mPrimType, count, GL_UNSIGNED_INT, getRawIndices() + offset); - } - else - { - llerrs << "Rendering non-indexed volume face!" << llendl; - glDrawArrays(mPrimType, mGeomIndex, mGeomCount); - } - } - else - { - if (mIndicesCount > 0) - { - glDrawElements(mPrimType, mIndicesCount, GL_UNSIGNED_INT, getRawIndices()); - } - else - { - glDrawArrays(mPrimType, mGeomIndex, mGeomCount); - } - } - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); + glDrawElements(GL_TRIANGLES, mIndicesCount, GL_UNSIGNED_INT, indicesp); } - + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + if (!isState(GLOBAL)) { // Restore the tranform for non-global objects @@ -862,6 +497,7 @@ void LLFace::renderSelected(LLImageGL *imagep, const LLColor4& color, const S32 void LLFace::renderSelectedUV(const S32 offset, const S32 count) { +#if 0 LLUUID uv_img_red_blue_id(gViewerArt.getString("uv_test1.tga")); LLUUID uv_img_green_id(gViewerArt.getString("uv_test2.tga")); LLViewerImage* red_blue_imagep = gImageList.getImage(uv_img_red_blue_id, TRUE, TRUE); @@ -911,7 +547,7 @@ void LLFace::renderSelectedUV(const S32 offset, const S32 count) glPolygonOffset(factor, bias); if (sSafeRenderSelect) { - glBegin(mPrimType); + glBegin(GL_TRIANGLES); if (count) { for (S32 i = offset; i < offset + count; i++) @@ -943,7 +579,7 @@ void LLFace::renderSelectedUV(const S32 offset, const S32 count) { if (mIndicesCount > 0) { - glDrawElements(mPrimType, count, GL_UNSIGNED_INT, getRawIndices() + offset); + glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, getRawIndices() + offset); } else { @@ -955,15 +591,14 @@ void LLFace::renderSelectedUV(const S32 offset, const S32 count) { if (mIndicesCount > 0) { - glDrawElements(mPrimType, mIndicesCount, GL_UNSIGNED_INT, getRawIndices()); + glDrawElements(GL_TRIANGLES, mIndicesCount, GL_UNSIGNED_INT, getRawIndices()); } else { - glDrawArrays(mPrimType, mGeomIndex, mGeomCount); + glDrawArrays(GL_TRIANGLES, mGeomIndex, mGeomCount); } } glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); } glDisable(GL_POLYGON_OFFSET_FILL); @@ -984,12 +619,13 @@ void LLFace::renderSelectedUV(const S32 offset, const S32 count) //restore blend func glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif } void LLFace::printDebugInfo() const { - LLDrawPool *poolp = getPool(); + LLFacePool *poolp = getPool(); llinfos << "Object: " << getViewerObject()->mID << llendl; if (getDrawable()) { @@ -1005,10 +641,6 @@ void LLFace::printDebugInfo() const } llinfos << "Face: " << this << llendl; - if (isState(BACKLIST)) - { - llinfos << "Backlisted!" << llendl; - } llinfos << "State: " << getState() << llendl; llinfos << "Geom Index Data:" << llendl; llinfos << "--------------------" << llendl; @@ -1037,7 +669,7 @@ void LLFace::printDebugInfo() const llinfos << "Incorrect number of pool references!" << llendl; } - +#if 0 llinfos << "Indices:" << llendl; llinfos << "--------------------" << llendl; @@ -1058,222 +690,231 @@ void LLFace::printDebugInfo() const llinfos << mGeomIndex + i << ":" << poolp->getVertex(mGeomIndex + i) << llendl; } llinfos << llendl; +#endif +} + +// Transform the texture coordinates for this face. +static void xform(LLVector2 &tex_coord, F32 cosAng, F32 sinAng, F32 offS, F32 offT, F32 magS, F32 magT) +{ + // New, good way + F32 s = tex_coord.mV[0]; + F32 t = tex_coord.mV[1]; + + // Texture transforms are done about the center of the face. + s -= 0.5; + t -= 0.5; + + // Handle rotation + F32 temp = s; + s = s * cosAng + t * sinAng; + t = -temp * sinAng + t * cosAng; + + // Then scale + s *= magS; + t *= magT; + + // Then offset + s += offS + 0.5f; + t += offT + 0.5f; + + tex_coord.mV[0] = s; + tex_coord.mV[1] = t; } -S32 LLFace::backup() + +BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f, + const LLMatrix4& mat_vert, const LLMatrix3& mat_normal, BOOL global_volume) { LLMemType mt1(LLMemType::MTYPE_DRAWABLE); + + const LLVolumeFace &face = volume.getVolumeFace(f); - if (isState(BACKLIST)) - { - llwarns << "Face is already backed up in LLFace::backup!" << llendl; - return mGeomCount; - } - if (mGeomIndex < 0) - { - // flexible objects can cause this - //llwarns << "No geometry to back-up" << llendl; - return 0; - } - - S32 size = 0; - if (!mBackupMem) - { - size = allocBackupMem(); - } - else + //get bounding box + if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME | LLDrawable::REBUILD_POSITION)) { - llerrs << "Memory already backed up!" << llendl; - } + if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME)) + { //vertex buffer no longer valid + mVertexBuffer = NULL; + mLastVertexBuffer = NULL; + } - // Need to flag this, because we can allocate a non-zero backup mem if we have indices and no geometry. + LLVector3 min,max; + + min = face.mExtents[0]; + max = face.mExtents[1]; - if (mGeomCount || mIndicesCount) - { - setState(BACKLIST); -#if !RELEASE_FOR_DOWNLOAD - if (mGeomIndex < 0 || mIndicesIndex < 0) + //min, max are in volume space, convert to drawable render space + LLVector3 center = ((min + max) * 0.5f)*mat_vert; + LLVector3 size = ((max-min) * 0.5f); + if (!global_volume) { - llerrs << "LLFace::backup" << llendl; + size.scaleVec(mDrawablep->getVObj()->getScale()); } -#endif + LLQuaternion rotation = LLQuaternion(mat_normal); - U32 *backup = (U32*)mBackupMem; - S32 stride = mDrawPoolp->getStride(); + LLVector3 v[4]; + //get 4 corners of bounding box + v[0] = (size * rotation); + v[1] = (LLVector3(-size.mV[0], -size.mV[1], size.mV[2]) * rotation); + v[2] = (LLVector3(size.mV[0], -size.mV[1], -size.mV[2]) * rotation); + v[3] = (LLVector3(-size.mV[0], size.mV[1], -size.mV[2]) * rotation); + + LLVector3& newMin = mExtents[0]; + LLVector3& newMax = mExtents[1]; - U32 *index = mDrawPoolp->getIndices(mIndicesIndex); - for (U32 i=0;imMemory.getMem() + mGeomIndex * stride), mGeomCount * stride); - backup += mGeomCount * stride / 4; - - if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_CLOTHING_WEIGHTS_MASK) - { - memcpy(backup, &mDrawPoolp->getClothingWeight(mGeomIndex), mGeomCount * sizeof(LLVector4)); - backup += mGeomCount*4; - } - - if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_VERTEX_WEIGHTS_MASK) + newMin = newMax = center; + + for (U32 i = 0; i < 4; i++) { - memcpy(backup, &mDrawPoolp->getVertexWeight(mGeomIndex), mGeomCount * sizeof(F32)); - backup += mGeomCount; + for (U32 j = 0; j < 3; j++) + { + F32 delta = fabsf(v[i].mV[j]); + F32 min = center.mV[j] - delta; + F32 max = center.mV[j] + delta; + + if (min < newMin.mV[j]) + { + newMin.mV[j] = min; + } + + if (max > newMax.mV[j]) + { + newMax.mV[j] = max; + } + } } - llassert((U8*)backup - mBackupMem == size); - - unReserve(); + mCenterLocal = (newMin+newMax)*0.5f; + updateCenterAgent(); } - return mGeomCount; + + return TRUE; } -void LLFace::restore() + +BOOL LLFace::getGeometryVolume(const LLVolume& volume, + S32 f, + LLStrider& vertices, + LLStrider& normals, + LLStrider& tex_coords, + LLStrider& tex_coords2, + LLStrider& colors, + LLStrider& indicesp, + const LLMatrix4& mat_vert, const LLMatrix3& mat_normal, + U32& index_offset) { - LLMemType mt1(LLMemType::MTYPE_DRAWABLE); + const LLVolumeFace &vf = volume.getVolumeFace(f); + S32 num_vertices = (S32)vf.mVertices.size(); + S32 num_indices = (S32)vf.mIndices.size(); - if (!isState(BACKLIST)) - { - // flexible objects can cause this -// printDebugInfo(); -// llwarns << "not backlisted for restore" << llendl; - return; - } - if (!mGeomCount || !mBackupMem) - { - if (!mBackupMem) - { - printDebugInfo(); - llwarns << "no backmem for restore" << llendl; - } - - clearState(BACKLIST); - return; - } + LLStrider old_verts; + LLStrider old_texcoords; + LLStrider old_texcoords2; + LLStrider old_normals; + LLStrider old_colors; - S32 stride = mDrawPoolp->getStride(); - mGeomIndex = mDrawPoolp->reserveGeom(mGeomCount); - mIndicesIndex = mDrawPoolp->reserveInd (mIndicesCount); - mGeneration = mDrawPoolp->mGeneration; + BOOL full_rebuild = mDrawablep->isState(LLDrawable::REBUILD_VOLUME); + BOOL moved = TRUE; - llassert(mGeomIndex >= 0); - llassert(mIndicesIndex >= 0); - - U32 *backup = (U32*)mBackupMem; - U32 *index = mDrawPoolp->getIndices(mIndicesIndex); - - for (U32 i=0;igetVOVolume()->isVolumeGlobal(); + LLVector3 scale; + if (global_volume) { - S32 ind = mGeomIndex + *backup; - index[i] = ind; - backup++; + scale.setVec(1,1,1); } - - mDrawPoolp->mMemory.copyToMem(mGeomIndex * stride, (U8 *)backup, mGeomCount * stride); - backup += mGeomCount * stride / 4; - - // - // Don't change the order of these unles you change the corresponding getGeometry calls that read out of - // backup memory, and also the other of the backup/restore pair! - // - if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_CLOTHING_WEIGHTS_MASK) - { - mDrawPoolp->mClothingWeights.copyToMem(mGeomIndex, (U8 *)backup, mGeomCount); - backup += mGeomCount*4; - } - - if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_VERTEX_WEIGHTS_MASK) + else { - mDrawPoolp->mWeights.copyToMem(mGeomIndex, (U8 *)backup, mGeomCount); - backup += mGeomCount; + scale = mVObjp->getScale(); } - delete[] mBackupMem; - mBackupMem = NULL; - clearState(BACKLIST); -} - -// Transform the texture coordinates for this face. -static void xform(LLVector2 &tex_coord, F32 cosAng, F32 sinAng, F32 offS, F32 offT, F32 magS, F32 magT) -{ - // New, good way - F32 s = tex_coord.mV[0]; - F32 t = tex_coord.mV[1]; - - // Texture transforms are done about the center of the face. - s -= 0.5; - t -= 0.5; - - // Handle rotation - F32 temp = s; - s = s * cosAng + t * sinAng; - t = -temp * sinAng + t * cosAng; - - // Then scale - s *= magS; - t *= magT; - - // Then offset - s += offS + 0.5f; - t += offT + 0.5f; + if (!full_rebuild) + { + if (mLastVertexBuffer == mVertexBuffer && + !mVertexBuffer->isEmpty()) + { //this face really doesn't need to be regenerated, try real hard not to do so + if (mLastGeomCount == mGeomCount && + mLastGeomIndex == mGeomIndex && + mLastIndicesCount == mIndicesCount && + mLastIndicesIndex == mIndicesIndex) + { //data is in same location in vertex buffer + moved = FALSE; + } - tex_coord.mV[0] = s; - tex_coord.mV[1] = t; -} + if (!moved && !mDrawablep->isState(LLDrawable::REBUILD_ALL)) + { //nothing needs to be done + vertices += mGeomCount; + normals += mGeomCount; + tex_coords += mGeomCount; + colors += mGeomCount; + tex_coords2 += mGeomCount; + index_offset += mGeomCount; + indicesp += mIndicesCount; + return FALSE; + } + if (mLastGeomCount == mGeomCount) + { + if (mLastGeomIndex >= mGeomIndex && + mLastGeomIndex + mGeomCount+1 < mVertexBuffer->getNumVerts()) + { + //copy from further down the buffer + mVertexBuffer->getVertexStrider(old_verts, mLastGeomIndex); + mVertexBuffer->getTexCoordStrider(old_texcoords, mLastGeomIndex); + mVertexBuffer->getTexCoord2Strider(old_texcoords2, mLastGeomIndex); + mVertexBuffer->getNormalStrider(old_normals, mLastGeomIndex); + mVertexBuffer->getColorStrider(old_colors, mLastGeomIndex); + + if (!mDrawablep->isState(LLDrawable::REBUILD_ALL)) + { + //quick copy + for (S32 i = 0; i < mGeomCount; i++) + { + *vertices++ = *old_verts++; + *tex_coords++ = *old_texcoords++; + *tex_coords2++ = *old_texcoords2++; + *colors++ = *old_colors++; + *normals++ = *old_normals++; + } -BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 f, - const LLMatrix4& mat, const LLMatrix3& inv_trans_mat, BOOL global_volume) -{ - const LLVolumeFace &vf = volume.getVolumeFace(f); - S32 num_vertices = (S32)vf.mVertices.size(); - S32 num_indices = (S32)vf.mIndices.size(); - setSize(num_vertices, num_indices); - - return genVolumeTriangles(volume, f, f, mat, inv_trans_mat, global_volume); -} + for (U32 i = 0; i < mIndicesCount; i++) + { + *indicesp++ = vf.mIndices[i] + index_offset; + } -BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 fstart, S32 fend, - const LLMatrix4& mat_vert, const LLMatrix3& mat_normal, const BOOL global_volume) -{ - LLMemType mt1(LLMemType::MTYPE_DRAWABLE); + index_offset += mGeomCount; + mLastGeomIndex = mGeomIndex; + mLastIndicesCount = mIndicesCount; + mLastIndicesIndex = mIndicesIndex; - if (!mDrawablep) + return TRUE; + } + } + else + { + full_rebuild = TRUE; + } + } + } + else + { + full_rebuild = TRUE; + } + } + else { - return TRUE; + mLastUpdateTime = gFrameTimeSeconds; } - S32 index_offset; - F32 r, os, ot, ms, mt, cos_ang, sin_ang; - LLStrider vertices; - LLStrider normals; - LLStrider binormals; - LLStrider tex_coords; - LLStrider tex_coords2; - U32 *indicesp = NULL; - BOOL bump = mDrawPoolp && (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_BINORMALS_MASK); + BOOL rebuild_pos = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_POSITION); + BOOL rebuild_color = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_COLOR); + BOOL rebuild_tcoord = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_TCOORD); + + F32 r = 0, os = 0, ot = 0, ms = 0, mt = 0, cos_ang = 0, sin_ang = 0; + BOOL is_static = mDrawablep->isStatic(); BOOL is_global = is_static; - - if (bump) - { - index_offset = getGeometryMultiTexture(vertices, normals, binormals, tex_coords, tex_coords2, indicesp); - } - else - { - index_offset = getGeometry(vertices, normals, tex_coords, indicesp); - } + if (-1 == index_offset) { return TRUE; @@ -1281,16 +922,6 @@ BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 fstart, S32 fend, LLVector3 center_sum(0.f, 0.f, 0.f); - LLVector3 render_pos; - - if (mDrawablep->isState(LLDrawable::REBUILD_TCOORD) && - global_volume) - { - render_pos = mVObjp->getRenderPosition(); - } - - setPrimType(LLTriangles); - if (is_global) { setState(GLOBAL); @@ -1299,26 +930,16 @@ BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 fstart, S32 fend, { clearState(GLOBAL); } - - LLVector3 min, max; + LLVector2 tmin, tmax; - BOOL grab_first_vert = TRUE; - BOOL grab_first_tcoord = TRUE; - - for (S32 vol_face = fstart; vol_face <= fend; vol_face++) + const LLTextureEntry *tep = mVObjp->getTE(f); + U8 bump_code = tep ? bump_code = tep->getBumpmap() : 0; + + if (rebuild_tcoord) { - const LLVolumeFace &vf = volume.getVolumeFace(vol_face); - S32 num_vertices = (S32)vf.mVertices.size(); - S32 num_indices = (S32)vf.mIndices.size(); - llassert(num_indices > 0); - - U8 bump_code; - const LLTextureEntry *tep = mVObjp->getTE(vol_face); - if (tep) { - bump_code = tep->getBumpmap(); r = tep->getRotation(); os = tep->mOffsetS; ot = tep->mOffsetT; @@ -1329,7 +950,6 @@ BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 fstart, S32 fend, } else { - bump_code = 0; cos_ang = 1.0f; sin_ang = 0.0f; os = 0.0f; @@ -1337,209 +957,235 @@ BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 fstart, S32 fend, ms = 1.0f; mt = 1.0f; } + } - if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME)) + if (isState(TEXTURE_ANIM)) + { + LLVOVolume* vobj = (LLVOVolume*) (LLViewerObject*) mVObjp; + U8 mode = vobj->mTexAnimMode; + if (!mode) { - // VERTICES & NORMALS - for (S32 i = 0; i < num_vertices; i++) + clearState(TEXTURE_ANIM); + } + else + { + //if (mode & LLViewerTextureAnim::TRANSLATE) { - LLVector3 v; - v = vf.mVertices[i].mPosition * mat_vert; - - LLVector3 normal = vf.mVertices[i].mNormal * mat_normal; - normal.normVec(); - *normals++ = normal; - - *vertices++ = v; - - if (grab_first_vert) - { - grab_first_vert = FALSE; - min = max = v; - } - else - { - for (U32 j = 0; j < 3; j++) - { - if (v.mV[j] < min.mV[j]) - { - min.mV[j] = v.mV[j]; - } - if (v.mV[j] > max.mV[j]) - { - max.mV[j] = v.mV[j]; - } - } - } + os = ot = 0.f; } - for (S32 i = 0; i < num_indices; i++) + //if (mode & LLViewerTextureAnim::ROTATE) { - S32 index = vf.mIndices[i] + index_offset; - llassert(index >= 0 && (i != 1 || *(indicesp-1)!=(U32)index)); - *indicesp++ = index; + r = 0.f; + cos_ang = 1.f; + sin_ang = 0.f; + } + //if (mode & LLViewerTextureAnim::SCALE) + { + ms = mt = 1.f; } } + } - if ((mDrawablep->isState(LLDrawable::REBUILD_TCOORD)) || - ((bump || getTextureEntry()->getTexGen() != 0) && mDrawablep->isState(LLDrawable::REBUILD_VOLUME))) + LLColor4U color = tep->getColor(); + + if (rebuild_color) + { + GLfloat alpha[4] = { - // TEX COORDS AND BINORMALS - LLVector3 binormal_dir( -sin_ang, cos_ang, 0 ); - LLVector3 bump_s_primary_light_ray; - LLVector3 bump_t_primary_light_ray; - if (bump) - { - F32 offset_multiple; - switch( bump_code ) - { - case BE_NO_BUMP: - offset_multiple = 0.f; - break; - case BE_BRIGHTNESS: - case BE_DARKNESS: - if( mTexture.notNull() && mTexture->getHasGLTexture()) - { - // Offset by approximately one texel - S32 cur_discard = mTexture->getDiscardLevel(); - S32 max_size = llmax( mTexture->getWidth(), mTexture->getHeight() ); - max_size <<= cur_discard; - const F32 ARTIFICIAL_OFFSET = 2.f; - offset_multiple = ARTIFICIAL_OFFSET / (F32)max_size; - } - else - { - offset_multiple = 1.f/256; - } - break; + 0.00f, + 0.25f, + 0.5f, + 0.75f + }; - default: // Standard bumpmap textures. Assumed to be 256x256 - offset_multiple = 1.f / 256; - break; - } + if (gPipeline.getPoolTypeFromTE(tep, getTexture()) == LLDrawPool::POOL_BUMP) + { + color.mV[3] = U8 (alpha[tep->getShiny()] * 255); + } + } - F32 s_scale = 1.f; - F32 t_scale = 1.f; - if( tep ) - { - tep->getScale( &s_scale, &t_scale ); - } - LLVector3 sun_ray = gSky.getSunDirection(); - LLVector3 moon_ray = gSky.getMoonDirection(); - LLVector3& primary_light_ray = (sun_ray.mV[VZ] > 0) ? sun_ray : moon_ray; - bump_s_primary_light_ray = offset_multiple * s_scale * primary_light_ray; - bump_t_primary_light_ray = offset_multiple * t_scale * primary_light_ray; + // INDICES + if (full_rebuild || moved) + { + for (S32 i = 0; i < num_indices; i++) + { + *indicesp++ = vf.mIndices[i] + index_offset; + } + } + else + { + indicesp += num_indices; + } + + //bump setup + LLVector3 binormal_dir( -sin_ang, cos_ang, 0 ); + LLVector3 bump_s_primary_light_ray; + LLVector3 bump_t_primary_light_ray; + + if (bump_code) + { + F32 offset_multiple; + switch( bump_code ) + { + case BE_NO_BUMP: + offset_multiple = 0.f; + break; + case BE_BRIGHTNESS: + case BE_DARKNESS: + if( mTexture.notNull() && mTexture->getHasGLTexture()) + { + // Offset by approximately one texel + S32 cur_discard = mTexture->getDiscardLevel(); + S32 max_size = llmax( mTexture->getWidth(), mTexture->getHeight() ); + max_size <<= cur_discard; + const F32 ARTIFICIAL_OFFSET = 2.f; + offset_multiple = ARTIFICIAL_OFFSET / (F32)max_size; } - - for (S32 i = 0; i < num_vertices; i++) + else { - LLVector2 tc = vf.mVertices[i].mTexCoord; + offset_multiple = 1.f/256; + } + break; - U8 texgen = getTextureEntry()->getTexGen(); - if (texgen != LLTextureEntry::TEX_GEN_DEFAULT) - { + default: // Standard bumpmap textures. Assumed to be 256x256 + offset_multiple = 1.f / 256; + break; + } - LLVector3 vec = vf.mVertices[i].mPosition; //-vf.mCenter; - - if (global_volume) - { - vec -= render_pos; - } - else - { - vec.scaleVec(mVObjp->getScale()); - } + F32 s_scale = 1.f; + F32 t_scale = 1.f; + if( tep ) + { + tep->getScale( &s_scale, &t_scale ); + } + LLVector3 sun_ray = gSky.getSunDirection(); + LLVector3 moon_ray = gSky.getMoonDirection(); + LLVector3& primary_light_ray = (sun_ray.mV[VZ] > 0) ? sun_ray : moon_ray; + bump_s_primary_light_ray = offset_multiple * s_scale * primary_light_ray; + bump_t_primary_light_ray = offset_multiple * t_scale * primary_light_ray; + } + + U8 texgen = getTextureEntry()->getTexGen(); - switch (texgen) - { - case LLTextureEntry::TEX_GEN_PLANAR: - planarProjection(tc, vf.mVertices[i], vf.mCenter, vec); - break; - case LLTextureEntry::TEX_GEN_SPHERICAL: - sphericalProjection(tc, vf.mVertices[i], vf.mCenter, vec); - break; - case LLTextureEntry::TEX_GEN_CYLINDRICAL: - cylindricalProjection(tc, vf.mVertices[i], vf.mCenter, vec); - break; - default: - break; - } - } - xform(tc, cos_ang, sin_ang, os, ot, ms, mt); - *tex_coords++ = tc; - if (grab_first_tcoord) - { - grab_first_tcoord = FALSE; - tmin = tmax = tc; - } - else - { - for (U32 j = 0; j < 2; j++) - { - if (tmin.mV[j] > tc.mV[j]) - { - tmin.mV[j] = tc.mV[j]; - } - else if (tmax.mV[j] < tc.mV[j]) - { - tmax.mV[j] = tc.mV[j]; - } - } - } - if (bump) + for (S32 i = 0; i < num_vertices; i++) + { + if (rebuild_tcoord) + { + LLVector2 tc = vf.mVertices[i].mTexCoord; + + if (texgen != LLTextureEntry::TEX_GEN_DEFAULT) + { + LLVector3 vec = vf.mVertices[i].mPosition; + + vec.scaleVec(scale); + + switch (texgen) { - LLVector3 tangent = vf.mVertices[i].mBinormal % vf.mVertices[i].mNormal; - LLMatrix3 tangent_to_object; - tangent_to_object.setRows(tangent, vf.mVertices[i].mBinormal, vf.mVertices[i].mNormal); - LLVector3 binormal = binormal_dir * tangent_to_object; + case LLTextureEntry::TEX_GEN_PLANAR: + planarProjection(tc, vf.mVertices[i], vf.mCenter, vec); + break; + case LLTextureEntry::TEX_GEN_SPHERICAL: + sphericalProjection(tc, vf.mVertices[i], vf.mCenter, vec); + break; + case LLTextureEntry::TEX_GEN_CYLINDRICAL: + cylindricalProjection(tc, vf.mVertices[i], vf.mCenter, vec); + break; + default: + break; + } + } - if (!global_volume) - { - binormal = binormal * mat_normal; - } - binormal.normVec(); - tangent.normVec(); - - tc += LLVector2( bump_s_primary_light_ray * tangent, bump_t_primary_light_ray * binormal ); - *tex_coords2++ = tc; + xform(tc, cos_ang, sin_ang, os, ot, ms, mt); + *tex_coords++ = tc; + + if (bump_code) + { + LLVector3 tangent = vf.mVertices[i].mBinormal % vf.mVertices[i].mNormal; + LLMatrix3 tangent_to_object; + tangent_to_object.setRows(tangent, vf.mVertices[i].mBinormal, vf.mVertices[i].mNormal); + LLVector3 binormal = binormal_dir * tangent_to_object; - *binormals++ = binormal; - } + binormal = binormal * mat_normal; + binormal.normVec(); + + tc += LLVector2( bump_s_primary_light_ray * tangent, bump_t_primary_light_ray * binormal ); + *tex_coords2++ = tc; + } + } + else if (moved) + { + *tex_coords++ = *old_texcoords++; + if (bump_code) + { + *tex_coords2++ = *old_texcoords2++; } } + + if (rebuild_pos) + { + *vertices++ = vf.mVertices[i].mPosition * mat_vert; - index_offset += num_vertices; + LLVector3 normal = vf.mVertices[i].mNormal * mat_normal; + normal.normVec(); + + *normals++ = normal; + } + else if (moved) + { + *normals++ = *old_normals++; + *vertices++ = *old_verts++; + } + + if (rebuild_color) + { + *colors++ = color; + } + else if (moved) + { + *colors++ = *old_colors++; + } + } - center_sum += vf.mCenter * mat_vert; + if (!rebuild_pos && !moved) + { + vertices += num_vertices; } - - center_sum /= (F32)(fend-fstart+1); - - if (is_static) + + if (!rebuild_tcoord && !moved) { - mCenterAgent = center_sum; - mCenterLocal = mCenterAgent - mDrawablep->getPositionAgent(); + tex_coords2 += num_vertices; + tex_coords += num_vertices; } - else + else if (!bump_code) { - mCenterLocal = center_sum; - updateCenterAgent(); + tex_coords2 += num_vertices; } - - if (!grab_first_vert && mDrawablep->isState(LLDrawable::REBUILD_VOLUME)) + + if (!rebuild_color && !moved) { - mExtents[0] = min; - mExtents[1] = max; + colors += num_vertices; } - - if (!grab_first_tcoord && mDrawablep->isState(LLDrawable::REBUILD_TCOORD)) + + if (rebuild_tcoord) { - mTexExtents[0] = tmin; - mTexExtents[1] = tmax; + mTexExtents[0].setVec(0,0); + mTexExtents[1].setVec(1,1); + xform(mTexExtents[0], cos_ang, sin_ang, os, ot, ms, mt); + xform(mTexExtents[1], cos_ang, sin_ang, os, ot, ms, mt); } - + + index_offset += num_vertices; + + mLastVertexBuffer = mVertexBuffer; + mLastGeomCount = mGeomCount; + mLastGeomIndex = mGeomIndex; + mLastIndicesCount = mIndicesCount; + mLastIndicesIndex = mIndicesIndex; + return TRUE; } +#if 0 BOOL LLFace::genLighting(const LLVolume* volume, const LLDrawable* drawablep, S32 fstart, S32 fend, const LLMatrix4& mat_vert, const LLMatrix3& mat_normal, BOOL do_lighting) { @@ -1662,21 +1308,20 @@ BOOL LLFace::genShadows(const LLVolume* volume, const LLDrawable* drawablep, S32 } return TRUE; } +#endif BOOL LLFace::verify(const U32* indices_array) const { BOOL ok = TRUE; // First, check whether the face data fits within the pool's range. - if ((mGeomIndex < 0) || (mGeomIndex + mGeomCount) > (S32)getPool()->getVertexCount()) + if ((mGeomIndex < 0) || (mGeomIndex + mGeomCount) > mVertexBuffer->getNumVerts()) { ok = FALSE; llinfos << "Face not within pool range!" << llendl; } S32 indices_count = (S32)getIndicesCount(); - S32 geom_start = getGeomStart(); - S32 geom_count = mGeomCount; - + if (!indices_count) { return TRUE; @@ -1688,6 +1333,10 @@ BOOL LLFace::verify(const U32* indices_array) const llinfos << "Face has bogus indices count" << llendl; } +#if 0 + S32 geom_start = getGeomStart(); + S32 geom_count = mGeomCount; + const U32 *indicesp = indices_array ? indices_array + mIndicesIndex : getRawIndices(); for (S32 i = 0; i < indices_count; i++) @@ -1706,6 +1355,7 @@ BOOL LLFace::verify(const U32* indices_array) const ok = FALSE; } } +#endif if (!ok) { @@ -1756,7 +1406,7 @@ const LLColor4& LLFace::getRenderColor() const void LLFace::renderSetColor() const { - if (!LLDrawPool::LLOverrideFaceColor::sOverrideFaceColor) + if (!LLFacePool::LLOverrideFaceColor::sOverrideFaceColor) { const LLColor4* color = &(getRenderColor()); @@ -1773,61 +1423,21 @@ void LLFace::renderSetColor() const S32 LLFace::pushVertices(const U32* index_array) const { - U32 indices_count = mIndicesCount; - S32 ret = 0; -#if ENABLE_FACE_LINKING - LLFace* next = mNextFace; -#endif - - if (mGeomCount < gGLManager.mGLMaxVertexRange && (S32) indices_count < gGLManager.mGLMaxIndexRange) + if (mIndicesCount) { - LLFace* current = (LLFace*) this; - S32 geom_count = mGeomCount; -#if ENABLE_FACE_LINKING - while (current) + if (mGeomCount <= gGLManager.mGLMaxVertexRange && + mIndicesCount <= (U32) gGLManager.mGLMaxIndexRange) { - //chop up batch into implementation recommended sizes - while (next && - (current == next || - ((S32) (indices_count + next->mIndicesCount) < gGLManager.mGLMaxIndexRange && - geom_count + next->mGeomCount < gGLManager.mGLMaxVertexRange))) - { - indices_count += next->mIndicesCount; - geom_count += next->mGeomCount; - next = next->mNextFace; - } -#endif - if (indices_count) - { - glDrawRangeElements(mPrimType, current->mGeomIndex, current->mGeomIndex + geom_count, indices_count, - GL_UNSIGNED_INT, index_array + current->mIndicesIndex); - } - ret += (S32) indices_count; - indices_count = 0; - geom_count = 0; -#if ENABLE_FACE_LINKING - current = next; + glDrawRangeElements(GL_TRIANGLES, mGeomIndex, mGeomIndex + mGeomCount-1, mIndicesCount, + GL_UNSIGNED_INT, index_array + mIndicesIndex); } -#endif - } - else - { -#if ENABLE_FACE_LINKING - while (next) - { - indices_count += next->mIndicesCount; - next = next->mNextFace; - } -#endif - if (indices_count) + else { - glDrawElements(mPrimType, indices_count, GL_UNSIGNED_INT, index_array + mIndicesIndex); + glDrawElements(GL_TRIANGLES, mIndicesCount, GL_UNSIGNED_INT, index_array+mIndicesIndex); } - ret += (S32) indices_count; } - return ret; - + return mIndicesCount; } const LLMatrix4& LLFace::getRenderMatrix() const @@ -1854,19 +1464,25 @@ S32 LLFace::renderElements(const U32 *index_array) const return ret; } -S32 LLFace::renderIndexed(const U32 *index_array) const +S32 LLFace::renderIndexed() { - if (mSkipRender) + if(mGeomIndex < 0 || mDrawablep.isNull() || mDrawPoolp == NULL) { return 0; } + + return renderIndexed(mDrawPoolp->getVertexDataMask()); +} - if(mGeomIndex < 0 || mDrawablep.isNull()) +S32 LLFace::renderIndexed(U32 mask) +{ + if (mVertexBuffer.isNull()) { return 0; } - - renderSetColor(); + + mVertexBuffer->setBuffer(mask); + U32* index_array = (U32*) mVertexBuffer->getIndicesPointer(); return renderElements(index_array); } @@ -1879,26 +1495,13 @@ S32 LLFace::getVertices(LLStrider &vertices) { return -1; } - if (isState(BACKLIST)) - { - if (!mBackupMem) - { - printDebugInfo(); - llerrs << "No backup memory for face" << llendl; - } - vertices = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_VERTICES]); - vertices.setStride( mDrawPoolp->getStride()); - return 0; - } - else + + if (mGeomIndex >= 0) // flexible objects may not have geometry { - if (mGeomIndex >= 0) // flexible objects may not have geometry - { - mDrawPoolp->getVertexStrider(vertices, mGeomIndex); - mDrawPoolp->setDirty(); - } - return mGeomIndex; + mVertexBuffer->getVertexStrider(vertices, mGeomIndex); + } + return mGeomIndex; } S32 LLFace::getColors(LLStrider &colors) @@ -1907,42 +1510,17 @@ S32 LLFace::getColors(LLStrider &colors) { return -1; } - if (isState(BACKLIST)) - { - llassert(mBackupMem); - colors = (LLColor4U*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_COLORS]); - colors.setStride( mDrawPoolp->getStride()); - return 0; - } - else - { - llassert(mGeomIndex >= 0); - mDrawPoolp->getColorStrider(colors, mGeomIndex); - return mGeomIndex; - } -} - -S32 LLFace::getIndices(U32* &indicesp) -{ - if (isState(BACKLIST)) - { - indicesp = (U32*)mBackupMem; - return 0; - } - else - { - indicesp = mDrawPoolp->getIndices(mIndicesIndex); - llassert(mGeomIndex >= 0 && indicesp[0] != indicesp[1]); - return mGeomIndex; - } + + llassert(mGeomIndex >= 0); + mVertexBuffer->getColorStrider(colors, mGeomIndex); + return mGeomIndex; } -void LLFace::link(LLFace* facep) +S32 LLFace::getIndices(LLStrider &indicesp) { -#if ENABLE_FACE_LINKING - mNextFace = facep; - facep->mSkipRender = TRUE; -#endif + mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex); + llassert(mGeomIndex >= 0 && indicesp[0] != indicesp[1]); + return mIndicesIndex; } LLVector3 LLFace::getPositionAgent() const -- cgit v1.1