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

Method OnPrepareResources

trinity/Tr2LineSet.cpp:49–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49bool Tr2LineSet::OnPrepareResources()
50{
51 USE_MAIN_THREAD_RENDER_CONTEXT();
52
53
54 // Visible lines
55 if( m_vertexDeclHandle == Tr2EffectStateManager::UNINITIALIZED_DECLARATION )
56 {
57 Tr2VertexDefinition vd;
58 vd.Add( vd.FLOAT32_3, vd.POSITION );
59 vd.Add( vd.FLOAT32_4, vd.TEXCOORD );
60
61 m_vertexDeclHandle = Tr2EffectStateManager::GetVertexDeclarationHandle( vd );
62 if( m_vertexDeclHandle == Tr2EffectStateManager::UNINITIALIZED_DECLARATION )
63 {
64 return false;
65 }
66 }
67
68 // Picking geometry
69 if( m_pickingVertexDeclHandle == Tr2EffectStateManager::UNINITIALIZED_DECLARATION )
70 {
71 Tr2VertexDefinition vd;
72 vd.Add( vd.FLOAT32_3, vd.POSITION );
73
74 m_pickingVertexDeclHandle = Tr2EffectStateManager::GetVertexDeclarationHandle( vd );
75 if( m_pickingVertexDeclHandle == Tr2EffectStateManager::UNINITIALIZED_DECLARATION )
76 {
77 return false;
78 }
79 }
80
81 if( m_lines.size() )
82 {
83 if( !m_vertexBuffer.IsValid() || ( m_currentSubmittedLineCount < m_lines.size() ) )
84 {
85 USE_MAIN_THREAD_RENDER_CONTEXT();
86 CR_RETURN_VAL(
87 m_vertexBuffer.Create(
88 sizeof( LineData ),
89 (unsigned int)m_lines.size(),
90 Tr2GpuUsage::VERTEX_BUFFER,
91 Tr2CpuUsage::WRITE_OFTEN,
92 nullptr,
93 renderContext ),
94 false );
95 m_currentSubmittedLineCount = (unsigned int)m_lines.size();
96 }
97
98 // Create a bounding sphere around the visible lines
99 Vector3 center( 0.0f, 0.0f, 0.0f );
100 float radius = 0.0f;
101 ComputeBoundingSphere( static_cast<Vector3*>( &m_lines[0].m_position1 ), (unsigned int)m_lines.size() * 2, sizeof( LineData ) / 2, center, radius );
102
103 void* vertexBuffer;
104 CR_RETURN_VAL( m_vertexBuffer.MapForWriting( vertexBuffer, renderContext ), false );
105 memcpy( vertexBuffer, &m_lines[0], sizeof( LineData ) * m_lines.size() );
106 m_vertexBuffer.UnmapForWriting( renderContext );

Callers

nothing calls this directly

Calls 7

sizeMethod · 0.80
AddMethod · 0.45
IsValidMethod · 0.45
CreateMethod · 0.45
MapForWritingMethod · 0.45
UnmapForWritingMethod · 0.45

Tested by

no test coverage detected