-
Notifications
You must be signed in to change notification settings - Fork 216
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
Add JS bindings for full libktx #874
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the changes in these comments are all that are needed so ktx_js is only built when the corresponding feature is on.
For some reason I cannot reply on this comment, so replying here: what do you mean by that? |
* Load .png and get data from it. * Display a texture on a rotating cube. * Create div elements
* Make createInfo parameter of ktxTexture{,1,2}_{Create,construct} constant so other language bindings can make it constant. * Expose ktxTexture_calcLevelSize and ktxTexture_GetLevelSize. This became useful when KTX_FACESLICE_WHOLE_LEVEL was added to ktxTexture*_SetImageFrom* and should have been added then. It is prompted now by the addition of a getImage function to the JS binding.
Generate isSrgbFormat to vkformat_check.c.
1815d9b
to
15ab4da
Compare
@abasilak, @ViNeek please review this PR. Please pay particular attention to the following:
I would like the glTF-Compressor to be updated to use this binding. Is there any room in your existing Khronos contract for that work? Better reply to me privately on this question. |
Modify libktx-read-test.js to use new `texture' name and cleanup.
Hi @MarkCallow thank you for the great work. Regarding you comments:
Test page also looks very good. |
Use libktx names with `ktx{,_}` prefix and `_e` suffix removed. Users will no longer need to remember or lookup the different name used in the binding.
@ViNeek thank you for your review and comments. I have made one final (fingers crossed) change. I have changed the enumerator names to be the same as the libktx names minus the |
This PR has been repurposed from adding the Phasmatic bindings for partial write functionality into adding bindings for nearly the full libktx functionality and a test for all the new functionality.
The PR makes the following minor API changes to libktx:
ktxTexture_GetLevelSize
function.ktxTexture[12]_Create
const
.ktxTexture2_{GetPrimaries_e, SetOETF and SetPrimaries}
functions.It adds the following functions to the JS binding while modernizing and greatly improving the binding code:
ktxTexture_Create
.createCopy
findKeyValue
getDataSize
getOETF
getPrimaries
getImage
for retrieving an image from the texture. Fixes ktxTexture should expose its data via JS bindings #288.setImageFromMemory
compressAstc
compressBasis
deflateZstd
deflateZLIB
addKVPairString
andaddKVPairByte
deleteKVPair
setOETF
setPrimaries
writeToMemory
It makes available two bindings. First is a read-only binding,
libktx_read.js
which has the previously available functions plusfindKeyValue
,getDataSize
,getOETF
,getPrimaries
andgetImage
. The second, using the original namelibktx.js
, has functions for creating new KTX texture objects and writing them to files.The JS
ktxTexture
class has been renamedtexture
as typical usage is with an Emscripten module instance name ofktx
andnew ktx.ktxTexture()
looks weird. Newly added classes do not havektx
prefixes.Compared to the Phasmatic bindings it:
compressBasisU
which was bundling calls toktxTexture2_CompressBasisEx
,ktxTexture2_DeflateZstd
,ktxTexture2_WriteToMemory
andktxHashList_addKVPair
. Instead each function now has a binding and can be called by the JS client.createFromBuffer
which was using parameters passed from Javascript to determine the VKFormat and size of the texture then creating it withktxTexture2_Create
and finally loading an image from a passed ArrayBufferView into the texture viaktxTexture_SetImageFromMemory
. Instead aktxCreateInfo
can be initialized in the JS code which can callnew ktxTexture
to create the texture then callsetImageFromMemory
to put the image into the texture object.