public void GenerateShadowMaps(GraphicsContext ctx, SceneGraph sceneGraph) { if (sceneGraph == null) { throw new ArgumentNullException("sceneGraph"); } // Push current viewport to be restore later State.ViewportState currentViewport = new State.ViewportState(ctx); foreach (SceneObjectLight sceneLight in ShadowLights) { using (SceneGraph shadowGraph = new SceneGraph(sceneGraph, //SceneGraphFlags.CullingViewFrustum | SceneGraphFlags.StateSorting SceneGraphFlags.None )) { shadowGraph.SceneRoot.ObjectState.DefineState(new State.CullFaceState(CullFaceMode.Back)); sceneLight.UpdateShadowMap(ctx, shadowGraph); } } // Restore viewport currentViewport.Apply(ctx, null); // Restore cull face state to default State.CullFaceState.DefaultState.Apply(ctx, null); }