/// <summary> /// Performs a deep copy of this <see cref="IGraphicsState"/>. /// </summary> /// <returns> /// It returns the equivalent of this <see cref="IGraphicsState"/>, but all objects referenced /// are not referred by both instances. /// </returns> public override IGraphicsState Push() { ShaderUniformStateBase copiedState = (ShaderUniformStateBase)base.Push(); if (copiedState._UniformBuffer != null) { copiedState._UniformBuffer.IncRef(); } #if ENABLE_REFS_ON_COPY foreach (KeyValuePair <string, UniformStateMember> pair in copiedState.UniformState) { //if (pair.Value.GetUniformType().GetInterface("IGraphicsResource") == null) // continue; IGraphicsResource graphicsResource = pair.Value.GetUniformValue(this) as IGraphicsResource; if (graphicsResource == null) { continue; } // Copied share references graphicsResource.IncRef(); } #endif return(copiedState); }
/// <summary> /// Link a resource used by this UserGraphicsResource. /// </summary> /// <param name="graphicsResource"> /// The <see cref="IGraphicsResource"/> that will be linked by this UserGraphicsResource. It will be referenced till /// this instance disposition. You should not manually reference this instance for the UserGraphicsResource lifetime. /// </param> /// <exception cref="ArgumentNullException"> /// Exception thrown if <paramref name="graphicsResource"/> is null. /// </exception> protected void LinkResource(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"); // Reference resources graphicsResource.IncRef(); // Unreference at disposition _GpuResources.Add(graphicsResource); }
/// <summary> /// Link a resource associated with this SceneGraphObject. /// </summary> /// <param name="graphicsResource"> /// A <see cref="IGraphicsResource"/> that will be created and disposed along with this SceneGraphObject instance. /// </param> /// <remarks> /// The <paramref name="graphicsResource"/> can be shared across multiple SceneGraphObject instances. /// </remarks> protected void LinkResource(IGraphicsResource graphicsResource) { if (graphicsResource == null) { throw new ArgumentNullException("graphicsResource"); } // Formally a resource can be linked multiple times, but probably it is caused by a copy & paste error Debug.Assert(!_Resources.Contains(graphicsResource)); // By default, threat resources as shared ones graphicsResource.IncRef(); // Let create/dispose it _Resources.Add(graphicsResource); }
/// <summary> /// Link a resource used by this UserGraphicsResource. /// </summary> /// <param name="graphicsResource"> /// The <see cref="GraphicsResource"/> that will be linked by this UserGraphicsResource. It will be referenced till /// this instance disposition. You should not manually reference this instance for the UserGraphicsResource lifetime. /// </param> /// <exception cref="ArgumentNullException"> /// Exception thrown if <paramref name="graphicsResource"/> is null. /// </exception> protected void LinkResource(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"); } // Reference resources graphicsResource.IncRef(); // Unreference at disposition Debug.Assert(!_UserResources.Contains(graphicsResource)); _UserResources.Add(graphicsResource); }
/// <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)); } }