stride3d / stride

Stride Game Engine (formerly Xenko)
https://stride3d.net
MIT License
6.32k stars 917 forks source link

feat: Adjust freeimage to all platforms #2303

Closed Jklawreszuk closed 1 week ago

Jklawreszuk commented 3 weeks ago

PR Details

This PR adjust FreeImage loading for macos and linux distributions (these operating systems load this dependency from packages). From now, FreeImage is handling image files instead of DirectXTex library (LoadWICFile method is only available for Windows) .

Types of changes

Checklist

Eideren commented 3 weeks ago

TC is complaining, might need to adjust those texture extensions you removed to get loaded by freeimage instead ? https://teamcity.stride3d.net/buildConfiguration/Engine_Tests_WindowsSimple/25548?hideTestsFromDependencies=false&hideProblemsFromDependencies=false&expandBuildDeploymentsSection=false&expandPull+Request+Details=true&expandBuildChangesSection=true&expandBuildProblemsSection=true

Jklawreszuk commented 3 weeks ago

@Eideren Glad the tests caught the error 😅 According to the documentation, it seems that FreeImage has dedicated both Unicode and Non-Unicode methods that should be used accordingly on Windows or Unix systems.

FreeImage 3.18.0 documentation FreeImage_LoadU Note that this function only works on MS Windows operating systems. On other systems, the function does nothing and returns NULL.

Jklawreszuk commented 3 weeks ago

I started looking for inspiration and it looks like our friends at Monogame fixed this by using appropriate method depending on the system. I will try to go in this direction Monogame :

[DllImport(NativeLibName, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")]
      public static extern IntPtr LoadU(FREE_IMAGE_FORMAT fif, string filename, int flags);

      [DllImport(NativeLibName, EntryPoint = "FreeImage_Load")]
      public static extern IntPtr LoadS(FREE_IMAGE_FORMAT fif, string filename, int flags);

      public static IntPtr Load(FREE_IMAGE_FORMAT fif, string filename, int flags)
      {
          if (CurrentPlatform.OS == OS.Windows)
              return LoadU(fif, filename, flags);
          else
              return LoadS(fif, filename, flags);
      }
Jklawreszuk commented 2 weeks ago

Done! @Eideren, Could you try to run tests again?

Eideren commented 2 weeks ago

We have a certificate issue right now that xen is looking into, I'll get back to you once it's done :)

Eideren commented 1 week ago

Thanks !