-------------------------------------------------------------------------------------- Description: Allocates memory for instance data (if passed instance count is different from previous one) and returns it. Arguments: count - Number of instances Return value: Instance data buffer --------------------------------------------------------------------------------------
| 166 | // Instance data buffer |
| 167 | // -------------------------------------------------------------------------------------- |
| 168 | void* Tr2DirectInstanceData::GetData( unsigned count ) |
| 169 | { |
| 170 | if( count != m_count ) |
| 171 | { |
| 172 | m_count = count; |
| 173 | } |
| 174 | |
| 175 | if( !m_stride || !m_count ) |
| 176 | { |
| 177 | return nullptr; |
| 178 | } |
| 179 | |
| 180 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 181 | |
| 182 | if( !m_vertexBuffer.IsValid() || m_vertexBuffer.GetDesc().count < m_count ) |
| 183 | { |
| 184 | m_vertexBuffer = Tr2BufferAL(); |
| 185 | auto hr = m_vertexBuffer.Create( |
| 186 | m_stride, |
| 187 | m_count, |
| 188 | Tr2GpuUsage::VERTEX_BUFFER, |
| 189 | Tr2CpuUsage::WRITE_OFTEN, |
| 190 | nullptr, |
| 191 | renderContext ); |
| 192 | if( FAILED( hr ) ) |
| 193 | { |
| 194 | return nullptr; |
| 195 | } |
| 196 | } |
| 197 | uint8_t* data = nullptr; |
| 198 | if( FAILED( m_vertexBuffer.MapForWriting( data, renderContext ) ) ) |
| 199 | { |
| 200 | return nullptr; |
| 201 | } |
| 202 | |
| 203 | return data; |
| 204 | } |
| 205 | |
| 206 | // -------------------------------------------------------------------------------------- |
| 207 | // Description: |
no test coverage detected