Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow different implementations of TextureResource #20

Open
5 tasks done
wakaztahir opened this issue Oct 11, 2023 · 1 comment · May be fixed by #23
Open
5 tasks done

Allow different implementations of TextureResource #20

wakaztahir opened this issue Oct 11, 2023 · 1 comment · May be fixed by #23

Comments

@wakaztahir
Copy link

wakaztahir commented Oct 11, 2023

Use Case

Android has GL calls to allow providing a Bitmap as texture data, Currently you need to copy the bitmap to a buffer before you can pass it to Kgl

  • When you load an image in android, You usually load a Bitmap for it
  • If you do load an image as buffer, You also need to provide a width and height, easy solution becomes loading a bitmap since it contains width and height, If you need to be memory efficient, You'll load the bitmap inJustDecodeBounds to get width and height and then load the bitmap as buffer which is a bit complex
  • Bitmap doesn't provide access to a Buffer object, It does but that's HardwareBuffer which doesn't extend Java Buffer
  • The constructor for Buffer that takes a Java Buffer is internal (even if it were public, there's no buffer)
  • When you load a bitmap, You must copy over the pixels from bitmap to a Buffer which is more work & not the best way !

Solution : Introduce TextureAsset interface, Make TextureResource implementation of TextureAsset

TextureResource can be a deprecated typealias for BufferTextureAsset (Later)

  • Split JVM to android & desktop target
  • Keep JVM TextureResource same in desktop, Keep other types same in both android and desktop
  • Create TextureAsset interface in commonMain & make TextureResource implement TextureAsset
  • TextureBitmapAsset can be implemented on Android
  • TextureAsset basically has methods that are called by Kgl itself to make gl calls & its given a Kgl instance with that call and parameters (There is no other way)

The only CON with this solution is that anyone can implement TextureAsset, in my opinion that is OK since

I've implemented it in the linked pull request, except for the iOS platform since I work on windows !

@wakaztahir
Copy link
Author

wakaztahir commented Oct 11, 2023

@gergelydaniel Could you please let me know your thoughts about this

@wakaztahir wakaztahir changed the title Accept a Bitmap in TextureResource in Android Allow different implementations of TextureResource Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant