/////////////////////////////////////////////////////// Process a terrain generation work item. Use the vector of vertices as scratch memory and upload the data to the vertex buffer when done. ///////////////////////////////////////////////////////
| 262 | /// |
| 263 | //////////////////////////////////////////////////////////// |
| 264 | void processWorkItem(std::vector<sf::Vertex>& vertices, const WorkItem& workItem) |
| 265 | { |
| 266 | const unsigned int rowStart = rowBlockSize * workItem.index; |
| 267 | |
| 268 | if (rowStart >= resolution.y) |
| 269 | return; |
| 270 | |
| 271 | const unsigned int rowEnd = std::min(rowStart + rowBlockSize, resolution.y); |
| 272 | const unsigned int rowCount = rowEnd - rowStart; |
| 273 | |
| 274 | for (unsigned int y = rowStart; y < rowEnd; ++y) |
| 275 | { |
| 276 | for (unsigned int x = 0; x < resolution.x; ++x) |
| 277 | { |
| 278 | const unsigned int arrayIndexBase = ((y - rowStart) * resolution.x + x) * 6; |
| 279 | |
| 280 | // Top left corner (first triangle) |
| 281 | if (x > 0) |
| 282 | { |
| 283 | vertices[arrayIndexBase + 0] = vertices[arrayIndexBase - 6 + 5]; |
| 284 | } |
| 285 | else if (y > rowStart) |
| 286 | { |
| 287 | vertices[arrayIndexBase + 0] = vertices[arrayIndexBase - resolution.x * 6 + 1]; |
| 288 | } |
| 289 | else |
| 290 | { |
| 291 | vertices[arrayIndexBase + 0] = computeVertex({x, y}); |
| 292 | } |
| 293 | |
| 294 | // Bottom left corner (first triangle) |
| 295 | if (x > 0) |
| 296 | { |
| 297 | vertices[arrayIndexBase + 1] = vertices[arrayIndexBase - 6 + 2]; |
| 298 | } |
| 299 | else |
| 300 | { |
| 301 | vertices[arrayIndexBase + 1] = computeVertex({x, y + 1}); |
| 302 | } |
| 303 | |
| 304 | // Bottom right corner (first triangle) |
| 305 | vertices[arrayIndexBase + 2] = computeVertex({x + 1, y + 1}); |
| 306 | |
| 307 | // Top left corner (second triangle) |
| 308 | vertices[arrayIndexBase + 3] = vertices[arrayIndexBase + 0]; |
| 309 | |
| 310 | // Bottom right corner (second triangle) |
| 311 | vertices[arrayIndexBase + 4] = vertices[arrayIndexBase + 2]; |
| 312 | |
| 313 | // Top right corner (second triangle) |
| 314 | if (y > rowStart) |
| 315 | { |
| 316 | vertices[arrayIndexBase + 5] = vertices[arrayIndexBase - resolution.x * 6 + 2]; |
| 317 | } |
| 318 | else |
| 319 | { |
| 320 | vertices[arrayIndexBase + 5] = computeVertex({x + 1, y}); |
| 321 | } |
no test coverage detected