Ejemplo n.º 1
0
        /// <summary>
        /// Bind a <see cref="Texture"/> to this ImageUnit (core function).
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="GraphicsContext"/> managing this ImageUnit.
        /// </param>
        /// <param name="texture">
        /// The <see cref="uint"/> that specifies the name of the texture to be bound to this ImageUnit.
        /// </param>
        /// <param name="unitState">
        /// Specifies the state of the image unit.
        /// </param>
        internal void Bind(GraphicsContext ctx, Texture texture, ImageUnitState unitState)
        {
            GraphicsResource.CheckCurrentContext(ctx);
            if (unitState == null)
            {
                throw new ArgumentNullException("unitState");
            }

            uint bindTextureName = texture != null ? texture.ObjectName : GraphicsResource.InvalidObjectName;

            Texture currTexture     = Texture;
            uint    currTextureName = currTexture != null ? currTexture.ObjectName : GraphicsResource.InvalidObjectName;

            // Bind the texture on the image unit, if necessary
            bool bindImageTexture = false;

#if ENABLE_LAZY_IMAGE_UNIT_BINDING
            bindImageTexture |= currTextureName != bindTextureName;
            bindImageTexture |= this != unitState;
#else
            bindImageTexture = true;
#endif

            if (bindImageTexture)
            {
                // Since here, the texture is bound to the texture unit
                Gl.BindImageTexture(Index, bindTextureName, unitState.Level, unitState.Layered, unitState.Layer, unitState.Access, unitState.InternalFormat);
                Texture = texture;
            }
            else
            {
                // Texture already bound to image unit, Gl.BindImageTexture not necessary
            }
        }