Browse Source

Renamed ImageReaderCallback to ImageDecodeCallback since the former was misleading.

Vicente Penades 5 years ago
parent
commit
d9bc3a5f5c

+ 1 - 1
src/SharpGLTF.Core/IO/ReadContext.cs

@@ -79,7 +79,7 @@ namespace SharpGLTF.IO
             : base(other)
         {
             this._FileReader = other._FileReader;
-            this.ImageReader = other.ImageReader;
+            this.ImageDecoder = other.ImageDecoder;
         }
 
         #endregion

+ 16 - 5
src/SharpGLTF.Core/Schema2/gltf.Serialization.Read.cs

@@ -12,7 +12,13 @@ namespace SharpGLTF.Schema2
 {
     using MODEL = ModelRoot;
 
-    public delegate Boolean ImageReaderCallback(Image image);
+    /// <summary>
+    /// Callback used to intercept the loading of textures so they can be decoded by the client
+    /// engine and uploaded to the GPU if neccesary.
+    /// </summary>
+    /// <param name="image">The Image containing the texture</param>
+    /// <returns>true if we want to keep the image memory data in Image. Otherwise the memory will be cleared.</returns>    
+    public delegate Boolean ImageDecodeCallback(Image image);
 
     /// <summary>
     /// Settings to customize how <see cref="MODEL"/> files are read.
@@ -46,7 +52,10 @@ namespace SharpGLTF.Schema2
         /// </summary>
         public VALIDATIONMODE Validation { get; set; } = VALIDATIONMODE.Strict;
 
-        public ImageReaderCallback ImageReader { get; set; }
+        /// <summary>
+        /// Gets or sets the callback used to decode the textures as they're loaded.
+        /// </summary>
+        public ImageDecodeCallback ImageDecoder { get; set; }
 
         #endregion
 
@@ -56,7 +65,7 @@ namespace SharpGLTF.Schema2
         {
             Guard.NotNull(other, nameof(other));
             other.Validation = this.Validation;
-            other.ImageReader = this.ImageReader;
+            other.ImageDecoder = this.ImageDecoder;
         }
 
         #endregion
@@ -216,11 +225,13 @@ namespace SharpGLTF.Schema2
 
             foreach (var image in this._images)
             {
+                // reads the image file into the current object.
                 image._ResolveUri(context);
 
-                if (context.ImageReader != null)
+                // if we have a decoder hook, call the decoder, and free the memory.
+                if (context.ImageDecoder != null)
                 {
-                    if (!context.ImageReader(image))
+                    if (!context.ImageDecoder(image))
                     {
                         image._DiscardContent();
                     }