android: expose RenderableManager.PrimitiveType value - #10342
android: expose RenderableManager.PrimitiveType value#10342rootkiller6788 wants to merge 3 commits into
Conversation
| PrimitiveType(int value) { mType = value; } | ||
| int getValue() { return mType; } | ||
|
|
||
| /** @return the primitive type's native value (matching the corresponding OpenGL primitive type). */ |
There was a problem hiding this comment.
sounds good, but don't mention OpenGL here, it shouldn't be relevant or required.
There was a problem hiding this comment.
I don't think that's the way to go, the Java bindings don't expose these values in the other enums. If there are APIs that don't take the enum, they should. The original issue mentions gltfio and it sounds like gltfio should just add extra APIs instead of doing this.
Review repliespixelflinger: Thank you for the review! I've fixed the Javadoc as suggested — the OpenGL reference is gone, and romainguy: Thanks for the feedback. I understand the concern about consistency — the other Java enums don't expose their values, and that's largely because they all map to their native counterparts via On "if there are APIs that don't take the enum, they should": the Java API surface already takes the enum directly — Regarding gltfio adding extra APIs: gltfio is a C++ library and already works with the native enum directly; a Java-level API there would be a larger, separate change and wouldn't cover integrations that don't use gltfio. If you'd prefer that direction anyway I'm happy to explore it, but the visibility change here is minimal and behavior-preserving. Could you please take another look? |
|
Then instead of exposing just a single |
|
@romainguy You're right — a one-off
A few enums are intentionally left without the accessor:
I compiled the full bindings with JDK 8 and verified the values returned by the special-cased enums against |
romainguy
left a comment
There was a problem hiding this comment.
Thanks, that looks good!
@pixelflinger can you check if you're ok with the name of the API?
Make PrimitiveType.getValue() public so code outside the com.google.android.filament package can pass the primitive topology through JNI to RenderableManager.setGeometryAt(). The enum values match the native OpenGL primitive types (LINE_STRIP is 3, not its ordinal 2), so ordinal() cannot be used as a substitute.
Per review feedback, the OpenGL mention isn't relevant to the accessor's contract, so remove it and keep the description generic.
Rename RenderableManager.PrimitiveType.getValue() to toFilamentNative() and add the same accessor to every other hand-written Java enum that maps to a native value, so the bindings expose one consistent way to obtain an enum constant's native value. Most enums return ordinal(); PrimitiveType returns its explicit value, StencilFace returns its bit-field mapping, and TargetBufferFlags returns its flag value.
00c0c36 to
d1fd1cc
Compare
|
Thanks @romainguy! Rebased onto the latest main so it's up to date. @pixelflinger — happy to change toFilamentNative() if you'd prefer a different name, just let me know what you'd like. |
pixelflinger
left a comment
There was a problem hiding this comment.
I think some of these enum on the java side are auto-generated by beamsplitter. The toFilamentNative() additions would be overwritten.
note: beamsplitter is currently broken. I will look at it asap.
Summary
Expose the native value of
RenderableManager.PrimitiveTypeby making itsgetValue()method public.Motivation
External Android integrations need to pass the primitive topology through JNI (e.g. to
RenderableManager.setGeometryAt()/Builder.geometry()). TodayPrimitiveType.getValue()is package-private, so callers outsidecom.google.android.filamentcannot obtain the underlying int.The enum's values are not ordinals — they mirror the native
backend::PrimitiveTypewhich is "made to match GL" (LINE_STRIP = 3, skipping 2). Soordinal()cannot be used as a substitute.Change
This only changes Java API visibility and does not affect rendering behavior. Matches the request in #10263.