diff options
Diffstat (limited to 'servers/camera/camera_feed.cpp')
-rw-r--r-- | servers/camera/camera_feed.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/servers/camera/camera_feed.cpp b/servers/camera/camera_feed.cpp index 355728beea..00deef0a7f 100644 --- a/servers/camera/camera_feed.cpp +++ b/servers/camera/camera_feed.cpp @@ -52,6 +52,8 @@ void CameraFeed::_bind_methods() { ClassDB::bind_method(D_METHOD("set_rgb_image", "rgb_image"), &CameraFeed::set_rgb_image); ClassDB::bind_method(D_METHOD("set_ycbcr_image", "ycbcr_image"), &CameraFeed::set_ycbcr_image); + ClassDB::bind_method(D_METHOD("set_external", "width", "height"), &CameraFeed::set_external); + ClassDB::bind_method(D_METHOD("get_texture_tex_id", "feed_image_type"), &CameraFeed::get_texture_tex_id); ClassDB::bind_method(D_METHOD("get_datatype"), &CameraFeed::get_datatype); @@ -70,6 +72,7 @@ void CameraFeed::_bind_methods() { BIND_ENUM_CONSTANT(FEED_RGB); BIND_ENUM_CONSTANT(FEED_YCBCR); BIND_ENUM_CONSTANT(FEED_YCBCR_SEP); + BIND_ENUM_CONSTANT(FEED_EXTERNAL); BIND_ENUM_CONSTANT(FEED_UNSPECIFIED); BIND_ENUM_CONSTANT(FEED_FRONT); @@ -139,6 +142,10 @@ RID CameraFeed::get_texture(CameraServer::FeedImage p_which) { return texture[p_which]; } +uint64_t CameraFeed::get_texture_tex_id(CameraServer::FeedImage p_which) { + return RenderingServer::get_singleton()->texture_get_native_handle(texture[p_which]); +} + CameraFeed::CameraFeed() { // initialize our feed id = CameraServer::get_singleton()->get_free_id(); @@ -254,6 +261,19 @@ void CameraFeed::set_ycbcr_images(const Ref<Image> &p_y_img, const Ref<Image> &p } } +void CameraFeed::set_external(int p_width, int p_height) { + if ((base_width != p_width) || (base_height != p_height)) { + // We're assuming here that our camera image doesn't change around formats etc, allocate the whole lot... + base_width = p_width; + base_height = p_height; + + auto new_texture = RenderingServer::get_singleton()->texture_external_create(p_width, p_height, 0); + RenderingServer::get_singleton()->texture_replace(texture[CameraServer::FEED_YCBCR_IMAGE], new_texture); + } + + datatype = CameraFeed::FEED_EXTERNAL; +} + bool CameraFeed::activate_feed() { // nothing to do here return true; |