imgLoadGpuTexture function image

Pointer<SdlGpuTexture> imgLoadGpuTexture(
  1. Pointer<SdlGpuDevice> device,
  2. Pointer<SdlGpuCopyPass> copyPass,
  3. String? file,
  4. Pointer<Int32> width,
  5. Pointer<Int32> height,
)

Load an image from a filesystem path into a GPU texture.

An SDL_GPUTexture represents an image in GPU memory, usable by SDL's GPU API. Regardless of the source format of the image, this function will create a GPU texture with the format SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM with no mip levels. It can be bound as a sampled texture from a graphics or compute pipeline and as a a readonly storage texture in a compute pipeline.

There is a separate function to read files from an SDL_IOStream, if you need an i/o abstraction to provide data from anywhere instead of a simple filesystem read; that function is IMG_LoadGPUTexture_IO().

When done with the returned texture, the app should dispose of it with a call to SDL_ReleaseGPUTexture().

\param device the SDL_GPUDevice to use to create the GPU texture. \param copy_pass the SDL_GPUCopyPass to use to upload the loaded image to the GPU texture. \param file a path on the filesystem to load an image from. \param width a pointer filled in with the width of the GPU texture. may be NULL. \param height a pointer filled in with the width of the GPU texture. may be NULL. \returns a new GPU texture, or NULL on error.

\since This function is available since SDL_image 3.4.0.

\sa IMG_LoadGPUTextureTyped_IO \sa IMG_LoadGPUTexture_IO

extern SDL_DECLSPEC SDL_GPUTexture * SDLCALL IMG_LoadGPUTexture(SDL_GPUDevice *device, SDL_GPUCopyPass *copy_pass, const char *file, int *width, int *height)

Implementation

Pointer<SdlGpuTexture> imgLoadGpuTexture(
  Pointer<SdlGpuDevice> device,
  Pointer<SdlGpuCopyPass> copyPass,
  String? file,
  Pointer<Int32> width,
  Pointer<Int32> height,
) {
  final imgLoadGpuTextureLookupFunction = _libImage
      .lookupFunction<
        Pointer<SdlGpuTexture> Function(
          Pointer<SdlGpuDevice> device,
          Pointer<SdlGpuCopyPass> copyPass,
          Pointer<Utf8> file,
          Pointer<Int32> width,
          Pointer<Int32> height,
        ),
        Pointer<SdlGpuTexture> Function(
          Pointer<SdlGpuDevice> device,
          Pointer<SdlGpuCopyPass> copyPass,
          Pointer<Utf8> file,
          Pointer<Int32> width,
          Pointer<Int32> height,
        )
      >('IMG_LoadGPUTexture');
  final filePointer = file != null ? file.toNativeUtf8() : nullptr;
  final result = imgLoadGpuTextureLookupFunction(
    device,
    copyPass,
    filePointer,
    width,
    height,
  );
  calloc.free(filePointer);
  return result;
}