MCPcopy Create free account
hub / github.com/cogentcore/core / RenderImpl

Method RenderImpl

xyz/render.go:379–448  ·  view source on GitHub ↗

RenderImpl renders the scene to the framebuffer. all scene-level resources must be initialized and activated at this point

()

Source from the content-addressed store, hash-verified

377// RenderImpl renders the scene to the framebuffer.
378// all scene-level resources must be initialized and activated at this point
379func (sc *Scene) RenderImpl() {
380 sc.Phong.UpdateMu.Lock()
381 sc.Phong.SetViewProjection(&sc.Camera.ViewMatrix, &sc.Camera.VkProjectionMatrix)
382 sc.Phong.UpdateMu.Unlock()
383 sc.Phong.Sync()
384
385 var rcs [RenderClassesN][]Node
386 sc.WalkDown(func(k tree.Node) bool {
387 if k == sc.This {
388 return tree.Continue
389 }
390 ni, _ := AsNode(k)
391 if ni == nil {
392 return tree.Break // going into a different type of thing, bail
393 }
394 // if !ni.IsVisible() || nb.ScBBox == (image.Rectangle{}) {
395 // return tree.Break
396 // }
397 if !ni.IsSolid() {
398 return tree.Continue
399 }
400 rc := ni.RenderClass()
401 if rc > RClassTransTexture { // all in one group b/c z-sorting is key
402 rc = RClassTransTexture
403 }
404 rcs[rc] = append(rcs[rc], ni)
405 return tree.Continue
406 })
407
408 sc.Phong.UpdateMu.Lock()
409 sy := &sc.Phong.Sys
410 cmd := sy.CmdPool.Buff
411 descIndex := 0
412 sy.ResetBeginRenderPass(cmd, sc.Frame.Frames[0], descIndex)
413 sc.Phong.UpdateMu.Unlock()
414
415 for rci, objs := range rcs {
416 rc := RenderClasses(rci)
417 if len(objs) == 0 {
418 continue
419 }
420 if rc >= RClassTransTexture { // sort back-to-front for transparent
421 sort.Slice(objs, func(i, j int) bool { // TODO: use slices.SortFunc here and everywhere else we use sort.Slice
422 return objs[i].AsNodeBase().NormDCBBox().Min.Z > objs[j].AsNodeBase().NormDCBBox().Min.Z
423 })
424 } else { // sort front-to-back for opaque to allow "early z rejection"
425 sort.Slice(objs, func(i, j int) bool {
426 return objs[i].AsNodeBase().NormDCBBox().Min.Z < objs[j].AsNodeBase().NormDCBBox().Min.Z
427 })
428 }
429 // fmt.Printf("\nRender class: %v\n", rc)
430 // for i := range objs {
431 // fmt.Printf("obj: %s max z: %g min z: %g\n", objs[i].Name, objs[i].AsNode().NDCBBox.Max.Z, objs[i].AsNode().NDCBBox.Min.Z)
432 // }
433
434 lastrc := RClassOpaqueVertex
435 for _, obj := range objs {
436 rc = obj.RenderClass()

Callers 1

RenderMethod · 0.95

Calls 15

RenderClassesTypeAlias · 0.85
SetViewProjectionMethod · 0.80
WalkDownMethod · 0.80
ResetBeginRenderPassMethod · 0.80
SliceMethod · 0.80
NormDCBBoxMethod · 0.80
EndRenderPassMethod · 0.80
WaitForRenderMethod · 0.80
AsNodeFunction · 0.70
LockMethod · 0.65
UnlockMethod · 0.65
IsSolidMethod · 0.65

Tested by

no test coverage detected