| 173 | } |
| 174 | |
| 175 | void Tr2LineGraph::Render( float scale, Tr2RenderContext& renderContext ) |
| 176 | { |
| 177 | if( m_isPrepared && ( !s_lineGraphEffect || !s_lineGraphEffect->GetShaderStateInterface() ) ) |
| 178 | { |
| 179 | m_isPrepared = false; |
| 180 | } |
| 181 | |
| 182 | if( !m_isPrepared ) |
| 183 | { |
| 184 | PrepareResources(); |
| 185 | |
| 186 | if( !m_isPrepared ) |
| 187 | { |
| 188 | return; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | LineGraphVertex* pVerts; |
| 193 | CR_RETURN( m_vertexBuffer.MapForWriting( pVerts, renderContext ) ); |
| 194 | |
| 195 | LineGraphVertex* pVertsEnd = pVerts + m_primitiveCount * 2; |
| 196 | |
| 197 | unsigned int count = (unsigned int)m_data.size(); |
| 198 | |
| 199 | float step = 2.0f / ( (float)count - 1.0f ); |
| 200 | |
| 201 | float x = -1.0f; |
| 202 | |
| 203 | m_maxValue = 0.0f; |
| 204 | |
| 205 | // Data is stored in a circular buffer - start at the oldest one, |
| 206 | // where the current index is and the next item would go. |
| 207 | float* p = &m_data[m_currentIx]; |
| 208 | for( unsigned int i = m_currentIx; i < count - 1; ++i ) |
| 209 | { |
| 210 | if( *p > m_maxValue ) |
| 211 | { |
| 212 | m_maxValue = *p; |
| 213 | } |
| 214 | |
| 215 | pVerts->pos.x = x; |
| 216 | pVerts->pos.y = *p; |
| 217 | ++pVerts; |
| 218 | |
| 219 | pVerts->pos.x = x + step; |
| 220 | pVerts->pos.y = *( p + 1 ); |
| 221 | ++pVerts; |
| 222 | |
| 223 | ++p; |
| 224 | x += step; |
| 225 | } |
| 226 | |
| 227 | // Then take the ones from the start of the buffer up the current index. |
| 228 | if( m_currentIx > 0 ) |
| 229 | { |
| 230 | // curIx is unsigned, so the condition in the for loop below is not |
| 231 | // enough to prevent iterating when curIx is 0. |
| 232 |
nothing calls this directly
no test coverage detected