feat: updated godot version

This commit is contained in:
Sara Gerretsen 2026-04-04 19:38:56 +02:00
parent 0c508b0831
commit 42b028dbb5
4694 changed files with 236470 additions and 401376 deletions

View file

@ -6,25 +6,19 @@ Import("env_modules")
env_camera = env_modules.Clone()
if env["platform"] in ["windows", "macos", "linuxbsd", "android", "ios", "visionos"]:
if env["platform"] in ["windows", "macos", "linuxbsd", "android"]:
env_camera.add_source_files(env.modules_sources, "register_types.cpp")
if env["platform"] == "windows":
env_camera.add_source_files(env.modules_sources, "camera_win.cpp")
elif env["platform"] == "macos":
env_camera.add_source_files(env.modules_sources, "camera_apple.mm")
env_camera.add_source_files(env.modules_sources, "camera_macos.mm")
elif env["platform"] == "android":
env_camera.add_source_files(env.modules_sources, "camera_android.cpp")
env.Append(LIBS=["camera2ndk", "mediandk"])
elif env["platform"] in ["ios", "visionos"]:
ext_module_source = ["camera_apple.mm"]
ext_camera_lib = env_camera.add_library("#bin/libgodot_camera", ext_module_source)
env.Append(LIBS_EXTERNAL=[ext_camera_lib])
env.Append(MODULES_EXTERNAL=["_camera"])
elif env["platform"] == "linuxbsd":
env_camera.add_source_files(env.modules_sources, "camera_linux.cpp")
env_camera.add_source_files(env.modules_sources, "camera_feed_linux.cpp")

View file

