示例#1
0
        /// <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)
        {
            /*
             * Check if the texture is already registered.
             * If so, return the existing handle.
             * */
            for (int i = 0; i < RegisteredTexturesCount; i++)
            {
                PathOrigin source = RegisteredTextures[i].Origin as PathOrigin;
                if (source != null && source.Path == path && source.Parameters == parameters)
                {
                    handle = RegisteredTextures[i];
                    return(true);
                }
            }

            /*
             * Register the texture and return the newly created handle.
             * */
            if (RegisteredTextures.Length == RegisteredTexturesCount)
            {
                Array.Resize <Texture>(ref RegisteredTextures, RegisteredTextures.Length << 1);
            }
            RegisteredTextures[RegisteredTexturesCount] = new Texture(path, parameters);
            RegisteredTexturesCount++;
            handle = RegisteredTextures[RegisteredTexturesCount - 1];
            return(true);
        }
示例#2
0
        /// <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
 /// <summary>Registeres 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.
      * */
     if (RegisteredTextures.Length == RegisteredTexturesCount)
     {
         Array.Resize <Texture>(ref RegisteredTextures, RegisteredTextures.Length << 1);
     }
     RegisteredTextures[RegisteredTexturesCount] = new Texture(bitmap, parameters);
     RegisteredTexturesCount++;
     return(RegisteredTextures[RegisteredTexturesCount - 1]);
 }
示例#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 < Plugins.LoadedPlugins.Length; i++)
         {
             if (Plugins.LoadedPlugins[i].TextureLoaders.Length > 0)
             {
                 try {
                     for (int l = 0; l < Plugins.LoadedPlugins[i].TextureLoaders.Length; l++)
                     {
                         if (Plugins.LoadedPlugins[i].TextureLoaders[l].CanLoadTexture(path))
                         {
                             try {
                                 if (Plugins.LoadedPlugins[i].TextureLoaders[l].LoadTexture(path, out texture))
                                 {
                                     texture = texture.ApplyParameters(parameters);
                                     return(true);
                                 }
                                 Debug.AddMessage(Debug.MessageType.Error, false,
                                                  "Plugin " + Plugins.LoadedPlugins[i].Title + " returned unsuccessfully at LoadTexture"
                                                  );
                             } catch (Exception ex) {
                                 Debug.AddMessage(Debug.MessageType.Error, false,
                                                  "Plugin " + Plugins.LoadedPlugins[i].Title + " raised the following exception at LoadTexture:" + ex.Message
                                                  );
                             }
                         }
                     }
                 } catch (Exception ex) {
                     Debug.AddMessage(Debug.MessageType.Error, false,
                                      "Plugin " + Plugins.LoadedPlugins[i].Title + " raised the following exception at CanLoadTexture:" + ex.Message
                                      );
                 }
             }
         }
         Debug.AddMessage(Debug.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>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 override bool RegisterTexture(string path, OpenBveApi.Textures.TextureParameters parameters, out OpenBveApi.Textures.TextureHandle handle)
 {
     if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path))
     {
         Textures.Texture data;
         if (Textures.RegisterTexture(path, parameters, out data))
         {
             handle = data;
             return(true);
         }
     }
     else
     {
         ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
     }
     handle = null;
     return(false);
 }
示例#6
0
文件: Host.cs 项目: piotrulos/OpenBVE
 /// <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 < Plugins.LoadedPlugins.Length; i++)
         {
             if (Plugins.LoadedPlugins[i].Texture != null)
             {
                 try
                 {
                     if (Plugins.LoadedPlugins[i].Texture.CanLoadTexture(path))
                     {
                         try
                         {
                             if (Plugins.LoadedPlugins[i].Texture.LoadTexture(path, out texture))
                             {
                                 //texture.CompatibleTransparencyMode = Interface.CurrentOptions.OldTransparencyMode;
                                 texture = texture.ApplyParameters(parameters);
                                 return(true);
                             }
                             Interface.AddMessage(Interface.MessageType.Error, false, "Plugin " + Plugins.LoadedPlugins[i].Title + " returned unsuccessfully at LoadTexture");
                         }
                         catch (Exception ex)
                         {
                             Interface.AddMessage(Interface.MessageType.Error, false, "Plugin " + Plugins.LoadedPlugins[i].Title + " raised the following exception at LoadTexture:" + ex.Message);
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     Interface.AddMessage(Interface.MessageType.Error, false, "Plugin " + Plugins.LoadedPlugins[i].Title + " raised the following exception at CanLoadTexture:" + ex.Message);
                 }
             }
         }
         Interface.AddMessage(Interface.MessageType.Error, false, "No plugin found that is capable of loading texture " + path);
     }
     else
     {
         ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
     }
     texture = null;
     return(false);
 }
示例#7
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>
 internal Texture(Bitmap bitmap, OpenBveApi.Textures.TextureParameters parameters)
 {
     this.Origin         = new BitmapOrigin(bitmap, parameters);
     this.OpenGlTextures = new OpenGlTexture[] { new OpenGlTexture(), new OpenGlTexture(), new OpenGlTexture(), new OpenGlTexture() };
 }
示例#8
0
 // --- constructors ---
 /// <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>
 internal Texture(string path, OpenBveApi.Textures.TextureParameters parameters)
 {
     this.Origin         = new PathOrigin(path, 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 override bool RegisterTexture(OpenBveApi.Textures.Texture texture, OpenBveApi.Textures.TextureParameters parameters, out OpenBveApi.Textures.TextureHandle handle)
 {
     texture = texture.ApplyParameters(parameters);
     handle  = Textures.RegisterTexture(texture);
     return(true);
 }
示例#10
0
        /// <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.
             * */
            if (RegisteredTextures.Length == RegisteredTexturesCount)
            {
                Array.Resize <Texture>(ref RegisteredTextures, RegisteredTextures.Length << 1);
            }
            RegisteredTextures[RegisteredTexturesCount] = new Texture(path, parameters);
            RegisteredTexturesCount++;
            handle = RegisteredTextures[RegisteredTexturesCount - 1];
            return(true);
        }
示例#11
0
 // --- constructors ---
 /// <summary>Creates a new path origin.</summary>
 /// <param name="path">The path to the texture.</param>
 /// <param name="parameters">The parameters that specify how to process the texture.</param>
 internal PathOrigin(string path, OpenBveApi.Textures.TextureParameters parameters)
 {
     this.Path       = path;
     this.Parameters = parameters;
 }
示例#12
0
 /// <summary>Creates a new bitmap origin.</summary>
 /// <param name="bitmap">The bitmap.</param>
 /// <param name="parameters">The texture parameters</param>
 internal BitmapOrigin(Bitmap bitmap, OpenBveApi.Textures.TextureParameters parameters)
 {
     this.Bitmap     = bitmap;
     this.Parameters = parameters;
 }
			// --- constructors ---
			/// <summary>Creates a new path origin.</summary>
			/// <param name="path">The path to the texture.</param>
			/// <param name="parameters">The parameters that specify how to process the texture.</param>
			internal PathOrigin(string path, OpenBveApi.Textures.TextureParameters parameters) {
				this.Path = path;
				this.Parameters = parameters;
			}
示例#14
0
			/// <summary>Creates a new bitmap origin.</summary>
			/// <param name="bitmap">The bitmap.</param>
			/// <param name="parameters">The texture parameters</param>
			internal BitmapOrigin(Bitmap bitmap, OpenBveApi.Textures.TextureParameters parameters)
			{
				this.Bitmap = bitmap;
				this.Parameters = parameters;
			}