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

Expose a function to create textures from a native handle in the compatibility renderer #96928

Conversation

dsnopek
Copy link
Contributor

@dsnopek dsnopek commented Sep 12, 2024

There is already a function in the compatibility renderer to create a texture from a native handle, however, it is unexposed and badly named, which is GLES3::TextureStorage::texture_create_external().

We need to expose it in order to implement some OpenXR extensions via GDExtension in the 'godot_openxr_vendor' repo.

But it is badly named, because there is an effort to add support for GL_TEXTURE_EXTERNAL_OES (see PR #96705 and #83519), and since that is from official GLES extensions, it would be better to call that an "external texture", and rename the existing function to something else.

We discussed a number of names for this over here, but I ended up going with something else in this PR: RenderingServer::texture_create_from_native_handle() (which I picked because it pairs with RenderingServer::texture_get_native_handle()).

I'm happy to continue discussing names for this if folks don't like it!

NOTE: There is already function for doing this when using rendering device, RenderingDevice::texture_create_from_extension() (also not named very well :-)), which allows configuring many RD-specific options. Since this PR adds a function to RenderingServer, we also need to implement it for the RD renderer, but it just calls RenderingDevice::texture_create_from_extension() while making a bunch of assumptions for the RD-specific options. Most folks using the RD render would probably be better off using the RD-specific function, rather than the generic one on RenderingServer, which I've noted in the docs.

@dsnopek dsnopek added this to the 4.x milestone Sep 12, 2024
@dsnopek dsnopek requested review from a team as code owners September 12, 2024 18:21
@dsnopek dsnopek force-pushed the rename-and-expose-texture-create-external branch 5 times, most recently from a3fe3a4 to 290570a Compare September 12, 2024 19:32
@dsnopek dsnopek requested a review from devloglogan September 18, 2024 21:30
Copy link
Contributor

@BastiaanOlij BastiaanOlij left a comment

Choose a reason for hiding this comment

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

LGTM, as discussed already on rocketchat, this is a much better name to prevent confusion with Android external textures.

@@ -1108,6 +1108,195 @@ void TextureStorage::texture_proxy_initialize(RID p_texture, RID p_base) {
tex->proxies.push_back(p_texture);
}

// Note: We make some big assumptions about format and usage. If developers need more control,
// they should use RD::texture_create_from_extension() instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it correct this comment refers to texture_create_from_extension ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! This PR adds RenderingServer::texture_create_from_native_handle() which is implemented by both OpenGL and the rendering device renderers, but if you're using rendering device you can get more control by using the pre-existing RenderingDevice::texture_create_from_extension() which has more options. I put a similar note in the docs.

@akien-mga akien-mga modified the milestones: 4.x, 4.4 Sep 19, 2024
Copy link
Contributor

@devloglogan devloglogan left a comment

Choose a reason for hiding this comment

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

I think the rename you chose to go with is suitable. Code LGTM!

@dsnopek dsnopek force-pushed the rename-and-expose-texture-create-external branch from 290570a to 7d56b09 Compare September 19, 2024 14:05
@akien-mga akien-mga merged commit b1b4c5d into godotengine:master Sep 19, 2024
20 checks passed
@akien-mga
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

5 participants