@ -31,7 +31,6 @@
#include "camera_android.h"
#include "core/os/os.h"
#include "platform/android/display_server_android.h"
#include "platform/android/java_godot_io_wrapper.h"
#include "platform/android/os_android.h"
@ -73,7 +72,7 @@ public:
#ifndef IF_EQUAL_RETURN
#define MAKE_FORMAT_CONST(suffix) AIMAGE_FORMAT_##suffix
#define IF_EQUAL_RETURN(param, val) \
#define IF_EQUAL_RETURN(param, val) \
if (MAKE_FORMAT_CONST(val) == param) \
return #val
#endif
@ -90,7 +89,8 @@ String GetFormatName(const int32_t &format) {
// CameraFeedAndroid - Subclass for our camera feed on Android
CameraFeedAndroid::CameraFeedAndroid(ACameraManager *manager, ACameraMetadata *metadata, const char *id,
CameraFeed::FeedPosition position, int32_t orientation) {
CameraFeed::FeedPosition position, int32_t orientation) :
CameraFeed() {
this->manager = manager;
this->metadata = metadata;
this->orientation = orientation;

View file

@ -40,7 +40,6 @@
#include <camera/NdkCameraManager.h>
#include <camera/NdkCameraMetadataTags.h>
#include <media/NdkImageReader.h>
#include <optional>
enum class CameraFacing {

View file

@ -350,7 +350,8 @@ bool CameraFeedLinux::set_format(int p_index, const Dictionary &p_parameters) {
return true;
}
CameraFeedLinux::CameraFeedLinux(const String &p_device_name) {
CameraFeedLinux::CameraFeedLinux(const String &p_device_name) :
CameraFeed() {
device_name = p_device_name;
_query_device(device_name);
}

View file

@ -32,7 +32,6 @@
#include "core/os/mutex.h"
#include "core/os/thread.h"
#include "core/templates/safe_refcount.h"
#include "servers/camera/camera_server.h"
class CameraLinux : public CameraServer {

View file

@ -1,5 +1,5 @@
/**************************************************************************/
/* camera_apple.h */
/* camera_macos.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -35,11 +35,11 @@
#include "servers/camera/camera_server.h"
class CameraApple : public CameraServer {
GDSOFTCLASS(CameraApple, CameraServer);
class CameraMacOS : public CameraServer {
GDSOFTCLASS(CameraMacOS, CameraServer);
public:
CameraApple() = default;
CameraMacOS() = default;
void update_feeds();
void set_monitoring_feeds(bool p_monitoring_feeds) override;

View file

@ -1,5 +1,5 @@
/**************************************************************************/
/* camera_apple.mm */
/* camera_macos.mm */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -31,14 +31,11 @@
///@TODO this is a near duplicate of CameraIOS, we should find a way to combine those to minimize code duplication!!!!
// If you fix something here, make sure you fix it there as well!
#import "camera_apple.h"
#import "camera_macos.h"
#include "servers/camera/camera_feed.h"
#import <AVFoundation/AVFoundation.h>
#ifdef IOS_ENABLED
#import <UIKit/UIKit.h>
#endif
//////////////////////////////////////////////////////////////////////////
// MyCaptureSession - This is a little helper class so we can capture our frames
@ -66,30 +63,23 @@
width[1] = 0;
height[1] = 0;
#ifdef IOS_ENABLED
if ([p_device lockForConfiguration:&error]) {
if ([p_device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]) {
[p_device setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
}
if ([p_device isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) {
[p_device setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
}
if ([p_device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance]) {
[p_device setWhiteBalanceMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance];
}
#ifdef APPLE_EMBEDDED_ENABLED
[p_device lockForConfiguration:&error];
[p_device unlockForConfiguration];
}
#endif // IOS_ENABLED
[p_device setFocusMode:AVCaptureFocusModeLocked];
[p_device setExposureMode:AVCaptureExposureModeLocked];
[p_device setWhiteBalanceMode:AVCaptureWhiteBalanceModeLocked];
[p_device unlockForConfiguration];
#endif // APPLE_EMBEDDED_ENABLED
[self beginConfiguration];
#ifdef IOS_ENABLED
#ifdef APPLE_EMBEDDED_ENABLED
self.sessionPreset = AVCaptureSessionPreset1280x720;
#endif // IOS_ENABLED
input = [[AVCaptureDeviceInput alloc] initWithDevice:p_device error:&error];
#endif // APPLE_EMBEDDED_ENABLED
input = [AVCaptureDeviceInput deviceInputWithDevice:p_device error:&error];
if (!input) {
print_line("Couldn't get input device for camera");
[self commitConfiguration];
@ -229,28 +219,6 @@
// set our texture...
feed->set_ycbcr_images(img[0], img[1]);
#ifdef IOS_ENABLED
UIInterfaceOrientation orientation = [UIApplication sharedApplication].delegate.window.windowScene.interfaceOrientation;
Transform2D display_transform;
switch (orientation) {
case UIInterfaceOrientationPortrait: {
display_transform = Transform2D(0.0, -1.0, -1.0, 0.0, 1.0, 1.0);
} break;
case UIInterfaceOrientationLandscapeRight: {
display_transform = Transform2D(1.0, 0.0, 0.0, -1.0, 0.0, 1.0);
} break;
case UIInterfaceOrientationLandscapeLeft: {
display_transform = Transform2D(-1.0, 0.0, 0.0, 1.0, 1.0, 0.0);
} break;
default: {
display_transform = Transform2D(0.0, 1.0, 1.0, 0.0, 0.0, 0.0);
} break;
}
feed->set_transform(display_transform);
#endif // IOS_ENABLED
// and unlock
CVPixelBufferUnlockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);
}
@ -258,10 +226,10 @@
@end
//////////////////////////////////////////////////////////////////////////
// CameraFeedApple - Subclass for camera feeds in macOS
// CameraFeedMacOS - Subclass for camera feeds in macOS
class CameraFeedApple : public CameraFeed {
GDSOFTCLASS(CameraFeedApple, CameraFeed);
class CameraFeedMacOS : public CameraFeed {
GDSOFTCLASS(CameraFeedMacOS, CameraFeed);
private:
AVCaptureDevice *device;
@ -270,8 +238,8 @@ private:
public:
AVCaptureDevice *get_device() const;
CameraFeedApple();
~CameraFeedApple();
CameraFeedMacOS();
~CameraFeedMacOS();
void set_device(AVCaptureDevice *p_device);
@ -279,23 +247,22 @@ public:
void deactivate_feed() override;
};
AVCaptureDevice *CameraFeedApple::get_device() const {
AVCaptureDevice *CameraFeedMacOS::get_device() const {
return device;
}
CameraFeedApple::CameraFeedApple() {
CameraFeedMacOS::CameraFeedMacOS() {
device = nullptr;
capture_session = nullptr;
transform = Transform2D(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); /* should re-orientate this based on device orientation */
}
CameraFeedApple::~CameraFeedApple() {
CameraFeedMacOS::~CameraFeedMacOS() {
if (is_active()) {
deactivate_feed();
}
}
void CameraFeedApple::set_device(AVCaptureDevice *p_device) {
void CameraFeedMacOS::set_device(AVCaptureDevice *p_device) {
device = p_device;
// get some info
@ -309,14 +276,14 @@ void CameraFeedApple::set_device(AVCaptureDevice *p_device) {
};
}
bool CameraFeedApple::activate_feed() {
bool CameraFeedMacOS::activate_feed() {
if (capture_session) {
// Already recording.
return true;
}
// Start camera capture, check permission.
if (@available(macOS 10.14, iOS 14.0, visionOS 1.0, *)) {
if (@available(macOS 10.14, *)) {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusAuthorized) {
capture_session = [[MyCaptureSession alloc] initForFeed:this andDevice:device];
@ -344,7 +311,7 @@ bool CameraFeedApple::activate_feed() {
}
}
void CameraFeedApple::deactivate_feed() {
void CameraFeedMacOS::deactivate_feed() {
// end camera capture if we have one
if (capture_session) {
[capture_session cleanup];
@ -357,7 +324,7 @@ void CameraFeedApple::deactivate_feed() {
// when devices are connected/disconnected
@interface MyDeviceNotifications : NSObject {
CameraApple *camera_server;
CameraMacOS *camera_server;
}
@end
@ -368,7 +335,7 @@ void CameraFeedApple::deactivate_feed() {
camera_server->update_feeds();
}
- (id)initForServer:(CameraApple *)p_server {
- (id)initForServer:(CameraMacOS *)p_server {
if (self = [super init]) {
camera_server = p_server;
@ -389,31 +356,13 @@ void CameraFeedApple::deactivate_feed() {
MyDeviceNotifications *device_notifications = nil;
//////////////////////////////////////////////////////////////////////////
// CameraApple - Subclass for our camera server on macOS
// CameraMacOS - Subclass for our camera server on macOS
void CameraApple::update_feeds() {
void CameraMacOS::update_feeds() {
NSArray<AVCaptureDevice *> *devices = nullptr;
#ifdef APPLE_EMBEDDED_ENABLED
{
NSMutableArray *deviceTypes = [NSMutableArray array];
if (@available(iOS 14.0, visionOS 2.1, *)) {
[deviceTypes addObject:AVCaptureDeviceTypeBuiltInWideAngleCamera];
}
#ifdef IOS_ENABLED
[deviceTypes addObject:AVCaptureDeviceTypeBuiltInTelephotoCamera];
[deviceTypes addObject:AVCaptureDeviceTypeBuiltInDualCamera];
[deviceTypes addObject:AVCaptureDeviceTypeBuiltInTrueDepthCamera];
[deviceTypes addObject:AVCaptureDeviceTypeBuiltInUltraWideCamera];
[deviceTypes addObject:AVCaptureDeviceTypeBuiltInDualWideCamera];
[deviceTypes addObject:AVCaptureDeviceTypeBuiltInTripleCamera];
#endif // IOS_ENABLED
AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:deviceTypes mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified];
devices = session.devices;
}
#else // APPLE_EMBEDDED_ENABLED
#if defined(__x86_64__)
if (@available(macOS 10.15, *)) {
#endif // __x86_64__
#endif
AVCaptureDeviceDiscoverySession *session;
if (@available(macOS 14.0, *)) {
session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:[NSArray arrayWithObjects:AVCaptureDeviceTypeExternal, AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeContinuityCamera, nil] mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified];
@ -425,12 +374,11 @@ void CameraApple::update_feeds() {
} else {
devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
}
#endif // __x86_64__
#endif // APPLE_EMBEDDED_ENABLED
#endif
// Deactivate feeds that are gone before removing them.
for (int i = feeds.size() - 1; i >= 0; i--) {
Ref<CameraFeedApple> feed = (Ref<CameraFeedApple>)feeds[i];
Ref<CameraFeedMacOS> feed = (Ref<CameraFeedMacOS>)feeds[i];
if (feed.is_null()) {
continue;
}
@ -446,7 +394,7 @@ void CameraApple::update_feeds() {
for (AVCaptureDevice *device in devices) {
bool found = false;
for (int i = 0; i < feeds.size() && !found; i++) {
Ref<CameraFeedApple> feed = (Ref<CameraFeedApple>)feeds[i];
Ref<CameraFeedMacOS> feed = (Ref<CameraFeedMacOS>)feeds[i];
if (feed.is_null()) {
continue;
}
@ -456,7 +404,7 @@ void CameraApple::update_feeds() {
};
if (!found) {
Ref<CameraFeedApple> newfeed;
Ref<CameraFeedMacOS> newfeed;
newfeed.instantiate();
newfeed->set_device(device);
@ -466,7 +414,7 @@ void CameraApple::update_feeds() {
emit_signal(SNAME(CameraServer::feeds_updated_signal_name));
}
void CameraApple::set_monitoring_feeds(bool p_monitoring_feeds) {
void CameraMacOS::set_monitoring_feeds(bool p_monitoring_feeds) {
if (p_monitoring_feeds == monitoring_feeds) {
return;
}
@ -483,14 +431,3 @@ void CameraApple::set_monitoring_feeds(bool p_monitoring_feeds) {
device_notifications = nil;
}
}
#ifdef APPLE_EMBEDDED_ENABLED
void register_camera_external_module() {
CameraServer::make_default<CameraApple>();
}
void unregister_camera_external_module() {
}
#endif // APPLE_EMBEDDED_ENABLED

View file

@ -30,8 +30,6 @@
#include "camera_win.h"
#include "servers/camera/camera_feed.h"
///@TODO sorry guys, I got about 80% through implementing this using DirectShow only
// to find out Microsoft deprecated half the API and its replacement is as confusing
// as they could make it. Joey suggested looking into libuvc which offers a more direct

View file

@ -30,6 +30,7 @@
#pragma once
#include "servers/camera/camera_feed.h"
#include "servers/camera/camera_server.h"
class CameraWindows : public CameraServer {

View file

@ -3,14 +3,7 @@ def can_build(env, platform):
if sys.platform.startswith("freebsd") or sys.platform.startswith("openbsd"):
return False
return (
platform == "macos"
or platform == "windows"
or platform == "linuxbsd"
or platform == "android"
or platform == "ios"
or platform == "visionos"
)
return platform == "macos" or platform == "windows" or platform == "linuxbsd" or platform == "android"
def configure(env):

View file

@ -37,7 +37,7 @@
#include "camera_win.h"
#endif
#if defined(MACOS_ENABLED)
#include "camera_apple.h"
#include "camera_macos.h"
#endif
#if defined(ANDROID_ENABLED)
#include "camera_android.h"
@ -55,7 +55,7 @@ void initialize_camera_module(ModuleInitializationLevel p_level) {
CameraServer::make_default<CameraWindows>();
#endif
#if defined(MACOS_ENABLED)
CameraServer::make_default<CameraApple>();
CameraServer::make_default<CameraMacOS>();
#endif
#if defined(ANDROID_ENABLED)
CameraServer::make_default<CameraAndroid>();