Represents additional parameters that specify how to process the texture.
Пример #1
0
        /// <summary>Checks whether this instance is equal to the specified object.</summary>
        /// <param name="obj">The object.</param>
        /// <returns>Whether this instance is equal to the specified object.</returns>
        public override bool Equals(object obj)
        {
            if (object.ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (object.ReferenceEquals(this, null))
            {
                return(false);
            }
            if (object.ReferenceEquals(obj, null))
            {
                return(false);
            }
            if (!(obj is TextureParameters))
            {
                return(false);
            }
            TextureParameters x = (TextureParameters)obj;

            if (this.MyClipRegion != x.MyClipRegion)
            {
                return(false);
            }
            if (this.MyTransparentColor != x.MyTransparentColor)
            {
                return(false);
            }
            return(true);
        }
        /// <summary>Registers a texture and returns a handle to the texture.</summary>
        /// <param name="bitmap">The bitmap that contains the texture.</param>
        /// <param name="parameters">The parameters that specify how to process the texture.</param>
        /// <returns>The handle to the texture.</returns>
        /// <remarks>Be sure not to dispose of the bitmap after calling this function.</remarks>
        internal static Texture RegisterTexture(Bitmap bitmap, OpenBveApi.Textures.TextureParameters parameters)
        {
            /*
             * Register the texture and return the newly created handle.
             * */
            int idx = GetNextFreeTexture();

            RegisteredTextures[idx] = new Texture(bitmap, parameters);
            RegisteredTexturesCount++;
            return(RegisteredTextures[idx]);
        }
Пример #3
0
		// --- apply parameters ---
		
		/// <summary>Applies parameters onto a texture.</summary>
		/// <param name="texture">The original texture.</param>
		/// <param name="parameters">The parameters, or a null reference.</param>
		/// <returns>The texture with the parameters applied.</returns>
		/// <exception cref="System.ArgumentException">Raised when the clip region is outside the texture bounds.</exception>
		/// <exception cref="System.NotSupportedException">Raised when the bits per pixel in the texture is other than 32.</exception>
		internal static Texture ApplyParameters(Texture texture, TextureParameters parameters) {
			Texture result = texture;
			if (parameters != null) {
				if (parameters.ClipRegion != null) {
					result = ExtractClipRegion(result, parameters.ClipRegion);
				}
				if (parameters.TransparentColor != null) {
					result = ApplyTransparentColor(result, parameters.TransparentColor);
				}
			}
			return result;
		}
Пример #4
0
 /// <summary>Loads a texture and returns the texture data.</summary>
 /// <param name="path">The path to the file or folder that contains the texture.</param>
 /// <param name="parameters">The parameters that specify how to process the texture.</param>
 /// <param name="texture">Receives the texture.</param>
 /// <returns>Whether loading the texture was successful.</returns>
 public override bool LoadTexture(string path, OpenBveApi.Textures.TextureParameters parameters, out OpenBveApi.Textures.Texture texture)
 {
     if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path))
     {
         for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++)
         {
             if (Program.CurrentHost.Plugins[i].Texture != null)
             {
                 try
                 {
                     if (Program.CurrentHost.Plugins[i].Texture.CanLoadTexture(path))
                     {
                         try
                         {
                             if (Program.CurrentHost.Plugins[i].Texture.LoadTexture(path, out texture))
                             {
                                 //texture.CompatibleTransparencyMode = Interface.CurrentOptions.OldTransparencyMode;
                                 texture = texture.ApplyParameters(parameters);
                                 return(true);
                             }
                             Interface.AddMessage(MessageType.Error, false, "Plugin " + Program.CurrentHost.Plugins[i].Title + " returned unsuccessfully at LoadTexture");
                         }
                         catch (Exception ex)
                         {
                             Interface.AddMessage(MessageType.Error, false, "Plugin " + Program.CurrentHost.Plugins[i].Title + " raised the following exception at LoadTexture:" + ex.Message);
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     Interface.AddMessage(MessageType.Error, false, "Plugin " + Program.CurrentHost.Plugins[i].Title + " raised the following exception at CanLoadTexture:" + ex.Message);
                 }
             }
         }
         FileInfo f = new FileInfo(path);
         if (f.Length == 0)
         {
             Interface.AddMessage(MessageType.Error, false, "Zero-byte texture file encountered at " + path);
         }
         else
         {
             Interface.AddMessage(MessageType.Error, false, "No plugin found that is capable of loading texture " + path);
         }
     }
     else
     {
         ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
     }
     texture = null;
     return(false);
 }
Пример #5
0
        /// <summary>Applies parameters onto a texture.</summary>
        /// <param name="texture">The original texture.</param>
        /// <param name="parameters">The parameters, or a null reference.</param>
        /// <returns>The texture with the parameters applied.</returns>
        /// <exception cref="System.ArgumentException">Raised when the clip region is outside the texture bounds.</exception>
        /// <exception cref="System.NotSupportedException">Raised when the bits per pixel in the texture is other than 32.</exception>
        internal static Texture ApplyParameters(Texture texture, TextureParameters parameters)
        {
            Texture result = texture;

            if (parameters != null)
            {
                if (parameters.ClipRegion != null)
                {
                    result = ExtractClipRegion(result, parameters.ClipRegion);
                }
                if (parameters.TransparentColor != null)
                {
                    result = ApplyTransparentColor(result, parameters.TransparentColor);
                }
            }
            return(result);
        }
Пример #6
0
 // --- functions ---
 /// <summary>Applies the specified parameters onto this texture.</summary>
 /// <param name="parameters">The parameters, or a null reference.</param>
 /// <returns>The texture with the parameters applied.</returns>
 /// <exception cref="System.ArgumentException">Raised when the clip region is outside the texture bounds.</exception>
 /// <exception cref="System.NotSupportedException">Raised when the bits per pixel in the texture is not supported.</exception>
 public Texture ApplyParameters(TextureParameters parameters)
 {
     return(Functions.ApplyParameters(this, parameters));
 }
Пример #7
0
 /// <summary>Creates a new texture.</summary>
 /// <param name="path">The path to the texture.</param>
 /// <param name="parameters">The parameters that specify how to process the texture.</param>
 /// <param name="currentHost">The callback function to the host application</param>
 public Texture(string path, TextureParameters parameters, Hosts.HostInterface currentHost)
 {
     this.Origin         = new PathOrigin(path, parameters, currentHost);
     this.OpenGlTextures = new OpenGlTexture[] { new OpenGlTexture(), new OpenGlTexture(), new OpenGlTexture(), new OpenGlTexture() };
 }
Пример #8
0
 /// <summary>Creates a new texture.</summary>
 /// <param name="bitmap">The System.Drawing.Bitmap that contains the texture.</param>
 /// <param name="parameters">The parameters that specify how to process the texture.</param>
 public Texture(Bitmap bitmap, TextureParameters parameters)
 {
     this.Origin         = new BitmapOrigin(bitmap, parameters);
     this.OpenGlTextures = new OpenGlTexture[] { new OpenGlTexture(), new OpenGlTexture(), new OpenGlTexture(), new OpenGlTexture() };
 }
Пример #9
0
		/// <summary>Registers a texture and returns a handle to the texture.</summary>
		/// <param name="texture">The texture data.</param>
		/// <param name="parameters">The parameters that specify how to process the texture.</param>
		/// <param name="handle">Receives the handle to the texture.</param>
		/// <returns>Whether loading the texture was successful.</returns>
		public virtual bool RegisterTexture(Textures.Texture texture, TextureParameters parameters, out TextureHandle handle) {
			handle = null;
			return false;
		}
Пример #10
0
		/// <summary>Registers a texture and returns a handle to the texture.</summary>
		/// <param name="path">The path to the file or folder that contains the texture.</param>
		/// <param name="parameters">The parameters that specify how to process the texture.</param>
		/// <param name="handle">Receives the handle to the texture.</param>
		/// <returns>Whether loading the texture was successful.</returns>
		public virtual bool RegisterTexture(string path, TextureParameters parameters, out TextureHandle handle) {
			handle = null;
			return false;
		}
