| 334 | } |
| 335 | |
| 336 | void Renderer::DrawDisplaySprites(RenderView& renderView, bool negativePriority) |
| 337 | { |
| 338 | constexpr auto VERTEX_COUNT = 4; |
| 339 | |
| 340 | if (renderView.DisplaySpritesToDraw.empty()) |
| 341 | return; |
| 342 | |
| 343 | Texture2D* texture2DPtr = nullptr; |
| 344 | for (const auto& spriteToDraw : renderView.DisplaySpritesToDraw) |
| 345 | { |
| 346 | if ((spriteToDraw.Priority >= 0) == negativePriority) |
| 347 | continue; |
| 348 | |
| 349 | if (texture2DPtr == nullptr) |
| 350 | { |
| 351 | _shaders.Bind(Shader::FullScreenQuad); |
| 352 | |
| 353 | _context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); |
| 354 | _context->IASetInputLayout(_inputLayout.Get()); |
| 355 | |
| 356 | _primitiveBatch->Begin(); |
| 357 | |
| 358 | BindTexture(TextureRegister::ColorMap, spriteToDraw.SpritePtr->Texture, SamplerStateRegister::AnisotropicClamp); |
| 359 | SetBlendMode(spriteToDraw.BlendMode); |
| 360 | } |
| 361 | else if (texture2DPtr != spriteToDraw.SpritePtr->Texture || _lastBlendMode != spriteToDraw.BlendMode) |
| 362 | { |
| 363 | _primitiveBatch->End(); |
| 364 | _primitiveBatch->Begin(); |
| 365 | |
| 366 | BindTexture(TextureRegister::ColorMap, spriteToDraw.SpritePtr->Texture, SamplerStateRegister::AnisotropicClamp); |
| 367 | SetBlendMode(spriteToDraw.BlendMode); |
| 368 | } |
| 369 | |
| 370 | // Calculate vertex base. |
| 371 | auto vertices = std::array<Vector2, VERTEX_COUNT> |
| 372 | { |
| 373 | spriteToDraw.Size / 2, |
| 374 | Vector2(-spriteToDraw.Size.x, spriteToDraw.Size.y) / 2, |
| 375 | -spriteToDraw.Size / 2, |
| 376 | Vector2(spriteToDraw.Size.x, -spriteToDraw.Size.y) / 2 |
| 377 | }; |
| 378 | |
| 379 | // Transform vertices. |
| 380 | // NOTE: Must rotate 180 degrees to account for +Y being down. |
| 381 | auto rotMatrix = Matrix::CreateRotationZ(TO_RAD(spriteToDraw.Orientation + ANGLE(180.0f))); |
| 382 | for (auto& vertex : vertices) |
| 383 | { |
| 384 | // Rotate. |
| 385 | vertex = Vector2::Transform(vertex, rotMatrix); |
| 386 | |
| 387 | // Apply aspect correction. |
| 388 | vertex *= spriteToDraw.AspectCorrection; |
| 389 | |
| 390 | // Offset to position and convert to NDC. |
| 391 | vertex += spriteToDraw.Position; |
| 392 | vertex = TEN::Utils::Convert2DPositionToNDC(vertex); |
| 393 | } |
nothing calls this directly
no test coverage detected