MCPcopy Create free account
hub / github.com/carbonengine/trinity / FillVertexBuffer

Method FillVertexBuffer

trinity/Tr2CurveLineSet.cpp:357–596  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------------ Description: Populate line set's vertex buffer with line data. Return value: Boolean value indicating success of vertex buffer creation. ------------------------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

355// Boolean value indicating success of vertex buffer creation.
356// ------------------------------------------------------------------------------------------------------
357bool Tr2CurveLineSet::FillVertexBuffer()
358{
359 CCP_STATS_ZONE( __FUNCTION__ );
360
361 USE_MAIN_THREAD_RENDER_CONTEXT();
362
363 // collect this while looping through the list
364 m_currentSubmittedLineCount = 0;
365
366 // build bounding sphere while looping through list
367 BoundingSphereInitialize( m_boundingSphere );
368 BoundingBoxInitialize( m_minBounds, m_maxBounds );
369 m_boundsDirty = true;
370
371 // catch zero size, so we don't need to worry about empty arrays
372 if( m_lines.size() )
373 {
374 // can the big vertexbuffer handle this?
375 int currentNumOfLines = GetNumOfLines();
376 if( !m_vertexBuffer.IsValid() || ( currentNumOfLines > m_vertexBufferSize ) )
377 {
378 // release old and create new
379 USE_MAIN_THREAD_RENDER_CONTEXT();
380
381 Tr2CpuUsage::Type cpuUsage = m_dynamic ? Tr2CpuUsage::WRITE_OFTEN : Tr2CpuUsage::WRITE;
382
383 CR_RETURN_VAL(
384 m_vertexBuffer.Create(
385 sizeof( LineVertex ),
386 currentNumOfLines * 6,
387 Tr2GpuUsage::VERTEX_BUFFER,
388 cpuUsage,
389 nullptr,
390 renderContext ),
391 false );
392 m_vertexBufferSize = currentNumOfLines;
393 }
394
395 size_t byteSize = m_vertexBufferSize * 6 * sizeof( LineVertex );
396 auto buffer = Tr2Renderer::GetPoolAllocator()->Allocate( byteSize );
397 LineVertex* vertexBuffer = reinterpret_cast<LineVertex*>( buffer );
398
399 for( unsigned int i = 0; i < m_lines.size(); ++i )
400 {
401 // what type of line?
402 switch( m_lines[i].type )
403 {
404 case LINETYPE_INVALID:
405 break;
406
407 case LINETYPE_STRAIGHT: {
408 // put some verts into buffer
409 WriteLineVerticesToBuffer(
410 m_lines[i].position1,
411 m_lines[i].color1,
412 0.f,
413 m_lines[i].position2,
414 m_lines[i].color2,

Callers

nothing calls this directly

Calls 15

BoundingSphereInitializeFunction · 0.85
BoundingBoxInitializeFunction · 0.85
BoundingSphereUpdateFunction · 0.85
BoundingBoxUpdateFunction · 0.85
CrossFunction · 0.85
LerpFunction · 0.85
HermiteFunction · 0.85
sizeMethod · 0.80
DotFunction · 0.50
IsValidMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected