/// <summary> /// Refreshes device dependent resources of this class. /// </summary> private void RefreshDeviceDependentResources() { if ((m_renderParameters == null) || (!m_renderParameters.IsLoaded)) { m_renderParameters = m_resources.AddAndLoadResource( GraphicsCore.GetNextGenericResourceKey(), new ViewRenderParameters()); } if ((m_renderPassTransparent == null) || (!m_renderPassTransparent.IsLoaded)) { m_renderPassTransparent = m_resources.GetResourceAndEnsureLoaded( new NamedOrGenericKey(typeof(RenderPassDefaultTransparent)), () => new RenderPassDefaultTransparent()); } if ((m_renderPassLineRender == null) || (!m_renderPassLineRender.IsLoaded)) { m_renderPassLineRender = m_resources.GetResourceAndEnsureLoaded( new NamedOrGenericKey(typeof(RenderPassLineRender)), () => new RenderPassLineRender()); } if ((m_renderPass2DOverlay == null) || (!m_renderPass2DOverlay.IsLoaded)) { m_renderPass2DOverlay = m_resources.GetResourceAndEnsureLoaded( new NamedOrGenericKey(typeof(RenderPass2DOverlay)), () => new RenderPass2DOverlay()); } }
/// <summary> /// Adds a resource to the scene /// </summary> /// <typeparam name="ResourceType">The type of the resource.</typeparam> /// <param name="resourceFactory">The factory method which creates the resource object.</param> /// <param name="resourceKey">The key for the newly generated resource.</param> /// <returns></returns> internal NamedOrGenericKey AddResource <ResourceType>(Func <ResourceType> resourceFactory, NamedOrGenericKey resourceKey) where ResourceType : Resource { resourceFactory.EnsureNotNull(nameof(resourceFactory)); InitializeResourceDictionaries(true); if (resourceKey == NamedOrGenericKey.Empty) { resourceKey = GraphicsCore.GetNextGenericResourceKey(); } foreach (ResourceDictionary actResourceDict in m_registeredResourceDicts) { actResourceDict.AddResource(resourceKey, resourceFactory()); } return(resourceKey); }
/// <summary> /// Adds the given resource to the dictionary. /// </summary> /// <param name="resource">The resource to add.</param> /// <param name="resourceKey">The key of the resource.</param> internal ResourceType AddResource <ResourceType>(NamedOrGenericKey resourceKey, ResourceType resource) where ResourceType : Resource { //Perform some checks if (resource == null) { throw new ArgumentNullException("resource"); } if (resource.Dictionary != null) { if (resource.Dictionary == this) { return(resource); } if (resource.Dictionary != this) { throw new ArgumentException("Given resource belongs to another ResourceDictionary!", "resource"); } } //Check given keys if ((!resource.IsKeyEmpty) && (!resourceKey.IsEmpty) && (resource.Key != resourceKey)) { throw new ArgumentException("Unable to override existing key on given resource!"); } //Remove another resource with the same name if (!resource.IsKeyEmpty) { RemoveResource(resource.Key); } if (!resourceKey.IsEmpty) { RemoveResource(resourceKey); } //Apply a valid key on the given resource object if (resource.Key.IsEmpty) { if (resourceKey.IsEmpty) { resource.Key = GraphicsCore.GetNextGenericResourceKey(); } else { resource.Key = resourceKey; } } //Add the resource ResourceInfo newResource = new ResourceInfo(resource); m_resources[resource.Key] = newResource; if (newResource.RenderableResource != null) { m_renderableResources.Add(newResource.RenderableResource); } //Register this dictionary on the resource resource.Dictionary = this; return(resource); }