------------------------------------------------------------------------------------------------------ Description: Populate line set's vertex buffer with line data. Return value: Boolean value indicating success of vertex buffer creation. ------------------------------------------------------------------------------------------------------
| 355 | // Boolean value indicating success of vertex buffer creation. |
| 356 | // ------------------------------------------------------------------------------------------------------ |
| 357 | bool 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, |
nothing calls this directly
no test coverage detected