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

Method GetBuffer

trinity/Shader/Tr2Material.cpp:17–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16
17std::pair<Tr2SharedConstantBuffers::Key, Tr2ConstantBufferAL> Tr2SharedConstantBuffers::GetBuffer( const void* contents, uint32_t size )
18{
19 if( !size || !contents )
20 {
21 return std::make_pair( Key(), Tr2ConstantBufferAL() );
22 }
23 Key key;
24 key.size = size;
25 key.hash = CcpHashFNV1( contents, size );
26 key.contents = contents;
27
28 auto found = m_buffers.find( key );
29 if( found != m_buffers.end() )
30 {
31 auto& value = found->second;
32 if( !value.buffer.IsValid() )
33 {
34 USE_MAIN_THREAD_RENDER_CONTEXT();
35 if( FAILED( value.buffer.Create( size, Tr2ConstantUsageAL::ONE_SHOT, contents, renderContext ) ) )
36 {
37 return std::make_pair( Key(), Tr2ConstantBufferAL() );
38 }
39 }
40 ++value.refCount;
41 return std::make_pair( found->first, value.buffer );
42 }
43
44 if( size % sizeof( Vector4 ) )
45 {
46 size += sizeof( Vector4 ) - size % sizeof( Vector4 );
47 }
48
49 Value value;
50 {
51 USE_MAIN_THREAD_RENDER_CONTEXT();
52 if( FAILED( value.buffer.Create( size, Tr2ConstantUsageAL::ONE_SHOT, contents, renderContext ) ) )
53 {
54 return std::make_pair( Key(), Tr2ConstantBufferAL() );
55 }
56 }
57
58 value.refCount = 1;
59
60 auto copy = new uint8_t[size];
61 memcpy( copy, contents, size );
62 key.contents = copy;
63
64 m_buffers[key] = value;
65 return std::make_pair( key, value.buffer );
66}
67
68void Tr2SharedConstantBuffers::ReleaseBuffer( const Key& key )
69{

Callers 15

GetInstanceDataMethod · 0.45
GetGpuBufferMethod · 0.45
GetBatchesMethod · 0.45
SetGeometryMethod · 0.45
SetStreamSourceMethod · 0.45
SetInidicesMethod · 0.45
GetInstanceDataMethod · 0.45
RenderTriangleVertsMethod · 0.45
IssueDrawCallMethod · 0.45
RunJobMethod · 0.45
ReplayCaptureMethod · 0.45

Calls 5

KeyClass · 0.85
Tr2ConstantBufferALClass · 0.50
endMethod · 0.45
IsValidMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected