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

Fix JNI function name for getDataSizeUncompressed #957

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

javagl
Copy link
Contributor

@javagl javagl commented Nov 12, 2024

A small fix for the JNI bindings:

The function signature for getDataSizeUncompressed was given as
Java_org_khronos_KTXTexture_getDataSizeUncompressed but must be
Java_org_khronos_ktx_KtxTexture_getDataSizeUncompressed (matching the full package- and class name)

Currently, calling this function would result in a
java.lang.UnsatisfiedLinkError: org.khronos.ktx.KtxTexture.getDataSizeUncompressed()J

I also added a test that might look useless at the first glance: It just creates a texture, and calls all the native "getter" functions on that (without any assertion). The point of that test is that it would have prevented this kind of error...

@@ -599,4 +599,37 @@ public void testSupercompressionZLIB() throws IOException {

t.destroy();
}

@Test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment similar to what you wrote in the PR description about this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That certainly makes sense (otherwise, people might wonder what the purpose of the test is).

(An aside: In another context, I automated this kind of test, using some reflection magic - but here, we only have ~20 native functions, whereas for JCuda, it was about (literally) thousands of native methods in dozens of classes...)

@MarkCallow MarkCallow merged commit f3902db into KhronosGroup:main Nov 15, 2024
17 checks passed
@MarkCallow
Copy link
Collaborator

Thanks @javagl.

MarkCallow pushed a commit that referenced this pull request Nov 19, 2024
(This builds upon #957,
so that should be merged first)

This adds bindings for the `ktxTexture_GLUpload` function to the Java
interface.

There certainly are a few degrees of freedom about how _exactly_ that
should be offered. And there is a trade-off between "trying to closely
resemble the existing API" and "trying to create a nice API for Java".
The main point here being that the function receives three _pointers_
(to `int` values, essentially). And pointers don't exist in Java.

A common (although not pretty) way is to emulate these with
single-element arrays. So the call currently looks like this:
```
int texture[] = { 0 };
int target[] = { 0 };
int glError[] = { 0 };
int result = ktxTexture.glUpload(texture, target, glError);
```
This will fill the given arrays with the values that are returned from
the native layer, accordingly.

Proper testing may be difficult. The basic call conditions are checked
in a unit test. But beyond that, really _using_ the function will
require an OpenGL context to be current, so that 1. requires an OpenGL
binding for the test, and 2. can hardly happen during the standard test
runs.


---

I tried it out in a _very_ basic experiment. This experiment currently
used https://www.lwjgl.org/ , but I'll probably also try it with
https://jogamp.org/ . Given that LWJGL is the library behind
https://libgdx.com/ and https://jmonkeyengine.org/ , that's likely to be
a primary goal.

The result of that experiment is shown here...

![Khronos KTX in
Java](https://github.com/user-attachments/assets/7c86d565-5fdf-4f31-a20c-f6616c2c99ed)

... and I frankly couldn't care less that it's upside down. It works 🙃
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 this pull request may close these issues.

2 participants