Aligned index buffers.
parent
05a23f8dba
commit
e90d2f88e5
|
|
@ -453,6 +453,7 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) :
|
|||
mTypeMask = typemask;
|
||||
mStride = stride;
|
||||
mAlignedOffset = 0;
|
||||
mAlignedIndexOffset = 0;
|
||||
|
||||
sCount++;
|
||||
}
|
||||
|
|
@ -642,16 +643,20 @@ void LLVertexBuffer::createGLIndices()
|
|||
|
||||
mEmpty = TRUE;
|
||||
|
||||
//pad by 16 bytes for aligned copies
|
||||
size += 16;
|
||||
|
||||
if (useVBOs())
|
||||
{
|
||||
//pad by another 16 bytes for VBO pointer adjustment
|
||||
size += 16;
|
||||
mMappedIndexData = NULL;
|
||||
genIndices();
|
||||
mResized = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
mMappedIndexData = new U8[size];
|
||||
memset(mMappedIndexData, 0, size);
|
||||
mMappedIndexData = (U8*) _mm_malloc(size, 16);
|
||||
static int gl_buffer_idx = 0;
|
||||
mGLIndices = ++gl_buffer_idx;
|
||||
}
|
||||
|
|
@ -699,7 +704,7 @@ void LLVertexBuffer::destroyGLIndices()
|
|||
}
|
||||
else
|
||||
{
|
||||
delete [] mMappedIndexData;
|
||||
_mm_free(mMappedIndexData);
|
||||
mMappedIndexData = NULL;
|
||||
mEmpty = TRUE;
|
||||
}
|
||||
|
|
@ -836,26 +841,10 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices)
|
|||
}
|
||||
else
|
||||
{
|
||||
//delete old buffer, keep GL buffer for now
|
||||
if (!useVBOs())
|
||||
{
|
||||
U8* old = mMappedData;
|
||||
mMappedData = new U8[newsize];
|
||||
if (old)
|
||||
{
|
||||
memcpy(mMappedData, old, llmin(newsize, oldsize));
|
||||
if (newsize > oldsize)
|
||||
{
|
||||
memset(mMappedData+oldsize, 0, newsize-oldsize);
|
||||
}
|
||||
|
||||
delete [] old;
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(mMappedData, 0, newsize);
|
||||
mEmpty = TRUE;
|
||||
}
|
||||
_mm_free(mMappedData);
|
||||
mMappedData = (U8*) _mm_malloc(newsize, 16);
|
||||
}
|
||||
mResized = TRUE;
|
||||
}
|
||||
|
|
@ -875,24 +864,8 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices)
|
|||
{
|
||||
if (!useVBOs())
|
||||
{
|
||||
//delete old buffer, keep GL buffer for now
|
||||
U8* old = mMappedIndexData;
|
||||
mMappedIndexData = new U8[new_index_size];
|
||||
|
||||
if (old)
|
||||
{
|
||||
memcpy(mMappedIndexData, old, llmin(new_index_size, old_index_size));
|
||||
if (new_index_size > old_index_size)
|
||||
{
|
||||
memset(mMappedIndexData+old_index_size, 0, new_index_size - old_index_size);
|
||||
}
|
||||
delete [] old;
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(mMappedIndexData, 0, new_index_size);
|
||||
mEmpty = TRUE;
|
||||
}
|
||||
_mm_free(mMappedIndexData);
|
||||
mMappedIndexData = (U8*) _mm_malloc(new_index_size, 16);
|
||||
}
|
||||
mResized = TRUE;
|
||||
}
|
||||
|
|
@ -958,7 +931,10 @@ U8* LLVertexBuffer::mapBuffer(S32 access)
|
|||
}
|
||||
{
|
||||
LLMemType mt_v(LLMemType::MTYPE_VERTEX_MAP_BUFFER_INDICES);
|
||||
mMappedIndexData = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
|
||||
U8* src = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
|
||||
mMappedIndexData = LL_NEXT_ALIGNED_ADDRESS<U8>(src);
|
||||
mAlignedIndexOffset = mMappedIndexData - src;
|
||||
|
||||
stop_glerror();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ public:
|
|||
S32 getRequestedVerts() const { return mRequestedNumVerts; }
|
||||
S32 getRequestedIndices() const { return mRequestedNumIndices; }
|
||||
|
||||
U8* getIndicesPointer() const { return useVBOs() ? NULL : mMappedIndexData; }
|
||||
U8* getIndicesPointer() const { return useVBOs() ? (U8*) mAlignedIndexOffset : mMappedIndexData; }
|
||||
U8* getVerticesPointer() const { return useVBOs() ? NULL : mMappedData; }
|
||||
S32 getStride() const { return mStride; }
|
||||
U32 getTypeMask() const { return mTypeMask; }
|
||||
|
|
@ -214,6 +214,7 @@ protected:
|
|||
S32 mRequestedNumIndices; // Number of indices requested
|
||||
|
||||
ptrdiff_t mAlignedOffset;
|
||||
ptrdiff_t mAlignedIndexOffset;
|
||||
S32 mStride;
|
||||
U32 mTypeMask;
|
||||
S32 mUsage; // GL usage
|
||||
|
|
|
|||
|
|
@ -1542,27 +1542,30 @@ LLVertexBufferAvatar::LLVertexBufferAvatar()
|
|||
|
||||
void LLVertexBufferAvatar::setupVertexBuffer(U32 data_mask) const
|
||||
{
|
||||
/* if (sRenderingSkinned)
|
||||
if (sRenderingSkinned)
|
||||
{
|
||||
U8* base = useVBOs() ? NULL : mMappedData;
|
||||
|
||||
glVertexPointer(3,GL_FLOAT, mStride, (void*)(base + 0));
|
||||
glNormalPointer(GL_FLOAT, mStride, (void*)(base + mOffsets[TYPE_NORMAL]));
|
||||
glTexCoordPointer(2,GL_FLOAT, mStride, (void*)(base + mOffsets[TYPE_TEXCOORD0]));
|
||||
glVertexPointer(3,GL_FLOAT, LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_VERTEX], (void*)(base + 0));
|
||||
glNormalPointer(GL_FLOAT, LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_NORMAL], (void*)(base + mOffsets[TYPE_NORMAL]));
|
||||
glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_TEXCOORD0], (void*)(base + mOffsets[TYPE_TEXCOORD0]));
|
||||
|
||||
set_vertex_weights(LLDrawPoolAvatar::sVertexProgram->mAttribute[LLViewerShaderMgr::AVATAR_WEIGHT], mStride, (F32*)(base + mOffsets[TYPE_WEIGHT]));
|
||||
set_vertex_weights(LLDrawPoolAvatar::sVertexProgram->mAttribute[LLViewerShaderMgr::AVATAR_WEIGHT],
|
||||
LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_WEIGHT], (F32*)(base + mOffsets[TYPE_WEIGHT]));
|
||||
|
||||
if (sShaderLevel >= LLDrawPoolAvatar::SHADER_LEVEL_BUMP)
|
||||
{
|
||||
set_binormals(LLDrawPoolAvatar::sVertexProgram->mAttribute[LLViewerShaderMgr::BINORMAL], mStride, (LLVector3*)(base + mOffsets[TYPE_BINORMAL]));
|
||||
set_binormals(LLDrawPoolAvatar::sVertexProgram->mAttribute[LLViewerShaderMgr::BINORMAL],
|
||||
LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_BINORMAL], (LLVector3*)(base + mOffsets[TYPE_BINORMAL]));
|
||||
}
|
||||
|
||||
if (sShaderLevel >= LLDrawPoolAvatar::SHADER_LEVEL_CLOTH)
|
||||
{
|
||||
set_vertex_clothing_weights(LLDrawPoolAvatar::sVertexProgram->mAttribute[LLViewerShaderMgr::AVATAR_CLOTHING], mStride, (LLVector4*)(base + mOffsets[TYPE_CLOTHWEIGHT]));
|
||||
set_vertex_clothing_weights(LLDrawPoolAvatar::sVertexProgram->mAttribute[LLViewerShaderMgr::AVATAR_CLOTHING],
|
||||
LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_CLOTHWEIGHT], (LLVector4*)(base + mOffsets[TYPE_CLOTHWEIGHT]));
|
||||
}
|
||||
}
|
||||
else*/
|
||||
else
|
||||
{
|
||||
LLVertexBuffer::setupVertexBuffer(data_mask);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue