public void Reset() { ModelMatrixStack.Clear(); ModelMatrixStack.Push(Matrix4x4.Identity); PipelineStateStack.Clear(); OpaqueRenderGroup.Reset(); TransparentRenderGroup.Reset(); RenderElementCount = 0; }
/// <summary> /// Cull Visitor for billboard /// </summary> /// <param name="billboard"></param> public override void Apply(IBillboard billboard) { var bb = billboard.GetBoundingBox(); if (IsCulled(bb, ModelMatrixStack.Peek())) { return; } IPipelineState pso = null; // Node specific state if (billboard.HasPipelineState) { pso = billboard.PipelineState; } // Shared State else if (PipelineStateStack.Count != 0) { pso = PipelineStateStack.Peek(); } // Fallback else { pso = PipelineState.Create(); } var eyeLocal = GetEyeLocal(); var modelView = GetModelViewMatrix(); foreach (var drawable in billboard.Drawables) { // TODO - need to modify is culled to handle billboard matrix offset //if (IsCulled(drawable.GetBoundingBox(), ModelMatrixStack.Peek())) continue; var billboardMatrix = billboard.ComputeMatrix(modelView, eyeLocal); var drawablePso = pso; if (drawable.HasPipelineState) { drawablePso = drawable.PipelineState; } // // This allocates / updates vbo/ibos // drawable.ConfigureDeviceBuffers(GraphicsDevice, ResourceFactory); var renderElementCache = new Dictionary <IRenderGroupState, RenderGroupElement>(); foreach (var pset in drawable.PrimitiveSets) { // TODO - need to modify is culled to handle billboard matrix offset //if (IsCulled(pset.GetBoundingBox(), ModelMatrixStack.Peek())) continue; // // Sort into appropriate render group // IRenderGroupState renderGroupState = null; if (drawablePso.BlendStateDescription.AttachmentStates.Contains(BlendAttachmentDescription.AlphaBlend)) { renderGroupState = TransparentRenderGroup.GetOrCreateState(drawablePso, pset.PrimitiveTopology, drawable.VertexLayout); } else { renderGroupState = OpaqueRenderGroup.GetOrCreateState(drawablePso, pset.PrimitiveTopology, drawable.VertexLayout); } if (false == renderElementCache.TryGetValue(renderGroupState, out var renderElement)) { renderElement = new RenderGroupElement() { ModelViewMatrix = billboardMatrix.PostMultiply(modelView), VertexBuffer = drawable.GetVertexBufferForDevice(GraphicsDevice), IndexBuffer = drawable.GetIndexBufferForDevice(GraphicsDevice), PrimitiveSets = new List <IPrimitiveSet>() }; renderGroupState.Elements.Add(renderElement); renderElementCache.Add(renderGroupState, renderElement); } renderElement.PrimitiveSets.Add(pset); } } }