Пример #1
0
        /// <summary>
        /// Function to retrieve the texture if it's not assigned.
        /// </summary>
        /// <returns>TRUE if the texture was found, FALSE if not.</returns>
        internal bool GetTexture()
        {
            if (!string.IsNullOrEmpty(_textureName))
            {
                // Copy to local values because LINQ doesn't seem to work with members
                // of a struct.
                string textureName = _textureName;
                GorgonTexture2DSettings settings = _settings;

                // Our texture is deferred, so we need to find it in the graphics object tracked
                // object list.
                // In order to do that, we need to find all graphics objects first:
                var graphics = Gorgon.GetTrackedObjectsOfType <GorgonGraphics>();

                // We have no graphics, then we can't do display a texture anyway, so throw an exception.
                if (graphics.Count == 0)
                {
                    throw new GorgonException(GorgonResult.NotInitialized, Resources.GORANM_KEYFRAME_TEXTURE_NOGFX);
                }

                var textures = (from graphicsObject in graphics
                                from graphicsTexture in graphicsObject.GetTrackedObjectsOfType <GorgonTexture2D>()
                                select graphicsTexture).ToArray();

                // Then, we begin our search by looking at -all- the texture information we have:
                Value = (from graphicsTexture in textures
                         where (string.Equals(graphicsTexture.Name, textureName, StringComparison.OrdinalIgnoreCase)) &&
                         (graphicsTexture.Settings.ArrayCount == settings.ArrayCount) &&
                         (graphicsTexture.Settings.Format == settings.Format) &&
                         (graphicsTexture.Settings.Height == settings.Height) &&
                         (graphicsTexture.Settings.Width == settings.Width) &&
                         (graphicsTexture.Settings.IsTextureCube == settings.IsTextureCube) &&
                         (graphicsTexture.Settings.MipCount == settings.MipCount) &&
                         (graphicsTexture.Settings.Multisampling == settings.Multisampling)
                         select graphicsTexture).FirstOrDefault();

                // ReSharper disable ConvertIfStatementToNullCoalescingExpression
                if (Value == null)
                {
                    // That one failed, so just try and look it up by name, width, height and format.
                    Value = (from graphicsTexture in textures
                             where (string.Equals(graphicsTexture.Name, textureName, StringComparison.OrdinalIgnoreCase)) &&
                             (graphicsTexture.Settings.Format == settings.Format) &&
                             (graphicsTexture.Settings.Height == settings.Height) &&
                             (graphicsTexture.Settings.Width == settings.Width)
                             select graphicsTexture).FirstOrDefault() ?? (from graphicsTexture in textures
                                                                          where (string.Equals(graphicsTexture.Name, textureName, StringComparison.OrdinalIgnoreCase))
                                                                          select graphicsTexture).FirstOrDefault();
                }
                // ReSharper restore ConvertIfStatementToNullCoalescingExpression
            }

            // We have our texture, stop deferring.
            if (Value == null)
            {
                return(false);
            }

            _textureName = string.Empty;
            return(true);
        }