コード例 #1
0
ファイル: llvertexbuffer.cpp プロジェクト: xinyaojiejie/Dale
void LLVertexBuffer::createGLIndices()
{
	LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
	U32 size = getIndicesSize();

	if (mGLIndices)
	{
		destroyGLIndices();
	}
	
	if (size == 0)
	{
		return;
	}

	mMappedIndexData = new U8[size];
	memset(mMappedIndexData, 0, size);
	mEmpty = TRUE;

	if (useVBOs())
	{
		glGenBuffersARB(1, (GLuint*) &mGLIndices);
		mResized = TRUE;
		sGLCount++;
	}
	else
	{
		static int gl_buffer_idx = 0;
		mGLIndices = ++gl_buffer_idx;
	}
}
コード例 #2
0
void LLVertexBuffer::createGLIndices()
{
	LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
	U32 size = getIndicesSize();

	if (mGLIndices)
	{
		destroyGLIndices();
	}
	
	if (size == 0)
	{
		return;
	}

	mEmpty = TRUE;

	if (useVBOs())
	{
		mMappedIndexData = NULL;
		genIndices();
		mResized = TRUE;
	}
	else
	{
		mMappedIndexData = new U8[size];
		if(!sOmitBlank) memset((void*)mMappedIndexData, 0, size);
		static int gl_buffer_idx = 0;
		mGLIndices = ++gl_buffer_idx;
	}
}
コード例 #3
0
// protected, use unref()
//virtual
LLVertexBuffer::~LLVertexBuffer()
{
	LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
	destroyGLBuffer();
	destroyGLIndices();
	sCount--;
};
コード例 #4
0
// protected, use unref()
//virtual
LLVertexBuffer::~LLVertexBuffer()
{
	LLMemType mt2(LLMemType::MTYPE_VERTEX_DESTRUCTOR);
	destroyGLBuffer();
	destroyGLIndices();
	sCount--;
};
コード例 #5
0
// protected, use unref()
//virtual
LLVertexBuffer::~LLVertexBuffer()
{
	LLMemType mt2(LLMemType::MTYPE_VERTEX_DESTRUCTOR);
	destroyGLBuffer();
	destroyGLIndices();
	sCount--;

	llassert_always(!mMappedData && !mMappedIndexData) ;
};
コード例 #6
0
ファイル: llvertexbuffer.cpp プロジェクト: xinyaojiejie/Dale
// protected, use unref()
//virtual
LLVertexBuffer::~LLVertexBuffer()
{
	LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
	destroyGLBuffer();
	destroyGLIndices();
	sCount--;
	
	if (mLocked)
	{
		//pull off of locked list
		for (buffer_list_t::iterator i = sLockedList.begin(); i != sLockedList.end(); ++i)
		{
			if (*i == this)
			{
				sLockedList.erase(i);
				break;
			}
		}
	}
};
コード例 #7
0
void LLVertexBuffer::createGLIndices()
{
	LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
	U32 size = getIndicesSize();

	if (mGLIndices)
	{
		destroyGLIndices();
	}
	
	if (size == 0)
	{
		return;
	}

	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 = (U8*) ll_aligned_malloc_16(size);
		if(!sOmitBlank) memset((void*)mMappedIndexData, 0, size);
		static int gl_buffer_idx = 0;
		mGLIndices = ++gl_buffer_idx;
	}
}
コード例 #8
0
ファイル: llvertexbuffer.cpp プロジェクト: xinyaojiejie/Dale
void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices)
{
	LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
	mDynamicSize = TRUE;
	if (mUsage == GL_STATIC_DRAW_ARB)
	{ //always delete/allocate static buffers on resize
		destroyGLBuffer();
		destroyGLIndices();
		allocateBuffer(newnverts, newnindices, TRUE);
		mFinal = FALSE;
	}
	else if (newnverts > mNumVerts || newnindices > mNumIndices ||
			 newnverts < mNumVerts/2 || newnindices < mNumIndices/2)
	{
		sAllocatedBytes -= getSize() + getIndicesSize();
		
		S32 oldsize = getSize();
		S32 old_index_size = getIndicesSize();

		updateNumVerts(newnverts);		
		updateNumIndices(newnindices);
		
		S32 newsize = getSize();
		S32 new_index_size = getIndicesSize();

		sAllocatedBytes += newsize + new_index_size;

		if (newsize)
		{
			if (!mGLBuffer)
			{ //no buffer exists, create a new one
				createGLBuffer();
			}
			else
			{
				//delete old buffer, keep GL buffer for now
				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;
				}
				mResized = TRUE;
			}
		}
		else if (mGLBuffer)
		{
			destroyGLBuffer();
		}
		
		if (new_index_size)
		{
			if (!mGLIndices)
			{
				createGLIndices();
			}
			else
			{
				//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;
				}
				mResized = TRUE;
			}
		}
		else if (mGLIndices)
		{
			destroyGLIndices();
		}
	}
}
コード例 #9
0
void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices)
{
	llassert(newnverts >= 0);
	llassert(newnindices >= 0);

	mRequestedNumVerts = newnverts;
	mRequestedNumIndices = newnindices;

	LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
	mDynamicSize = TRUE;
	if (mUsage == GL_STATIC_DRAW_ARB)
	{ //always delete/allocate static buffers on resize
		destroyGLBuffer();
		destroyGLIndices();
		allocateBuffer(newnverts, newnindices, TRUE);
		mFinal = FALSE;
	}
	else if (newnverts > mNumVerts || newnindices > mNumIndices ||
			 newnverts < mNumVerts/2 || newnindices < mNumIndices/2)
	{
		sAllocatedBytes -= getSize() + getIndicesSize();
		
		S32 oldsize = getSize();
		S32 old_index_size = getIndicesSize();

		updateNumVerts(newnverts);		
		updateNumIndices(newnindices);
		
		S32 newsize = getSize();
		S32 new_index_size = getIndicesSize();

		sAllocatedBytes += newsize + new_index_size;

		if (newsize)
		{
			if (!mGLBuffer)
			{ //no buffer exists, create a new one
				createGLBuffer();
			}
			else
			{
				//delete old buffer, keep GL buffer for now
				if (!useVBOs())
				{
					volatile U8* old = mMappedData;
					mMappedData =  (U8*) ll_aligned_malloc_16(newsize);
					if (old)
					{	
						memcpy((void*)mMappedData, (void*)old, llmin(newsize, oldsize));
						if ((newsize > oldsize) && !sOmitBlank)
						{
							memset((void*)(mMappedData+oldsize), 0, newsize-oldsize);
						}

						ll_aligned_free_16((void*)old);
					}
					else
					{
						if (!sOmitBlank) memset((void*)mMappedData, 0, newsize);
						mEmpty = TRUE;
					}
				}
				mResized = TRUE;
			}
		}
		else if (mGLBuffer)
		{
			destroyGLBuffer();
		}
		
		if (new_index_size)
		{
			if (!mGLIndices)
			{
				createGLIndices();
			}
			else
			{
				if (!useVBOs())
				{
					//delete old buffer, keep GL buffer for now
					volatile U8* old = mMappedIndexData;
					mMappedIndexData = (U8*) ll_aligned_malloc_16(new_index_size);
					
					if (old)
					{	
						memcpy((void*)mMappedIndexData, (void*)old, llmin(new_index_size, old_index_size));
						if ((new_index_size > old_index_size) && !sOmitBlank)
						{
							memset((void*)(mMappedIndexData+old_index_size), 0, new_index_size - old_index_size);
						}
						ll_aligned_free_16((void*)old);
					}
					else
					{
						if (!sOmitBlank) memset((void*)mMappedIndexData, 0, new_index_size);
						mEmpty = TRUE;
					}
				}
				mResized = TRUE;
			}
		}
		else if (mGLIndices)
		{
			destroyGLIndices();
		}
	}

	if (mResized && useVBOs())
	{
		freeClientBuffer() ;
		setBuffer(0);
	}
}