feat: updated engine

This commit is contained in:
Sara Gerretsen 2026-07-10 17:04:34 +02:00
parent cbe99774ff
commit f4cf6b3999
6607 changed files with 910135 additions and 430025 deletions

View file

@ -30,6 +30,7 @@
#include "camera_feed.h"
#include "core/object/class_db.h"
#include "servers/rendering/rendering_server.h"
void CameraFeed::_bind_methods() {
@ -61,6 +62,8 @@ void CameraFeed::_bind_methods() {
GDVIRTUAL_BIND(_activate_feed);
GDVIRTUAL_BIND(_deactivate_feed);
GDVIRTUAL_BIND(_set_format, "index", "parameters");
GDVIRTUAL_BIND(_get_formats);
ADD_SIGNAL(MethodInfo("frame_changed"));
ADD_SIGNAL(MethodInfo("format_changed"));
@ -189,21 +192,17 @@ void CameraFeed::set_rgb_image(const Ref<Image> &p_rgb_img) {
int new_width = p_rgb_img->get_width();
int new_height = p_rgb_img->get_height();
// Emit `format_changed` signal if feed datatype or frame size is changed.
// The signal is deferred to ensure:
// - They are emitted on Godot's main thread.
// - Both datatype and frame size are updated before the emission.
if (datatype != CameraFeed::FEED_RGB || (base_width != new_width) || (base_height != new_height)) {
call_deferred("emit_signal", format_changed_signal_name);
}
if ((base_width != new_width) || (base_height != new_height)) {
// We're assuming here that our camera image doesn't change around formats etc, allocate the whole lot...
base_width = new_width;
base_height = new_height;
RID new_texture = RenderingServer::get_singleton()->texture_2d_create(p_rgb_img);
RenderingServer::get_singleton()->texture_replace(texture[CameraServer::FEED_RGBA_IMAGE], new_texture);
// `format_changed` signal is deferred to ensure:
// - They are emitted on Godot's main thread.
// - Both datatype and frame size are updated before the emission.
call_deferred("emit_signal", format_changed_signal_name);
} else {
RenderingServer::get_singleton()->texture_2d_update(texture[CameraServer::FEED_RGBA_IMAGE], p_rgb_img);
}
@ -221,23 +220,19 @@ void CameraFeed::set_ycbcr_image(const Ref<Image> &p_ycbcr_img) {
int new_width = p_ycbcr_img->get_width();
int new_height = p_ycbcr_img->get_height();
// Emit `format_changed` signal if feed datatype or frame size is changed.
// The signal is deferred to ensure:
// - They are emitted on Godot's main thread.
// - Both datatype and frame size are updated before the emission.
if (datatype != CameraFeed::FEED_YCBCR || (base_width != new_width) || (base_height != new_height)) {
call_deferred("emit_signal", format_changed_signal_name);
}
if ((base_width != new_width) || (base_height != new_height)) {
// We're assuming here that our camera image doesn't change around formats etc, allocate the whole lot...
base_width = new_width;
base_height = new_height;
RID new_texture = RenderingServer::get_singleton()->texture_2d_create(p_ycbcr_img);
RenderingServer::get_singleton()->texture_replace(texture[CameraServer::FEED_RGBA_IMAGE], new_texture);
RenderingServer::get_singleton()->texture_replace(texture[CameraServer::FEED_YCBCR_IMAGE], new_texture);
// `format_changed` signal is deferred to ensure:
// - They are emitted on Godot's main thread.
// - Both datatype and frame size are updated before the emission.
call_deferred("emit_signal", format_changed_signal_name);
} else {
RenderingServer::get_singleton()->texture_2d_update(texture[CameraServer::FEED_RGBA_IMAGE], p_ycbcr_img);
RenderingServer::get_singleton()->texture_2d_update(texture[CameraServer::FEED_YCBCR_IMAGE], p_ycbcr_img);
}
datatype = CameraFeed::FEED_YCBCR;
@ -258,16 +253,7 @@ void CameraFeed::set_ycbcr_images(const Ref<Image> &p_y_img, const Ref<Image> &p
int new_y_width = p_y_img->get_width();
int new_y_height = p_y_img->get_height();
// Emit `format_changed` signal if feed datatype or frame size is changed.
// The signal is deferred to ensure:
// - They are emitted on Godot's main thread.
// - Both datatype and frame size are updated before the emission.
if (datatype != CameraFeed::FEED_YCBCR_SEP || (base_width != new_y_width) || (base_height != new_y_height)) {
call_deferred("emit_signal", format_changed_signal_name);
}
if ((base_width != new_y_width) || (base_height != new_y_height)) {
// We're assuming here that our camera image doesn't change around formats etc, allocate the whole lot...
base_width = new_y_width;
base_height = new_y_height;
{
@ -278,6 +264,11 @@ void CameraFeed::set_ycbcr_images(const Ref<Image> &p_y_img, const Ref<Image> &p
RID new_texture = RenderingServer::get_singleton()->texture_2d_create(p_cbcr_img);
RenderingServer::get_singleton()->texture_replace(texture[CameraServer::FEED_CBCR_IMAGE], new_texture);
}
// `format_changed` signal is deferred to ensure:
// - They are emitted on Godot's main thread.
// - Both datatype and frame size are updated before the emission.
call_deferred("emit_signal", format_changed_signal_name);
} else {
RenderingServer::get_singleton()->texture_2d_update(texture[CameraServer::FEED_Y_IMAGE], p_y_img);
RenderingServer::get_singleton()->texture_2d_update(texture[CameraServer::FEED_CBCR_IMAGE], p_cbcr_img);
@ -291,21 +282,17 @@ 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) {
// Emit `format_changed` signal if feed datatype or frame size is changed.
// The signal is deferred to ensure:
// - They are emitted on Godot's main thread.
// - Both datatype and frame size are updated before the emission.
if (datatype != CameraFeed::FEED_EXTERNAL || (base_width != p_width) || (base_height != p_height)) {
call_deferred("emit_signal", format_changed_signal_name);
}
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;
RID 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);
// `format_changed` signal is deferred to ensure:
// - They are emitted on Godot's main thread.
// - Both datatype and frame size are updated before the emission.
call_deferred("emit_signal", format_changed_signal_name);
}
datatype = CameraFeed::FEED_EXTERNAL;
@ -325,11 +312,15 @@ void CameraFeed::deactivate_feed() {
}
bool CameraFeed::set_format(int p_index, const Dictionary &p_parameters) {
return false;
bool ret = false;
GDVIRTUAL_CALL(_set_format, p_index, p_parameters, ret);
return ret;
}
Array CameraFeed::get_formats() const {
return Array();
Array ret;
GDVIRTUAL_CALL(_get_formats, ret);
return ret;
}
CameraFeed::FeedFormat CameraFeed::get_format() const {