| 258 | } |
| 259 | |
| 260 | void Renderer::DrawSprites(RenderView& view, RendererPass rendererPass) |
| 261 | { |
| 262 | if (view.SpritesToDraw.empty()) |
| 263 | return; |
| 264 | |
| 265 | // Draw instanced sprites. |
| 266 | bool wasGpuSet = false; |
| 267 | for (const auto& spriteBucket : _spriteBuckets) |
| 268 | { |
| 269 | if (spriteBucket.SpritesToDraw.empty() || !spriteBucket.IsBillboard) |
| 270 | continue; |
| 271 | |
| 272 | if (!SetupBlendModeAndAlphaTest(spriteBucket.BlendMode, rendererPass, 0)) |
| 273 | continue; |
| 274 | |
| 275 | if (!wasGpuSet) |
| 276 | { |
| 277 | _context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); |
| 278 | |
| 279 | BindRenderTargetAsTexture(TextureRegister::GBufferDepthMap, &_depthRenderTarget, SamplerStateRegister::PointWrap); |
| 280 | |
| 281 | SetDepthState(DepthState::Read); |
| 282 | SetCullMode(CullMode::None); |
| 283 | |
| 284 | _shaders.Bind(Shader::InstancedSprites); |
| 285 | |
| 286 | // Set up vertex buffer and parameters. |
| 287 | unsigned int stride = sizeof(Vertex); |
| 288 | unsigned int offset = 0; |
| 289 | _context->IASetVertexBuffers(0, 1, _quadVertexBuffer.Buffer.GetAddressOf(), &stride, &offset); |
| 290 | |
| 291 | wasGpuSet = true; |
| 292 | } |
| 293 | |
| 294 | // Define sprite preparation logic. |
| 295 | auto prepareSprites = [&](int start, int end) |
| 296 | { |
| 297 | for (int i = start; i < end; i++) |
| 298 | { |
| 299 | const auto& spriteToDraw = spriteBucket.SpritesToDraw[i]; |
| 300 | |
| 301 | _stInstancedSpriteBuffer.Sprites[i].World = GetWorldMatrixForSprite(spriteToDraw, view); |
| 302 | _stInstancedSpriteBuffer.Sprites[i].Color = spriteToDraw.color; |
| 303 | _stInstancedSpriteBuffer.Sprites[i].IsBillboard = 1.0f; |
| 304 | _stInstancedSpriteBuffer.Sprites[i].PerVertexColor = 0; |
| 305 | _stInstancedSpriteBuffer.Sprites[i].IsSoftParticle = spriteToDraw.SoftParticle ? 1.0f : 0.0f; |
| 306 | _stInstancedSpriteBuffer.Sprites[i].RenderType = (int)spriteToDraw.renderType; |
| 307 | |
| 308 | PackSpriteTextureCoordinates(i, spriteToDraw.Sprite); |
| 309 | } |
| 310 | }; |
| 311 | g_Parallel.AddTasks((int)spriteBucket.SpritesToDraw.size(), prepareSprites).wait(); |
| 312 | |
| 313 | BindTexture(TextureRegister::ColorMap, spriteBucket.Sprite->Texture, SamplerStateRegister::LinearClamp); |
| 314 | UpdateConstantBuffer(_stInstancedSpriteBuffer, _cbInstancedSpriteBuffer);; |
| 315 | |
| 316 | // Draw sprites with instancing. |
| 317 | DrawInstancedTriangles(4, (int)spriteBucket.SpritesToDraw.size(), 0); |
nothing calls this directly
no test coverage detected