Skip to content

android: expose RenderableManager.PrimitiveType value - #10342

Open
rootkiller6788 wants to merge 3 commits into
google:mainfrom
rootkiller6788:fix-primitive-type-getvalue-public
Open

android: expose RenderableManager.PrimitiveType value#10342
rootkiller6788 wants to merge 3 commits into
google:mainfrom
rootkiller6788:fix-primitive-type-getvalue-public

Conversation

@rootkiller6788

Copy link
Copy Markdown

Summary

Expose the native value of RenderableManager.PrimitiveType by making its getValue() method public.

Motivation

External Android integrations need to pass the primitive topology through JNI (e.g. to RenderableManager.setGeometryAt() / Builder.geometry()). Today PrimitiveType.getValue() is package-private, so callers outside com.google.android.filament cannot obtain the underlying int.

The enum's values are not ordinals — they mirror the native backend::PrimitiveType which is "made to match GL" (LINE_STRIP = 3, skipping 2). So ordinal() cannot be used as a substitute.

Change

public int getValue() { return mType; }

This only changes Java API visibility and does not affect rendering behavior. Matches the request in #10263.

PrimitiveType(int value) { mType = value; }
int getValue() { return mType; }

/** @return the primitive type's native value (matching the corresponding OpenGL primitive type). */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

sounds good, but don't mention OpenGL here, it shouldn't be relevant or required.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@pixelflinger pixelflinger added the internal Issue/PR does not affect clients label Aug 21, 2026
@rootkiller6788

Copy link
Copy Markdown
Author

Review replies

pixelflinger: Thank you for the review! I've fixed the Javadoc as suggested — the OpenGL reference is gone, and getValue() now simply documents that it returns the value of the primitive type.

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 ordinal(). PrimitiveType is the one exception in the bindings: the native backend::PrimitiveType is explicitly "made to match GL" (filament/backend/include/backend/DriverEnums.h), so LINE_STRIP = 3 and the sequence skips 2. ordinal() would silently produce the wrong value (LINE_STRIP=2), which is why the enum already stores an explicit value and the bindings already pass it through getValue() internally (e.g. in Builder.geometry() and setGeometryAt()).

On "if there are APIs that don't take the enum, they should": the Java API surface already takes the enum directly — Builder.geometry() and RenderableManager.setGeometryAt() both accept PrimitiveType. This change doesn't add any new int-typed entry point; it only widens the visibility of the existing accessor so that external integrations (issue #10263) can bridge the value through their own JNI layer, where the enum instance isn't available on the native side.

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?

@rootkiller6788
rootkiller6788 marked this pull request as ready for review August 22, 2026 17:55
@romainguy

Copy link
Copy Markdown
Contributor

Then instead of exposing just a single getValue() maybe all Java enums should have a toFilamentNative() or equivalent to at least be consistent (which for most enums would just be a call to ordinal()).

@rootkiller6788

Copy link
Copy Markdown
Author

@romainguy You're right — a one-off getValue() is inconsistent with the rest of the bindings, so I've implemented the toFilamentNative() direction in commit 00c0c36:

  • RenderableManager.PrimitiveType.getValue() is renamed to toFilamentNative(), still returning the primitive type's explicit native value (0/1/3/4/5, matching backend::PrimitiveType); all internal callers were updated.
  • Every other hand-written Java enum that is passed to native code now exposes the same public int toFilamentNative() accessor. For most of them this is simply return ordinal();. The three enums whose native value cannot be derived from ordinal() are handled explicitly:
    • MaterialInstance.StencilFace → returns its bit-field mapping {0x1, 0x2, 0x3};
    • View.TargetBufferFlags → returns the flag's bit value;
    • RenderableManager.PrimitiveType → returns its explicit value.

A few enums are intentionally left without the accessor:

  • the beamsplitter-generated part of View.java (generated code shouldn't be hand-edited);
  • enums that are purely Java descriptors with no native counterpart (Colors.*, Material.Parameter.Type/Precision, NioUtils.BufferType);
  • Fence.FenceStatus, which is a result type converted from native rather than an input, and whose ordinals don't match the native values (-1/0/1).

I compiled the full bindings with JDK 8 and verified the values returned by the special-cased enums against backend/DriverEnums.h. Could you take another look?

@romainguy romainguy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
@rootkiller6788
rootkiller6788 force-pushed the fix-primitive-type-getvalue-public branch from 00c0c36 to d1fd1cc Compare August 24, 2026 03:15
@rootkiller6788

Copy link
Copy Markdown
Author

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 pixelflinger left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Issue/PR does not affect clients

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants