Ejemplo n.º 1
0
/** 
 * Resizes the buffer to the passed in number of indices.  
 * Preserves internal data
 */
void FSlateOpenGLVertexBuffer::ResizeBuffer( uint32 NewSize )
{
	ConditionalCreateBuffer();

	// Only resize if the buffer cant provide the number of bytes requestd
	if( NewSize > BufferSize )
	{
		uint8 *SavedVertices = NULL;

		// If there are any indices at all save them off now
		if( BufferSize > 0 )
		{
			void *Vertices = Lock( 0 );

			SavedVertices = new uint8[BufferSize];
			FMemory::Memcpy( SavedVertices, Vertices, BufferSize );

			Unlock();

			DestroyBuffer();
		}

		// Create the vertex buffer
		ConditionalCreateBuffer();

		// Bind the buffer so we can give it data
		Bind();

		// Set the vertex buffer's size
		glBufferData( GL_ARRAY_BUFFER, NewSize, NULL, GL_DYNAMIC_DRAW );

		// If there are any saved vertices, copy them back now.
		if( SavedVertices )
		{
			void *Vertices = Lock( 0 );

			FMemory::Memcpy( Vertices, SavedVertices, BufferSize );

			Unlock();

			delete[] SavedVertices;
		}

		BufferSize = NewSize;
	}

}
/** 
 * Resizes the buffer to the passed in number of indices.  
 * Preserves internal data
 */
void FSlateOpenGLIndexBuffer::ResizeBuffer( uint32 NumIndices )
{
	// Only resize if the index buffer cant provide the number of indices  requested
	if( NumIndices > MaxNumIndices )
	{
		// Determine the current buffer size so we can save off the current indices
		uint32 CurrentBufferSize = MaxNumIndices*sizeof(SlateIndex);
		uint8 *SavedIndices = NULL;

		// If there are any indices at all save them off now
		if( MaxNumIndices > 0 )
		{
			void *Indices = Lock( 0 );

			SavedIndices = new uint8[CurrentBufferSize];
			FMemory::Memcpy( SavedIndices, Indices, CurrentBufferSize );

			Unlock();

			// Destroy the current buffer.  It needs to be recreated with a larger size
			DestroyBuffer();
		}

		// Calculate the new buffer size
		BufferSize = NumIndices*sizeof(SlateIndex);
		// Create the index buffer
		ConditionalCreateBuffer();

		// Bind the buffer so we can give it data
		Bind();

		MaxNumIndices = NumIndices;

		// Set the index buffer's size
		glBufferData( GL_ELEMENT_ARRAY_BUFFER, BufferSize, NULL, GL_DYNAMIC_DRAW );
		
		// If there are any saved indices, copy them back now.
		if( SavedIndices )
		{
			void *Indices = Lock( 0 );

			FMemory::Memcpy( Indices, SavedIndices, CurrentBufferSize );

			Unlock();

			delete[] SavedIndices;
		}
	}
}