Beispiel #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);
        }
Beispiel #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]);
        }
Beispiel #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]);
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #6
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].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);
 }
Beispiel #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() };
 }
Beispiel #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() };
 }
Beispiel #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);
 }
Beispiel #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);
        }
Beispiel #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;
 }
Beispiel #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;
			}
			/// <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;
			}