Update draws the entities in the RenderSystem to the OpenGL Surface.
(dt float32)
| 331 | |
| 332 | // Update draws the entities in the RenderSystem to the OpenGL Surface. |
| 333 | func (rs *RenderSystem) Update(dt float32) { |
| 334 | if engo.Headless() { |
| 335 | return |
| 336 | } |
| 337 | |
| 338 | if rs.sortingNeeded { |
| 339 | sort.Sort(rs.entities) |
| 340 | rs.sortingNeeded = false |
| 341 | } |
| 342 | |
| 343 | if rs.newCamera { |
| 344 | newCamera(rs.world) |
| 345 | rs.newCamera = false |
| 346 | } |
| 347 | |
| 348 | engo.Gl.Clear(engo.Gl.COLOR_BUFFER_BIT) |
| 349 | |
| 350 | preparedCullingShaders := make(map[CullingShader]struct{}) |
| 351 | var cullingShader CullingShader // current culling shader |
| 352 | var prevShader Shader // shader of the previous entity |
| 353 | var currentShader Shader // currently "active" shader |
| 354 | |
| 355 | // TODO: it's linear for now, but that might very well be a bad idea |
| 356 | for _, e := range rs.entities { |
| 357 | if e.RenderComponent.Hidden { |
| 358 | continue // with other entities |
| 359 | } |
| 360 | |
| 361 | // Retrieve a shader, may be the default one -- then use it if we aren't already using it |
| 362 | shader := e.RenderComponent.shader |
| 363 | |
| 364 | if !compareShaders(shader, prevShader) { |
| 365 | // to increase performance avoid the type assertions when possible |
| 366 | prevShader = shader |
| 367 | if cs, ok := shader.(CullingShader); ok { |
| 368 | cullingShader = cs |
| 369 | if _, isPrepared := preparedCullingShaders[cullingShader]; !isPrepared { |
| 370 | cullingShader.PrepareCulling() |
| 371 | preparedCullingShaders[cullingShader] = struct{}{} |
| 372 | } |
| 373 | } else { |
| 374 | cullingShader = nil |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | if cullingShader != nil && !cullingShader.ShouldDraw(e.RenderComponent, e.SpaceComponent) { |
| 379 | continue |
| 380 | } |
| 381 | |
| 382 | // Change Shader if we have to |
| 383 | if !compareShaders(shader, currentShader) { |
| 384 | if currentShader != nil { |
| 385 | currentShader.Post() |
| 386 | } |
| 387 | shader.Pre() |
| 388 | currentShader = shader |
| 389 | } |
| 390 |
nothing calls this directly
no test coverage detected