Пример #11
0
		/// <summary>Loads a texture and returns the texture data.</summary>
		/// <param name="path">The path to the file or folder that contains the texture.</param>
		/// <param name="parameters">The parameters that specify how to process the texture.</param>
		/// <param name="texture">Receives the texture.</param>
		/// <returns>Whether loading the texture was successful.</returns>
		public virtual bool LoadTexture(string path, TextureParameters parameters, out Textures.Texture texture) {
			texture = null;
			return false;
		}
Пример #12
0
		// --- functions ---
		/// <summary>Applies the specified parameters onto this texture.</summary>
		/// <param name="parameters">The parameters, or a null reference.</param>
		/// <returns>The texture with the parameters applied.</returns>
		/// <exception cref="System.ArgumentException">Raised when the clip region is outside the texture bounds.</exception>
		/// <exception cref="System.NotSupportedException">Raised when the bits per pixel in the texture is not supported.</exception>
		public Texture ApplyParameters(TextureParameters parameters) {
			return Functions.ApplyParameters(this, parameters);
		}
Пример #13
0
 /// <summary>Creates a new bitmap origin.</summary>
 /// <param name="bitmap">The bitmap.</param>
 /// <param name="parameters">The texture parameters</param>
 public BitmapOrigin(Bitmap bitmap, TextureParameters parameters)
 {
     this.Bitmap     = bitmap;
     this.Parameters = parameters;
 }
Пример #14
0
 /// <summary>Applies the specified parameters onto a texture.</summary>
 /// <param name="texture">The original texture.</param>
 /// <param name="parameters">The parameters, or a null reference.</param>
 /// <returns>The texture with the parameters applied.</returns>
 /// <exception cref="System.ArgumentException">Raised when the clip region is outside the texture bounds.</exception>
 /// <exception cref="System.NotSupportedException">Raised when the bits per pixel in the texture is not supported.</exception>
 public static Texture ApplyParameters(Texture texture, TextureParameters parameters)
 {
     return(Functions.ApplyParameters(texture, parameters));
 }
        /// <summary>Registeres a texture and returns a handle to the texture.</summary>
        /// <param name="path">The path to the texture.</param>
        /// <param name="parameters">The parameters that specify how to process the texture.</param>
        /// <param name="handle">Receives a handle to the texture.</param>
        /// <returns>Whether registering the texture was successful.</returns>
        internal static bool RegisterTexture(string path, OpenBveApi.Textures.TextureParameters parameters, out Texture handle)
        {
            /* BUG:
             * Attempt to delete null texture handles from the end of the array
             * These sometimes seem to end up there
             *
             * Have also seen a registered textures count of 72 and an array length of 64
             * Is it possible for a texture to fail to register, but still increment the registered textures count?
             *
             * There appears to be a timing issue somewhere whilst loading, as this only happens intermittantly
             */
            if (RegisteredTexturesCount > RegisteredTextures.Length)
            {
                /* BUG:
                 * The registered textures count very occasional becomes greater than the array length (Texture loader crashses possibly?)
                 * This then crashes when we attempt to itinerate the array, so reset it...
                 */
                RegisteredTexturesCount = RegisteredTextures.Length;
            }
            if (RegisteredTexturesCount != 0)
            {
                try
                {
                    for (int i = RegisteredTexturesCount - 1; i > 0; i--)
                    {
                        if (RegisteredTextures[i] != null)
                        {
                            break;
                        }
                        Array.Resize <Texture>(ref RegisteredTextures, RegisteredTextures.Length - 1);
                    }
                }
                catch
                {
                }
            }

            /*
             * Check if the texture is already registered.
             * If so, return the existing handle.
             * */
            for (int i = 0; i < RegisteredTexturesCount; i++)
            {
                if (RegisteredTextures[i] != null)
                {
                    try
                    {
                        //The only exceptions thrown were these when it barfed
                        PathOrigin source = RegisteredTextures[i].Origin as PathOrigin;
                        if (source != null && source.Path == path && source.Parameters == parameters)
                        {
                            handle = RegisteredTextures[i];
                            return(true);
                        }
                    }
                    catch
                    {
                    }
                }
            }

            /*
             * Register the texture and return the newly created handle.
             * */
            int idx = GetNextFreeTexture();

            RegisteredTextures[idx] = new Texture(path, parameters);
            RegisteredTexturesCount++;
            handle = RegisteredTextures[idx];
            return(true);
        }