/// <summary> /// Create or update resources defined by this IGraphicsState, based on the associated <see cref="ShaderProgram"/>. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating resources. /// </param> /// <param name="shaderProgram"> /// A <see cref="ShaderProgram"/> that will be used in conjunction with this IGraphicsState. /// </param> public override void CreateState(GraphicsContext ctx, ShaderProgram shaderProgram) { // Create IGraphicsResource uniforms (i.e. textures) Dictionary <string, UniformStateMember> uniformState = UniformState; 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; } // Create the IGraphicsResource associated with the uniform state variable graphicsResource.Create(ctx); } // Uniform buffer is created depending on program // It is assumed that the uniform buffer layout is shared across all shader programs, otherwise // we need a way to identify the specific uniform buffer layout and map them based on ShaderProgram // instances CreateUniformBuffer(ctx, shaderProgram); }
/// <summary> /// Create or update resources defined by this IGraphicsState, based on the associated <see cref="ShaderProgram"/>. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating resources. /// </param> /// <param name="shaderProgram"> /// A <see cref="ShaderProgram"/> that will be used in conjunction with this IGraphicsState. /// </param> public override void Create(GraphicsContext ctx, ShaderProgram shaderProgram) { // Create IGraphicsResource uniforms (i.e. textures) Dictionary <string, UniformStateMember> uniformState = UniformState; 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; } // Create the IGraphicsResource associated with the uniform state variable graphicsResource.Create(ctx); } // Create uniform buffer, if supported if (UniformBlockTag != null && shaderProgram != null && shaderProgram.IsActiveUniformBlock(UniformBlockTag) && UniformBuffer == null) { _UniformBuffer = shaderProgram.CreateUniformBlock(UniformBlockTag, MapBufferUsageMask.MapWriteBit); _UniformBuffer.Create(ctx); } // Base implementation base.Create(ctx, shaderProgram); }
/// <summary> /// Actually create resources associated to the type. /// </summary> /// <param name="instance"> /// A <see cref="Object"/> that specifies the underlying instance. /// </param> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for creating the resources. /// </param> public virtual void Create(object instance, GraphicsContext ctx) { IGraphicsResource graphicsResource = instance as IGraphicsResource; if (graphicsResource == null) { throw new InvalidOperationException("not implementing IGraphicsResource"); } graphicsResource.Create(ctx); }
/// <summary> /// Actually create this GraphicsResource resources. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating resources. /// </param> protected override void CreateObject(GraphicsContext ctx) { Dictionary <string, UniformStateMember> uniformState = UniformState; foreach (KeyValuePair <string, UniformStateMember> pair in uniformState) { if (pair.Value.GetUniformType().GetInterface("IGraphicsResource") == null) { continue; } IGraphicsResource graphicsResource = pair.Value.GetUniformValue(this) as IGraphicsResource; // Create the IGraphicsResource associated with the uniform state variable Debug.Assert(graphicsResource != null); graphicsResource.Create(ctx); } }