/// <summary> /// Unlink a resource used by this UserGraphicsResource. /// </summary> /// <param name="graphicsResource"> /// The <see cref="IGraphicsResource"/> that will be unlinked from this UserGraphicsResource. It will be unreferenced. /// </param> /// <exception cref="ArgumentNullException"> /// Exception thrown if <paramref name="graphicsResource"/> is null. /// </exception> protected void UnlinkResource(IGraphicsResource graphicsResource) { if (graphicsResource == null) throw new ArgumentNullException("graphicsResource"); if (ObjectNamespace != Guid.Empty && graphicsResource.ObjectNamespace != Guid.Empty && ObjectNamespace != graphicsResource.ObjectNamespace) throw new ArgumentException("namespace mismatch", "graphicsResource"); // Unreference at disposition bool res = _GpuResources.Remove(graphicsResource); Debug.Assert(res); // No more referenced graphicsResource.DecRef(); }
/// <summary> /// Set uniform variable state. /// </summary> /// <param name="uniformName"> /// /// </param> /// <param name="value"> /// /// </param> public void SetUniformState(string uniformName, object value) { if (uniformName == null) { throw new ArgumentNullException("uniformName"); } UniformStateMember uniformStateMember; if (_UniformProperties.TryGetValue(uniformName, out uniformStateMember)) { UniformStateVariable uniformStateVariable = (UniformStateVariable)uniformStateMember; IGraphicsResource prevResource = uniformStateVariable.UniformValue as IGraphicsResource; if (prevResource != null) { prevResource.DecRef(); } IGraphicsResource currResource = value as IGraphicsResource; if (currResource != null) { currResource.IncRef(); } uniformStateVariable.UniformValue = value; } else { IGraphicsResource currResource = value as IGraphicsResource; if (currResource != null) { currResource.IncRef(); } _UniformProperties.Add(uniformName, new UniformStateVariable(uniformName, value)); } }
/// <summary> /// Dispose resources hold by this GraphicsState. /// </summary> public override void Dispose() { if (_UniformBuffer != null) { _UniformBuffer.DecRef(); } #if ENABLE_REFS_ON_COPY foreach (KeyValuePair <string, UniformStateMember> pair in UniformState) { if (pair.Value.GetUniformType().GetInterface("IGraphicsResource") == null) { continue; } IGraphicsResource graphicsResource = pair.Value.GetUniformValue(this) as IGraphicsResource; if (graphicsResource == null) { continue; } graphicsResource.DecRef(); } #endif }