| 19 | // -------------------------------------------------------------------------------------- |
| 20 | template <typename Owner> |
| 21 | class Tr2PersistentPerObjectData |
| 22 | : public Tr2DeviceResource |
| 23 | { |
| 24 | public: |
| 25 | Tr2PersistentPerObjectData() : |
| 26 | m_bufferDirty( true ) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | // ---------------------------------------------------------------------------------- |
| 31 | // Description: |
| 32 | // Invalidates dirty flag for the object. Next time it is requested to apply its |
| 33 | // constant buffer, the object fill re-fill it with new data. |
| 34 | // ---------------------------------------------------------------------------------- |
| 35 | void InvalidateBufferData() |
| 36 | { |
| 37 | m_bufferDirty = true; |
| 38 | } |
| 39 | |
| 40 | void UpdateBuffer( Owner& owner, Tr2RenderContextEnum::ShaderType shaderType ) |
| 41 | { |
| 42 | #if TRINITY_PLATFORM != TRINITY_DIRECTX11 |
| 43 | if( !m_bufferDirty ) |
| 44 | { |
| 45 | return; |
| 46 | } |
| 47 | uint32_t size = owner.GetPerObjectDataSize( shaderType ); |
| 48 | if( size > 0 ) |
| 49 | { |
| 50 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 51 | |
| 52 | auto& buffer = m_constantBuffer; |
| 53 | if( !buffer.IsValid() || size > buffer.GetSize() ) |
| 54 | { |
| 55 | CR_RETURN( buffer.Create( size, renderContext.GetPrimaryRenderContext() ) ); |
| 56 | } |
| 57 | void* data = nullptr; |
| 58 | |
| 59 | if( SUCCEEDED( buffer.Lock( &data, renderContext ) ) && data ) |
| 60 | { |
| 61 | owner.UpdatePerObjectBuffer( shaderType, size, data ); |
| 62 | buffer.Unlock( renderContext ); |
| 63 | } |
| 64 | } |
| 65 | m_bufferDirty = false; |
| 66 | #endif |
| 67 | } |
| 68 | |
| 69 | Tr2ConstantBufferAL& UpdateBuffer( |
| 70 | Owner& owner, |
| 71 | Tr2RenderContextEnum::ShaderType shaderType, |
| 72 | Tr2RenderContext& renderContext ) |
| 73 | { |
| 74 | if( m_bufferDirty ) |
| 75 | { |
| 76 | uint32_t size = owner.GetPerObjectDataSize( shaderType ); |
| 77 | if( size > 0 ) |
| 78 | { |
nothing calls this directly
no test coverage detected